pyhgf.utils.vectorised_belief_propagation.sample_step#

pyhgf.utils.vectorised_belief_propagation.sample_step(network, x, y, learning_kind='precision_weighted', time_step=1.0)[source]#

One full local learning step for one sample, as a pure function.

Runs the prediction sweep (clamp x on top, predict downward) and the update sweep (clamp y at the bottom, compute errors and correct beliefs upward), then reads out everything a caller needs without mutating anything.

Parameters:
  • network (VectorisedNetwork) – The state template. Not modified; every call starting from the same template sees the same weights and the same precisions, which is what makes this function safe to jax.vmap over a batch of samples.

  • x (Array) – Predictors clamped on the top layer, shape (n_input_features,).

  • y (Array) – Observations clamped on the bottom layer, shape (n_output_features,).

  • learning_kind (str) – Weight-gradient mode, as in pyhgf.updates.vectorised.learning.learning_weights_vectorised().

  • time_step (float) – Inference time step for the prediction sweep.

Returns:

  • input_error – The prediction error at the input (top) layer — see input_prediction_error().

  • grads – Per-element weight gradients (descent form, None for the bottom element). Average these across a batch and apply once.

  • increments – Per-element change of the carried precision fields (value-level posterior precision and the volatility level), relative to the template. Average these across a batch and apply once with apply_precision_increments().

Return type:

tuple[Array, tuple, tuple]