brainmass.Network#
- class brainmass.Network(*args, **kwargs)#
Wire a node model into a delay-coupled whole-brain network.
The network reads a single
node(aDynamicssized for N regions) and couples its regions through a structural-connectivity matrix, optionally with distance-dependent conduction delays.updatecomputes the coupling current and feeds it back as the node’s first positional input – the samecurrent = coupling(); node(current)idiom hand-written in the examples.- nodebrainstate.nn.Dynamics
The per-region dynamics, already sized for N regions (
node.varshape[0] == N) and carrying any per-region noise. Exposed afterwards asnode; its states are reachable asnetwork.node.<coupled_var>.- connarray_like or brainstate.nn.Param
Structural connectivity. A plain
(N, N)(or flattened(N * N,)) array has its diagonal zeroed unlessself_connectionisTrue; aParam/LaplacianConnParamis passed through untouched (the caller owns its structure) and may be trained.- distancearray_like, optional
Inter-region distance matrix
(N, N). Combined withspeedinto conduction delaysdistance / speed. If eitherdistanceorspeedisNonethe coupling is instantaneous (zero delays).- speedfloat or brainunit.Quantity, optional
Conduction speed. If
distancecarries length units andspeedcarrieslength / timeunits the delay is unit-correct; if both are plain numbers the quotient is interpreted as milliseconds (matching the examples).
coupling : {‘diffusive’, ‘additive’, ‘laplacian’, ‘sigmoidal’, ‘tanh’,
- ‘sigmoidal_jansen_rit’}, default ‘diffusive’
Coupling kernel.
'diffusive'usesDiffusiveCoupling(k * sum_j conn_ij (x_j - x_i));'additive'usesAdditiveCoupling(k * sum_j conn_ij x_j);'laplacian'wrapsconnin aLaplacianConnParamand applies it additively. The nonlinear forms'sigmoidal'(SigmoidalCoupling),'tanh'(HyperbolicTangentCoupling) and'sigmoidal_jansen_rit'(SigmoidalJansenRitCoupling) apply their nonlinearity to the same delayed source read, withkas the global strength (TVBG;G ≡ k).- coupled_varstr
Name of the node state variable to couple (e.g.
'rE','x','V'). Validated at initialisation; an unknown name raisesValueError.- kfloat, brainunit.Quantity or brainstate.nn.Param, default 1.0
Global coupling strength. Pass a trainable
Paramto fit it.- delay_initCallable, default
braintools.init.Uniform(0., 0.05) Initializer for the delay buffer’s history.
- self_connectionbool, default False
If
False(default), the connectivity diagonal is zeroed (no self-coupling). Only applies to plain-arrayconn.- noisebrainstate.nn.Module, optional
Optional network-level noise process (e.g. an
OUProcesssized for N). Its output is added to the coupling current each step.
brainmass.Simulator : drives the network and collects trajectories. brainmass.DiffusiveCoupling : the underlying diffusive coupling kernel.
The delay-buffer shape
(max_delay_steps, N)does not depend on whether the(delay, index)pair is supplied flattened (as inexamples/100) or as(N, N)matrices (as here), so a seeded run reproduces the hand-wired examples bit-for-bit. The self-delay (delay-matrix diagonal) is always zeroed.A four-region Hopf network driven by the simulator:
>>> import brainmass >>> import brainunit as u >>> import numpy as np >>> N = 4 >>> conn = np.ones((N, N)) * 0.1 >>> node = brainmass.HopfStep(N, a=0.1) >>> net = brainmass.Network(node, conn=conn, coupled_var='x', k=0.5) >>> sim = brainmass.Simulator(net, dt=0.1 * u.ms) >>> res = sim.run(5.0 * u.ms, monitors=lambda m: m.node.x.value) >>> res['output'].shape (50, 4)
- Return type:
Any
- __init__(node, *, conn, distance=None, speed=None, coupling='diffusive', coupled_var, k=1.0, delay_init=Uniform(low=0.0, high=0.05), self_connection=False, noise=None)[source]#
Methods
__init__(node, *, conn[, distance, speed, ...])check_valid_context(error_msg)Raise
TraceContextErrorif the node's trace context is invalid.children()Return immediate child modules.
desc(*args, **kwargs)Create a parameter describer for this class.
init_all_states(*args[, state_tag])init_state(*args, **kwargs)Validate
coupled_varonce the node's states exist.modules([include_self])Return all modules in the network.
named_children()Return an iterator over immediate child modules, yielding name and module.
named_modules([prefix, include_self])Return an iterator over all modules in the network, yielding name and module.
named_param_modules([allowed_hierarchy])Iterate over (name, parameter) pairs.
named_parameters([prefix, recurse])Return an iterator over module parameters, yielding name and parameter.
nodes(*filters[, allowed_hierarchy])Collect all children nodes.
param_modules([allowed_hierarchy])Collect all Param parameters in this module and children.
param_precompute([allowed_hierarchy])Context manager to temporarily cache all Param parameters.
parameters([recurse])Return module parameters.
reg_loss()Compute total regularization loss from all Param parameters.
reset_state(*args, **kwargs)State resetting function.
state_trees(*filters)Collect all states in this node and the children nodes.
states(*filters[, allowed_hierarchy])Collect all states in this node and the children nodes.
update(*node_inputs)Advance one step: coupling current (+ noise) -> node.
Attributes
graph_invisible_attrsin_sizenameName of the model.
non_hashable_paramsout_size- __init__(node, *, conn, distance=None, speed=None, coupling='diffusive', coupled_var, k=1.0, delay_init=Uniform(low=0.0, high=0.05), self_connection=False, noise=None)[source]#
- update(*node_inputs)[source]#
Advance one step: coupling current (+ noise) -> node.
- Parameters:
*node_inputs – Extra inputs forwarded to the node after the coupling current (e.g. a second drive supplied by
brainmass.Simulator.run()). The coupling current is always the node’s first positional input.- Returns:
The node’s
updatereturn value.- Return type:
Any