The InfluenceEstimator class#

Aliases#

halerium.InfluenceEstimator
halerium.core.InfluenceEstimator
halerium.core.objectives.InfluenceEstimator
class InfluenceEstimator(graph, target, compiler=None, n_samples=1000, name='InfluenceEstimator', description=None, copy_graph=True)#

The influence estimator class.

This class calculates the amount by which parts of the graph influence the value of a target. The target can be a KPI or a specific part of the graph.

Parameters:
  • graph (halerium.core.Graph) – The graph in which the influences are to be assessed.

  • target (Variable, Entity, Graph, Inputs, Outputs, callable) – The target for which the influences are to be assessed. This can be a substructure of the graph or a callable, which takes the graph as an input and outputs an operator, e.g. a KPI.

  • compiler (halerium.core.compiler.compiler_base.CompilerBase, optional) – The compiler compiling the model. The default is the TFCompiler.

  • n_samples (int, optional) – The amount of samples that are generated to estimate influence strengths. The default is 1000.

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

__call__(fetches=None)#

Get the influence strengths.

Returns the relative influence of fetches on the target. The influence strength is returned for each element in fetches individually.

Parameters:

fetches – A single graph element, or arbitrarily nested list or dict of graph elements. The default is to compute influence strengths for the graph itself and all its elements.

Returns:

The influence strengths.

Return type:

result

dump_dict(value_postprocessor=None)#

Dump a dict with information on the evaluator.

The dict returned contains the name, description and the values resulting from a call of the evaluator. Further keys are used by the GUI for appropriately displaying the results of the evaluator.

Parameters:

value_postprocessor (optional) – A function to apply to the values returned by the evaluator.

Returns:

result – A dictionary containing the name, description, etc. and results of the evaluator.

Return type:

dict

get_influences(fetches, relative=True)#

Returns the (relative) influence of fetches on the target. The influence strength is returned for each element in fetches individually.

Parameters:
  • fetches – A single graph element, or arbitrarily nested list or dict of graph elements.

  • relative (bool, optional) – Whether or not to return the relative influence strength, where 1 indicates an influence of the same strength as the influence of the (reduced) target on itself. The default is True.

Returns:

The influence strengths.

Return type:

result

Examples

>>> from halerium.core import Graph, Entity, Variable
>>> from halerium import InfluenceEstimator
>>>
>>> g = Graph("g")
>>> with g:
>>>     e = Entity("e")
>>>     with e:
>>>         a = Variable("a", mean=0, variance=1)
>>>         b = Variable("b", mean=0, variance=2)
>>>     d = Variable("d", mean=e.a + e.b, variance=3)
>>> ie = InfluenceEstimator(g, target=g.d)
>>> ie([g.e.a, g.e.b])
[0.17, 0.33] # plus sampling error