pyhgf.updates.vectorized.learning.vectorized_weight_update#
- pyhgf.updates.vectorized.learning.vectorized_weight_update(parent_state, child_state, weights, coupling_fn, lr=None, parent_has_constant=False, adam_m=None, adam_v=None, adam_t=0, adam_beta1=0.9, adam_beta2=0.999, adam_epsilon=1e-08)[source]#
Unified weight update for vectorized layers.
Branches on the
lrparameter:Fixed (
lris a float): \(\Delta w = \text{lr} \cdot \text{PE} \cdot \pi_\text{child} \cdot g(\text{parent})\)Dynamic (
lr is None): Kalman-gain rule. \(K = \pi_\text{parent} / (\pi_\text{parent} + \pi_\text{child})\) \(\Delta w = K \cdot \text{PE} \cdot g(\text{parent})\)
When
adam_mandadam_vare provided (not None), the fixed-LR gradient is filtered through Adam before being applied.- Parameters:
parent_state (LayerState) – Current state of the parent layer.
child_state (LayerState) – Current state of the child layer (with observations).
weights (Array) – Current weight matrix, shape
(n_children, n_parents)or(n_children, n_parents + 1)when the parent layer includes a constant input node.coupling_fn (Callable) – Coupling function applied to parent means.
lr (float | None) – Fixed learning rate. When
None(default) the dynamic precision-weighted Kalman-gain rule is used instead.parent_has_constant (bool) – If True, the parent layer has a constant input node. The parent mean is augmented with 1.0 and the precision with the parent precision mean so the bias column of weights is updated.
adam_m (Array | None) – First moment estimate for Adam, same shape as weights. Pass
Noneto disable Adam.adam_v (Array | None) – Second moment estimate for Adam, same shape as weights.
adam_t (int) – Global Adam timestep (already incremented for this step).
adam_beta1 (float) – Exponential decay rate for the first moment.
adam_beta2 (float) – Exponential decay rate for the second moment.
adam_epsilon (float) – Small constant for numerical stability.
- Returns:
new_weights – Updated weight matrix.
new_adam_m – Updated first moment (or None when Adam is not used).
new_adam_v – Updated second moment (or None when Adam is not used).
- Return type:
tuple[Array, Array | None, Array | None]