The ProbabilityEstimator class#
Aliases#
halerium.ProbabilityEstimator
halerium.core.ProbabilityEstimator
halerium.core.objectives.ProbabilityEstimator
- class ProbabilityEstimator(graph, data, compiler=None, n_samples=1000, method='marginalized', name='ProbabilityEstimator', description=None, copy_graph=True)#
The probability estimator class.
This class estimates the probability of a set of data points for a given graph. The probability is estimated for each data point individually.
- Parameters:
graph (halerium.core.Graph) – The graph that defines the dependencies and probabilities of the variables
data (dict, halerium.core.DataLinker) – The data for which to estimate probabilities. Either dictionary with variables as keys and data arrays as values, or a DataLinker holding links to the variables in graph.
compiler (halerium.core.compiler.compiler_base.CompilerBase, optional) – The backend compiler to be used. The default is the Tensorflow compiler.
n_samples (int, optional) – The amount of samples to be used to estimate the probabilities. The default is 1000.
method (str, optional,) – The method with which the probability is estimated. Either “upsampled” or “marginalized”. “upsampled” samples the missing values, so that the result represents a probability density over all variables. “marginalized” marginalizes the missing values, so that the result represents a probability density only over the variables that have data. The default is “marginalized”.
name (str, optional) – The name of the objective.
description (str, optional) – The description of the objective.
copy_graph (bool, optional) – Whether the objective 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.
Examples
A call of the instance with the graph as arguement returns the log. probabilities of all data points.
>>> from halerium.core import Graph, Variable >>> g = Graph("g") >>> with g: >>> Variable("v", mean=0, variance=1) >>> g_data = {g.v: [-1., 0., 1.]} >>> p = ProbabilityEstimator(g, data=g_data) >>> p(g) array([-1.41893853, -0.91893853, -1.41893853])
- __call__(fetches=None)#
Get log. probabilities.
Returns the logarithmic probability densities of each element in fetches for each data point.
- Parameters:
fetches (halerium.core.scope.Scopetor, dict, list or tuple, optional) – The scopetors for which to return the log probabilities. If no fetches are provided, the default is to return estimates for the graph itself and all its elements.
- Returns:
log-probabilities – The log-probabilities for each element in fetches.
- Return type:
array, dict, list or tuple
- dump_dict(value_postprocessor=None)#
Dump a dict with information on the objective.
The dict returned contains the name, description and the values resulting from a call of the objective. Additional keys included are used by the GUI for appropriately displaying the results of the objective.
- Parameters:
value_postprocessor (optional) – A function to apply to the values returned by the call of the objective. The default is None, in which case no post-processing is done.
- Returns:
result – A dictionary containing the name, description, etc. of the objective.
- Return type:
dict
- get_log_probabilities(fetches, return_samples=False)#
Get log. probabilities.
- Parameters:
fetches (halerium.core.scope.Scopee, dict, list or tuple) – The fetches for which to compute log. probabilities.
return_samples (bool) – Whether to return samples.
- Returns:
log-probabilities – The log-probabilities for each element in fetches.
- Return type:
array, dict, list or tuple