HORNSeqLayer#
- class brainmass.HORNSeqLayer(n_input, n_hidden, alpha=0.04, omega=0.2243994752564138, gamma=0.01, v=0.0, delay_init=ZeroInit(unit=1), x_init=ZeroInit(unit=1), y_init=ZeroInit(unit=1), delay=None, rec_w_init=KaimingNormal(mode=fan_in, nonlinearity=relu, unit=1), rec_b_init=ZeroInit(unit=1), inp_w_init=KaimingNormal(mode=fan_in, nonlinearity=relu, unit=1), inp_b_init=ZeroInit(unit=1))[source]#
Sequential layer wrapper for HORN dynamics with input and recurrent connections.
This layer combines a
HORNStepdynamics model with trainable input-to-hidden and hidden-to-hidden (recurrent) linear transformations to process sequential data. It supports optional synaptic delays in recurrent connections and processes entire input sequences using a for-loop scan operation.The layer computes:
\[\begin{split}\begin{aligned} \mathbf{I}_{t+1}^{\mathrm{ext}} &= \mathbf{W}^{ih} \mathbf{s}_{t+1} + \mathbf{b}^{ih}, \\ \mathbf{I}_{t+1}^{\mathrm{rec}} &= \mathbf{W}^{hh} \mathbf{y}_t + \mathbf{b}^{hh} + \mathbf{v} \cdot \mathbf{x}_t, \\ \mathbf{out}_t &= \text{HORNStep}(\mathbf{I}_{t}^{\mathrm{ext}} + \mathbf{I}_{t}^{\mathrm{rec}}), \end{aligned}\end{split}\]where \(\mathbf{s}\) is the input sequence, \(\mathbf{W}^{ih}, \mathbf{b}^{ih}\) are input weights/biases, \(\mathbf{W}^{hh}, \mathbf{b}^{hh}\) are recurrent weights/biases, and the output is the position state \(\mathbf{x}\) from the HORN dynamics.
- Parameters:
n_input (
int) – Dimensionality of input features at each time step.n_hidden (
int) – Dimensionality of the hidden state (number of HORN oscillators).alpha (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|Param) – Excitability factor for HORN dynamics (dimensionless). Broadcastable ton_hidden. Default is0.04.omega (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|Param) – Natural frequency for HORN dynamics (radians per time step). Default is2π/28 ≈ 0.224.gamma (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|Param) – Damping coefficient for HORN dynamics (dimensionless). Default is0.01.v (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|Param) – Amplitude feedback coefficient (dimensionless). Default is0.0.x_init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Initializer for HORN position state \(\mathbf{x}\). Default isbraintools.init.ZeroInit().y_init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Initializer for HORN velocity state \(\mathbf{y}\). Default isbraintools.init.ZeroInit().delay (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|Callable|None) – Synaptic delay configuration for recurrent connections. If provided, creates a(n_hidden, n_hidden)delay matrix where each entry specifies the number of time steps to delay that connection. WhenNone, no delays are used. Default isNone.rec_w_init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Initializer for recurrent weight matrix \(\mathbf{W}^{hh}\). Default isbraintools.init.KaimingNormal().rec_b_init (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|Callable|None) – Initializer for recurrent bias vector \(\mathbf{b}^{hh}\). IfNone, no recurrent bias is used. Default isbraintools.init.ZeroInit().inp_w_init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Initializer for input weight matrix \(\mathbf{W}^{ih}\). Default isbraintools.init.KaimingNormal().inp_b_init (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|Callable|None) – Initializer for input bias vector \(\mathbf{b}^{ih}\). IfNone, no input bias is used. Default isbraintools.init.ZeroInit().
- Return type:
Any
- i2h#
Input-to-hidden linear transformation with shape
(n_input, n_hidden).- Type:
brainstate.nn.Linear
- h2h#
Hidden-to-hidden recurrent transformation. When
delayisNone, this is a standardLinearlayer with shape(n_hidden, n_hidden). Whendelayis specified, this is anAdditiveCouplingoperator that applies delayed synaptic connections.- Type:
brainstate.nn.Linear or AdditiveCoupling
Notes
Sequential processing: The
updatemethod usesbrainstate.transform.for_loopto scan over the time dimension of the input sequence, maintaining the HORN hidden states across time steps.Delay implementation: When synaptic delays are specified via the
delayparameter, the layer uses anAdditiveCouplingoperator that prefetches delayed values of the velocity state \(\mathbf{y}\) from a ring buffer. This enables modeling of axonal/dendritic delays in recurrent connections.State recording: The
record_stateparameter in theupdatemethod allows recording both position and velocity states at each time step, returning them alongside the output sequence.Parameter sharing: All HORN dynamics parameters (
alpha,omega,gamma,v,h) are shared across all oscillators in the layer, though they can be initialized as arrays to provide per-oscillator heterogeneity.
See also
HORNStepSingle-step HORN dynamics
HORNSeqNetworkMulti-layer HORN network