pyeeg.simulate.CTRNN
- class pyeeg.simulate.CTRNN(N, W, input_dim=1, output_dim=1, dt=0.001, seed=42, nonlinearity=<function sigmoid>, theta=None, tau=1.0, solver='euler', x0=None)
Continuous Time Recurrent Neural Network (CTRNN) model.
The state \(x\) of the network evolves according to
\[\tau \dot{x} = -x + W o + I\]where \(o = f(x + \theta)\) is the output of the network through the nonlinearity \(f\), \(I\) is the external input projected through a (trainable) input matrix, and \(\theta\) is a bias term. A (trainable) readout matrix projects the node outputs to the desired output dimension, rescaled into the range [-1, 1] when the nonlinearity is a sigmoid.
- Parameters:
N (int) – The number of neurons/nodes.
W (array_like) – The connectivity matrix. Shape (N, N).
input_dim (int) – The dimension of the external input. The input is projected through a zero-initialised matrix of shape (N, input_dim).
output_dim (int) – The dimension of the readout. The node outputs are projected through a zero-initialised matrix of shape (output_dim, N).
dt (float) – The integration time step in seconds.
seed (int) – The random seed used to initialise the network’s random number generator.
nonlinearity (callable) – The nonlinearity function applied to the network state. Default is sigmoid (e.g. can use
np.tanh()).theta (array_like, optional) – The bias term. Shape (N,). If
None, a zero bias is used.tau (float or array_like) – The leaky-integrator time constant \(\tau\) in seconds. A scalar applies to all neurons, an array must have shape (N,). Defaults to 1.
solver (str or callable) – Integration scheme used by
step():"euler"(explicit Euler, the default),"euler-maruyama"or"em"(aliases of"euler": with noise the scheme is Euler-Maruyama),"rk4"(classical fourth-order Runge-Kutta), or a custom callable stepperf(derivative, x, dt, *args) -> x_new.x0 (array_like, optional) – The initial state. Shape (N,). If
None, the state starts at zero. The outputois initialised consistently with the state.
- Raises:
ValueError – If
tauis not positive or does not have shape()or(N,), ifsolveris not a supported name, or ifx0does not have shape (N,).
Methods
Compute the readout of the network.
Reset the network to its initial state.
CTRNN.simulate([x0, tmax, noise, I])Simulate the CTRNN model and monitor the output.
CTRNN.step([I, noise])Compute one step of the CTRNN model (the configured solver).