relentless.optimize.RelativeEntropy#
- class relentless.optimize.RelativeEntropy(target, simulation, potentials, thermo, extensive=False)#
Relative entropy.
The relative entropy \(S_{\rm rel}\) (or Kullback-Leibler divergence) quantifies the overlap of two probability distributions. For a known target statistical mechanical ensemble having distribution \(p_0\) and a simulated model ensemble having distribution \(p\) and parametrized on a set of design variables \(\mathbf{x}\), the relative entropy from the model to the target is:
\[S_{\rm rel} = -\int d\Gamma p_0(\Gamma)\ln\left(\frac{p(\Gamma)}{p_0(\Gamma)}\right)\]where \(\Gamma\) is an element of phase space. The relative entropy is zero when the two ensembles overlap completely, and it is positive otherwise. Hence, minimization of \(S_{\rm rel}\) can be used to find parameters of a model that reproduce a known target ensemble.
The value of the relative entropy is not readily determined in molecular simulations, so this
ObjectiveFunctiondoes not return a value. However, the gradient of the relative entropy with respect to the design variables \(\mathbf{x}\) is much easier to compute as ensemble averages. Currently, theRelativeEntropyobjective function supports onlyPairPotentialinteractions. These interactions are characterized by \(g_{ij}(r)\), anRDFfor each pair of interacting types \((i,j)\) in eachEnsemble. The gradient of \(S_{\rm rel}\) is then:\[\nabla_\mathbf{x} S_{\rm rel} = -\frac{1}{2} \sum_{i,j} \int dr 4\pi r^2 \left[\frac{\beta N_i N_j}{V} g_{ij}(r) \right. \left. -\frac{\beta_0 N_{i,0} N_{j,0}}{V_0} g_{ij,0}(r)\right] \nabla_\mathbf{x} u_{ij}(r)}\]where \(\beta=1/(k_{\rm B}T)\), \(N_i\) is the number of particles of type \(i\), \(V\) is the extent, and \(u_{ij}(r)\) is the pair potential in the model ensemble. The corresponding properties of the target ensemble are denoted with subscript \(0\).
\(S_{\rm rel}\) is extensive as written, meaning that it depends on the size of the system. This can be undesirable for optimization because it means certain hyperparameters are system-dependent, so the default behavior is to normalize \(s_{\rm rel}=S_{\rm rel}/V_0\). To use the extensive relative entropy set
extensive=True.- Parameters:
target (
Ensemble) – The target ensemble (must have specifiedVandN).simulation (
Simulation) – The simulation engine to use, with specified simulation operations.potentials (
Potentials) – The pair potentials to use in the simulations.thermo (
SimulationOperation) – The thermodynamic analyzer operation for the simulation ensemble and rdf (usuallyAddEnsembleAnalyzer). The model ensemble will be extracted from this operation.extensive (bool) – Specification of whether the relative entropy is extensive (defaults to
False).
Methods
compute(variables[, directory])Evaluate the value and gradient of the relative entropy function.
compute_gradient(ensemble, variables)Computes the relative entropy gradient for an ensemble.
Attributes
The target ensemble.
- compute(variables, directory=None)#
Evaluate the value and gradient of the relative entropy function.
The value of the relative entropy is not computed, but the gradient is. Calculating the gradient requires running a simulation, which may be computationally expensive.
Optionally, a directory can be specified to write the simulation output as defined in
run(), namely the values of the pair potential design variables, which are written topair_potential.i.jsonfor the \(i\)th pair potential, and theObjectiveFunctionResult, which is written toresult.json.- Parameters:
variables (
Variableor tuple) – Variables with respect to which to compute gradient.directory (str or
Directory) – The output directory
- Returns:
The result, which has unknown value
Noneand known gradient.- Return type:
- compute_gradient(ensemble, variables)#
Computes the relative entropy gradient for an ensemble.
- Parameters:
ensemble (
Ensemble) – The ensemble for which to evaluate the gradient.variables (
Variableor tuple) – Variables with respect to which to compute gradient.
- Returns:
The gradient, keyed on the
variables.- Return type:
- property target#
The target ensemble. Must have both
VandNparameters set.- Type:
Ensemble