I am reading the article of Deriving probability distributions using the Principle of Maximum Entropy
and I am trying to derive some of the equations in it automatically using Mathematica.
1. Derivation of maximum entropy probability distribution with no other constraints (uniform distribution)
First, we solve for the case where the only constraint is that the distribution is a pdf, which we will see is the uniform distribution. To maximize entropy, we want to minimize the following function: $$ J(p)=\int_a^b p(x) \ln p(x) d x-\lambda_0\left(\int_a^b p(x) d x-1\right) $$ . Taking the derivative with respect ot $p(x)$ and setting to zero, $$ \frac{\delta J}{\delta p(x)}=1+\ln p(x)-\lambda_0=0 $$
Can I derive the second equation automatically using Mathematica?
if just $ J(p)=\int_a^b p(x) \ln p(x) dx$, I can do
Needs["VariationalMethods`"]
VariationalD[p[x] Log[p[x]], p[x], x]
the output is 1 + Log[p[x]] as expected.
But here $ J(p)=\int_a^b p(x) \ln p(x) d x-\lambda_0\left(\int_a^b p(x) d x-1\right) $, how can I do that?
VariationalD[p[x] Log[p[x]] - λ0 ( p[x] - 1), p[x], x]? What's the issue? – bmf Jan 12 '23 at 11:401 - λ0 + Log[p[x]]which is the expected answer from the OP – bmf Jan 12 '23 at 11:55Inegrate[p[x] Log[p[x]] - \[Lambda]0 (p[x] - 1)] === Inegrate[p[x] Log[p[x]]] - \[Lambda]0*(Inegrate[p[x]] - 1), the output is False – benjaminchanming Jan 12 '23 at 12:00Integrateand also with respect to what? And also, this last comment contradicts what you wrote in the OP in my opinion – bmf Jan 12 '23 at 12:021-\[Lambda]0+Log[p[x]]and a warning. – user64494 Jan 12 '23 at 12:04Integrate[f[x]], to get the expression off, so that I can passfinto the first parameter ofVariationalD[f,u[x],x]? – benjaminchanming Jan 12 '23 at 12:0413.2.0on macOS I have no warnings; see – bmf Jan 12 '23 at 12:07Integrate[p[x] Log[p[x]] - \[Lambda]0 (p[x] - 1), x] === Integrate[p[x] Log[p[x]], x] - \[Lambda]0*(Integrate[p[x], x] - 1), but it still return False. And why the comment contradicts what I wrote in the OP? – benjaminchanming Jan 12 '23 at 12:14$$ \int_a^b p(x) \ln p(x) d x-\lambda_0\left(\int_a^b p(x) d x-1\right) $$
into $$ \int_a^b (p(x) \ln p(x)-\lambda_0\left( p(x)-1\right))dx $$
By which rule in calculus can we do the factoring out $\int_a^b $ transformation?
– benjaminchanming Jan 12 '23 at 12:32