# Cross-entropy method

(Redirected from Cross entropy method)

The cross-entropy (CE) method is a Monte Carlo method for importance sampling and optimization. It is applicable to both combinatorial and continuous problems, with either a static or noisy objective.

The method approximates the optimal importance sampling estimator by repeating two phases[1]:

1. Draw a sample from a probability distribution.
2. Minimize the cross-entropy between this distribution and a target distribution to produce a better sample in the next iteration.

Reuven Rubinstein developed the method in the context of rare event simulation, where tiny probabilities must be estimated, for example in network reliability analysis, queueing models, or performance analysis of telecommunication systems. The method has also been applied to the traveling salesman, quadratic assignment, DNA sequence alignment, max-cut and buffer allocation problems.

## Estimation via importance sampling

Consider the general problem of estimating the quantity

${\displaystyle \ell =\mathbb {E} _{\mathbf {u} }[H(\mathbf {X} )]=\int H(\mathbf {x} )\,f(\mathbf {x} ;\mathbf {u} )\,{\textrm {d}}\mathbf {x} }$,

where ${\displaystyle H}$ is some performance function and ${\displaystyle f(\mathbf {x} ;\mathbf {u} )}$ is a member of some parametric family of distributions. Using importance sampling this quantity can be estimated as

${\displaystyle {\hat {\ell }}={\frac {1}{N}}\sum _{i=1}^{N}H(\mathbf {X} _{i}){\frac {f(\mathbf {X} _{i};\mathbf {u} )}{g(\mathbf {X} _{i})}}}$,

where ${\displaystyle \mathbf {X} _{1},\dots ,\mathbf {X} _{N}}$ is a random sample from ${\displaystyle g\,}$. For positive ${\displaystyle H}$, the theoretically optimal importance sampling density (PDF) is given by

${\displaystyle g^{*}(\mathbf {x} )=H(\mathbf {x} )f(\mathbf {x} ;\mathbf {u} )/\ell }$.

This, however, depends on the unknown ${\displaystyle \ell }$. The CE method aims to approximate the optimal PDF by adaptively selecting members of the parametric family that are closest (in the Kullback–Leibler sense) to the optimal PDF ${\displaystyle g^{*}}$.

## Generic CE algorithm

1. Choose initial parameter vector ${\displaystyle \mathbf {v} ^{(0)}}$; set t = 1.
2. Generate a random sample ${\displaystyle \mathbf {X} _{1},\dots ,\mathbf {X} _{N}}$ from ${\displaystyle f(\cdot ;\mathbf {v} ^{(t-1)})}$
3. Solve for ${\displaystyle \mathbf {v} ^{(t)}}$, where
${\displaystyle \mathbf {v} ^{(t)}=\mathop {\textrm {argmax}} _{\mathbf {u} }{\frac {1}{N}}\sum _{i=1}^{N}H(\mathbf {X} _{i}){\frac {f(\mathbf {X} _{i};\mathbf {u} )}{f(\mathbf {X} _{i};\mathbf {v} ^{(t-1)})}}\log f(\mathbf {X} _{i};\mathbf {v} ^{(t-1)})}$
4. If convergence is reached then stop; otherwise, increase t by 1 and reiterate from step 2.

In several cases, the solution to step 3 can be found analytically. Situations in which this occurs are

• When ${\displaystyle f\,}$ belongs to the natural exponential family
• When ${\displaystyle f\,}$ is discrete with finite support
• When ${\displaystyle H(\mathbf {X} )=\mathrm {I} _{\{\mathbf {x} \in A\}}}$ and ${\displaystyle f(\mathbf {X} _{i};\mathbf {u} )=f(\mathbf {X} _{i};\mathbf {v} ^{(t-1)})}$, then ${\displaystyle \mathbf {v} ^{(t)}}$ corresponds to the maximum likelihood estimator based on those ${\displaystyle \mathbf {X} _{k}\in A}$.

## Continuous optimization—example

The same CE algorithm can be used for optimization, rather than estimation. Suppose the problem is to maximize some function ${\displaystyle S(x)}$, for example, ${\displaystyle S(x)={\textrm {e}}^{-(x-2)^{2}}+0.8\,{\textrm {e}}^{-(x+2)^{2}}}$. To apply CE, one considers first the associated stochastic problem of estimating ${\displaystyle \mathbb {P} _{\boldsymbol {\theta }}(S(X)\geq \gamma )}$ for a given level ${\displaystyle \gamma \,}$, and parametric family ${\displaystyle \left\{f(\cdot ;{\boldsymbol {\theta }})\right\}}$, for example the 1-dimensional Gaussian distribution, parameterized by its mean ${\displaystyle \mu _{t}\,}$ and variance ${\displaystyle \sigma _{t}^{2}}$ (so ${\displaystyle {\boldsymbol {\theta }}=(\mu ,\sigma ^{2})}$ here). Hence, for a given ${\displaystyle \gamma \,}$, the goal is to find ${\displaystyle {\boldsymbol {\theta }}}$ so that ${\displaystyle D_{\mathrm {KL} }({\textrm {I}}_{\{S(x)\geq \gamma \}}\|f_{\boldsymbol {\theta }})}$ is minimized. This is done by solving the sample version (stochastic counterpart) of the KL divergence minimization problem, as in step 3 above. It turns out that parameters that minimize the stochastic counterpart for this choice of target distribution and parametric family are the sample mean and sample variance corresponding to the elite samples, which are those samples that have objective function value ${\displaystyle \geq \gamma }$. The worst of the elite samples is then used as the level parameter for the next iteration. This yields the following randomized algorithm that happens to coincide with the so-called Estimation of Multivariate Normal Algorithm (EMNA), an estimation of distribution algorithm.

### Pseudo-code

// Initialize parameters
mu:=-6
sigma2:=100
t:=0
maxits:=100
N:=100
Ne:=10
// While maxits not exceeded and not converged
while t < maxits and sigma2 > epsilon
// Obtain N samples from current sampling distribution
X:=SampleGaussian(mu,sigma2,N)
// Evaluate objective function at sampled points
S:=exp(-(X-2)^2) + 0.8 exp(-(X+2)^2)
// Sort X by objective function values in descending order
X:=sort(X,S)
// Update parameters of sampling distribution
mu:=mean(X(1:Ne))
sigma2:=var(X(1:Ne))
t:=t+1
// Return mean of final sampling distribution as solution
return mu