11.3. Maximum Entropy for reconstructing a function from its moments#
Here we use Maximum Entropy to reconstruct some simple functions from their moments, using the formulation by Mead and Papanicolaou, J. Math. Phys. 24, 2404 (1984). The context is answering the question: If we know some (or all) of the moments of a one-dimensional distribution \(p(x)\), how can we find the PDF? This question was asked in Section 4.4 and we repeat the definitions from there. We define the moments \(m_k\) for integer \(k\) as
where \(S\) denotes the support of the PDF (e.g., \((-\infty,\infty)\) for a Gaussian or \([0,1]\) for a Beta distribution). So \(m_0 = 1\), the mean \(\mu\) is \(m_1\), the variance \(\sigma^2\) is \(m_2 - m_1^2\), and so on.
If we have only a finite number \(N+1\) of moments, this is an underdetermined inverse problem. We solve it by maximizing the entropy associated with \(p(x)\) subject to the condition that the first \(N+1\) moments be equal to the true moments \(m_k\), \(k=0,1,\ldots,N\). To carry this out we introduce \(N+1\) Lagrange multipliers \(\lambda_k\) and maximize the functional \(S = S[p]\) defined by
We take the functional derivative with respect to \(p(x)\) and set it equal to zero, yielding
which will be our expression when we know the \(\lambda_k\)s. We have \(N+1\) nonlinear equations for those \(N+1\) unknown after taking partial derivatives with respect to the \(\lambda_k\)s and setting them to zero, yielding
We will assume that \(p(x)\) is normalized, i.e., that \(m_0 = 1\). This implies that the \(k=0\) equation can be used to solve for \(\lambda_0\), which defines the partition function (and a Boltzmann factor as the integrand):
We perform a Legendre transformation to go from the free energy \(\ln Z\) to the effective potential \(\Gamma = \Gamma(\lambda_1, \lambda_2,\ldots,\lambda_N)\)
Given initial guesses for the \(\lambda\)s, we will simply numerically minimize \(\Gamma\) to find the \(\lambda\)s and then evaluate \(p_N(x)\).
Benchmark case#
As a benchmark, we consider the (normalized) distribution \(p(x)=x + 1/2\) in the domain \(0 \leq x \leq 1\). For \(N=2\) to \(N=5\), we minimize the effective potential, starting from \(\lambda_k = 1\) for all \(k\), and then reconstruct and plot the result, comparing to the exact result.
N=2 moments#
Moments: [0.58333333 0.41666667]
Minimized Lagrange multipliers lambdas: [-1.5892963 0.53499597]
N=3 moments#
Moments: [0.58333333 0.41666667 0.325 ]
Minimized Lagrange multipliers lambdas: [-1.84589891 1.13219435 -0.38049834]
N=4 moments#
Moments: [0.58333333 0.41666667 0.325 0.26666667]
Minimized Lagrange multipliers lambdas: [-1.69942478 0.54755159 0.45576187 -0.39286306]
N=5 moments#
Moments: [0.58333333 0.41666667 0.325 0.26666667 0.22619048]
Minimized Lagrange multipliers lambdas: [-1.57582227 0.23066907 0.48946635 0.13622942 -0.36347669]
Checkpoint question
Does the result improve from \(N=2\) to \(N=3\)? From \(N=3\) to \(N=4\)? From \(N=4\) to \(N=5\)?
Answer
There is clear improvement from \(N=2\) to \(N=3\), but not beyond that. Note that at N=4 the minimum found is: -0.04278640499674846, but there is also: -0.04279159257882259. How could you persuade Python to find this slightly better minimum? Does it help?
Exercises#
Exercise 11.1
Copy the code defined here (open Show code cell source) to a Jupyter notebook (or write your own version) to produce a MaxEnt reconstruction of \(y(x)=2x\) for \(0 \leq x \leq 1\).
Exercise 11.2
MaxEnt doesn’t even care about essential singularities. Compute the moments for \(y(x)=1/\mu_0 \exp(-1/x)\) and reconstruct it. Note that you need to choose the constant \(\mu_0\) so that \(y\) can be interpreted as a probability distribution (i.e., normalized). [Copy the code defined here (open Show code cell source) to a Jupyter notebook (or write your own version)].
Exercise 11.3
MaxEnt does care about some things, though. Repeat the last exercise but for \(P(x)=4x-1\) and see what happens. Can you figure out why MaxEnt failed for this function?