The ADVIModel class#

Aliases#

halerium.core.model.ADVIModel
class ADVIModel(graph, data=None, compiler=None, initial_values=None, initial_source_values=None, copy_graph=True, model_graph_options=None)#

Model providing variational inference predictions.

Model providing variational inference predictions.

The model implements the ADVI algorithms, which stands for automatic differentiation variational inference. See https://arxiv.org/abs/1603.00788

Parameters:
  • graph (halerium.Graph) – The graph of the model.

  • data (halerium.core.DataLinker, dict, optional) – The data linker or dict containing data constraining the model. The default is None.

  • compiler (optional) – The compiler instance or class for compiling the model. The default is None, in which case a Tensorflow compiler is used.

  • initial_values (dict, optional) – A dictionary containing (static) variables in the graph as keys and their initial values as values. The model then tries to convert these into appropriate initial values for the solver.

  • initial_source_values (dict, optional) – A dictionary containing (static) variables in the graph as keys and initial value for their source as values. In addition, strings are accepted as keys, but are ignored unless the model can interpret these. This attribute may be used to pass initial values for trainable model parameters obtained from training of earlier models with the same (or a sufficiently similar) graph. Other usage is not recommended (unless users know exactly how the model handles its sources and their initial values).

  • copy_graph (bool, optional) – Whether the model should make a copy of the graph for its own use, or just keep the graph itself as attribute. Users should leave this set to the default True, unless they are certain that the graph won’t be altered by the user or other code. Such changes to a graph a model holds directly (i.e. not a copy) makes that model inconsistent and likely causes errors.

  • model_graph_options (dict, optional) – The options for creating the model graph. The default is None.

Return type:

None.

apply_to_samples(fetches, function, n_samples)#

Draw samples and apply a function to them.

Parameters:
  • fetches – The variables to generate sample data for.

  • function (callable) – The function to apply to the sample data.

  • n_samples (int) – The number of samples to draw from the model.

Returns:

The result of applying the function to the sampled data.

Return type:

result

assert_is_trained()#

Check if model is trained.

Return type:

None.

Raises:

RuntimeWarning – If model is not trained.

get_example(fetches)#

Draw an example from the model.

Parameters:

fetches – The variables to generate example values for.

Returns:

The example data.

Return type:

example

get_means(fetches, n_samples=100)#

Estimate mean values.

Parameters:
  • fetches – The variables to estimate mean values for.

  • n_samples (int) – The number of samples to estimate the means from.

Returns:

The estimated means of the variables.

Return type:

means

get_posterior_graph(name=None, n_samples=100)#

Create posterior graph from trained model.

Parameters:
  • name (str) – The name to give to the posterior graph.

  • n_samples (int) – The number of samples to estimate the posterior distributions from.

Returns:

post_graph – The posterior graph.

Return type:

halerium.core.Graph

get_samples(fetches, n_samples=1)#

Draw samples from the model.

Parameters:
  • fetches – The variables to generate sample data for.

  • n_samples (int) – The number of examples to draw from the model.

Returns:

The sampled data.

Return type:

samples

get_source_values(return_all=False)#

Get source values.

Prior to any training, these are just any initial values provided by the caller to the model upon construction. After training, these are the final values of the sources at the end of the training.

Parameters:

return_all (bool) – Whether to return all, or just the source values for static variables (default).

Returns:

The source values.

Return type:

source_values

get_standard_deviations(fetches, n_samples=100)#

Estimate standard deviations.

Parameters:
  • fetches – The variables to estimate standard deviations for.

  • n_samples (int) – The number of samples to estimate the standard deviations from.

Returns:

The estimated standard deviations of the variables.

Return type:

standard_deviations

get_variances(fetches, n_samples=100)#

Estimate variances.

Parameters:
  • fetches – The variables to estimate variances for.

  • n_samples (int) – The number of samples to estimate the variances from.

Returns:

The estimated variances of the variables.

Return type:

variances

property is_trained#

Whether the model has been trained.

property model_graph#

The model graph (don’t modify it yourself).

solve(max_iter=100000, convergence_iter=1000, eta=0.1, alpha=0.1, tau=1.0, epsilon=1e-16)#

Solve the model.

Parameters:
  • max_iter (int) – The maximum number of iterations to run the solver.

  • convergence_iter (int) – The number of iterations after which to check for convergence.

  • eta

    ?

  • alpha

    ?

  • tau

    ?

  • epsilon

    ?

Return type:

None