pyhgf.utils.beliefs_propagation#

pyhgf.utils.beliefs_propagation(attributes, inputs, update_sequence, edges, input_idxs, observations='external', action_fn=None)[source]#

Update the networks parameters after observing new data point(s).

This function performs the beliefs propagation step. Belief propagation consists in: 1. A prediction sequence, from the leaves of the graph to the roots. 2. The assignation of new observations to target nodes (usually the roots of the network) 3. An inference step alternating between prediction errors and posterior updates, starting from the roots of the network to the leaves. This function returns a tuple of two new parameter_structure (i.e. the carryover and the accumulated in the context of jax.lax.scan()).

Parameters:
attributes

The dictionaries of nodes’ parameters. This variable is updated and returned after the beliefs propagation step.

inputs

A tuple of n by time steps arrays containing the new observation(s), the time steps as well as a boolean mask for observed values. The new observations are a tuple of array, with length equal to the number of input nodes. Each input node can receive observations The time steps are the last column of the array, the default is unit incrementation.

update_sequence

The sequence of updates that will be applied to the node structure.

edges

Information on the network’s edges.

input_idxs

List input indexes.

observations

A string indicating how the network receive new observations. Can be “external” (default) when new observation are provided, “generative” - in which case the network sample observation from its own predictive distribution, or “deprived” so no observation are provided.

action_fn

Optional. When provided, can implement action, decisions or transformation in the environment. The function should receive and return the attributes of the network and the inputs. This function is called after prediction and before observation.

Returns:
attributes, attributes

A tuple of parameters structure (carryover and accumulated).

Parameters:
  • attributes (Dict[int | str, Dict])

  • inputs (Tuple[Array | ndarray | bool | number | bool | int | float | complex, ...])

  • update_sequence (Tuple[Tuple[Tuple[int, Callable[[...], Dict[int | str, Dict]]], ...], Tuple[Tuple[int, Callable[[...], Dict[int | str, Dict]]], ...]])

  • edges (Tuple[AdjacencyLists, ...])

  • input_idxs (Tuple[int])

  • observations (str)

  • action_fn (Callable[[Dict[int | str, Dict], tuple], tuple[Dict[int | str, Dict], tuple]] | None)

Return type:

Tuple[Dict, Dict]