runlmc.parameterization.model module

This module defines a generic internal Model class, which handles the interface between this class and the paramz optimization layer.

class runlmc.parameterization.model.Model(name)[source]

Bases: paramz.model.Model, runlmc.parameterization.priorizable._PriorizableNode

A Model provides a graphical model dependent on latent parameters, which it contains either explicitly (as attributes in derived classes of Model) or implicitly (as parameters implicitly linked to a model’s explicit parameters).

Access to any parameter in this tree can be done by the name of those parameters. See the Parameterized documentation for details.

The parameters can be either Param`s or :class:`Parameterized. In fact, the tree of references from objects to their attributes, as represented in the Python garbage collector, matches identically with the graphical model that this Model represents (though the direction of the links is reversed).

The Model binds together likelihood values computed from the model without the priors (which is implemented by derived classes) with the priors. In other words, for observations \(\mathbf{y}\), parameters \(\theta\) dependent on priors \(\phi\), the user supplies \(\log p(\mathbf{y}|\theta,\phi)\) as well as its derivative with respect to \(\theta\). This class automatically adds in the missing \(\log p(\theta|\phi)\) term and its derivative.

log_likelihood()[source]
Returns:the log likelihood of the current model with respect to its current inputs and outputs and the current prior. This should NOT include the likelihood of the parameters given their priors. In other words, this value should be \(\log p(\mathbf{y}|\theta,\phi)\)
log_likelihood_with_prior()[source]

Let the observations be \(\mathbf{y}\), parameters be \(\theta\), and the prior \(\phi\).

\[\log p(\mathbf{y}|\phi) = \log p(\mathbf{y}|\theta,\phi) + \log p(\mathbf{y}|\theta,\phi)\]
Returns:the overall log likelihood shown above.
log_prior()[source]
Returns:the log prior \(\log p(\theta|\phi)\)
objective_function()[source]

The objective function for the given algorithm.

This function is the true objective, which wants to be minimized. Note that all parameters are already set and in place, so you just need to return the objective function here.

For probabilistic models this is the negative log_likelihood (including the MAP prior), so we return it here. If your model is not probabilistic, just return your objective to minimize here!

objective_function_gradients()[source]

The gradients for the objective function for the given algorithm. The gradients are w.r.t. the negative objective function, as this framework works with negative log-likelihoods as a default.

You can find the gradient for the parameters in self.gradient at all times. This is the place, where gradients get stored for parameters.

This function is the true objective, which wants to be minimized. Note that all parameters are already set and in place, so you just need to return the gradient here.

For probabilistic models this is the gradient of the negative log_likelihood (including the MAP prior), so we return it here. If your model is not probabilistic, just return your negative gradient here!