pyhgf.model.hybrid.DeepNetworkAdapter#
- class pyhgf.model.hybrid.DeepNetworkAdapter(net, optimiser=None, learning_kind='precision_weighted', learning_kwargs=None, update_precisions=False, time_step=1.0, weight_reuse=1.0)[source]#
A learning part: a PyHGF
DeepNetworkin the pipeline.Declares the wrapped network and how it learns; the executor runs one batch-synchronous local learning step per training step (the same computation as
batch_update(), staged in-trace) and threads the error at the network’s input onward.Error convention bridge
This part is where the pipeline’s descent-error convention meets PyHGF’s observed-minus-predicted convention (see
pyhgf.model.error_types). The executor performs the conversion at this single boundary:- Forward (pipeline → PyHGF):
Input (DescentError) is unchanged; used as usual.
- Backward (PyHGF → pipeline):
Pipeline passes
DescentError(positive = too high)This part converts to
ObservedMinusPredicted:observation = output - descent_errorPyHGF’s
batch_updatetreats this as the target, computingprediction_error = observation - output = -descent_errorLearning uses the prediction error natively
Input error (also prediction-error convention) is negated back to descent-error convention before passing to the previous part
This two-step conversion (descent↔observed-minus-predicted) happens in exactly one place: inside the executor’s backward pass for this adapter. No other part needs to know about the convention flip.
- Parameters:
net (DeepNetwork) – The wrapped network. Its top (input) layer width is the part’s input size; its bottom (output) layer width is the part’s output size.
optimiser (Optional[optax.GradientTransformation]) – Optax optimiser for the local weight step.
Nonefreezes the weights (the beliefs still update).learning_kind (str) – Weight-gradient mode, as in
fit()."synaptic_uncertainty"selects the weight-belief rule, whose settings come fromlearning_kwargsand whose step size is each weight’s own belief variance, sooptimiseris then unused.learning_kwargs (Optional[dict]) – Settings of the learning rule, used by
learning_kind="synaptic_uncertainty"(seepyhgf.updates.vectorised.learning.resolve_synaptic_uncertainty_settings()).update_precisions (bool) – Whether the precision state adapts across batches (see
batch_update()). Defaults to False — the setting used for exact comparisons against backpropagation.time_step (float) – Inference time step — scales the precision leak per batch (one batch counts as one observation of duration
time_step).weight_reuse (float) – How many times
net’s weights are applied per sample, default1.0. Set it when the caller feeds this part more rows than samples because the wrapped network’s weights are shared across several positions of each sample: the plain batch mean then divides by the reuse count, which that weight’s true per-sample gradient and curvature sum over instead. It rescales the mean gradient and, underlearning_kind="synaptic_uncertainty", the importance increment too, so it reaches every learning path rather than onlyoptimiser(seepyhgf.utils.vectorised_belief_propagation._batch_step()).
- __init__(net, optimiser=None, learning_kind='precision_weighted', learning_kwargs=None, update_precisions=False, time_step=1.0, weight_reuse=1.0)[source]#
Methods
__init__(net[, optimiser, learning_kind, ...])init_state()Return the
(network, opt_state)state pytree.