The ForwardModel class#

Aliases#

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

Model providing forward predictions.

Model providing forward predictions.

The model uses direct sampling to generate samples along the causal directions of the graph. Information therefore only travels forward along the causal connections as defined by the Variables dependencies.

Parameters:
  • graph (halerium.core.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.

  • 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.

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_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()#

Solve the model.

The forward model does not require any solving.

Return type:

None.