nstat.simulate_two_neuron_network

nstat.simulate_two_neuron_network(duration_s=50.0, dt=0.001, baseline_mu=(-3.0, -3.0), history_kernel=(-4.0, -2.0, -1.0), stimulus_kernel=(1.0, -1.0), ensemble_kernel=(1.0, -4.0), stimulus_frequency_hz=1.0, seed=13, uniform_values=None, backend='auto')[source]

Standalone Python replacement for the MATLAB/Simulink 2-neuron NetworkTutorial.

Simulates two coupled neurons on the grid arange(0, duration_s + dt, dt). In each bin the log-odds of spiking for neuron i is the baseline plus self-history, a sinusoidal stimulus drive, and the other neuron’s previous-bin spike; the spike probability is the logistic function of that sum.

Parameters:
  • duration_s (float, default 50.0) – Simulation length in seconds. Must be positive.

  • dt (float, default 0.001) – Time step (bin width) in seconds. Must be positive.

  • baseline_mu (tuple of float, default (-3.0, -3.0)) – Per-neuron baseline log-odds (one value per neuron).

  • history_kernel (tuple of float, default (-4.0, -2.0, -1.0)) – Self-history filter coefficients shared by both neurons, ordered from the most recent bin (lag 1) backwards.

  • stimulus_kernel (tuple of float, default (1.0, -1.0)) – Per-neuron gain applied to the sinusoidal stimulus.

  • ensemble_kernel (tuple of float, default (1.0, -4.0)) – Coupling coefficients: the first entry is the effect of neuron 2’s previous-bin spike on neuron 1, the second the effect of neuron 1 on neuron 2.

  • stimulus_frequency_hz (float, default 1.0) – Frequency of the sinusoidal stimulus sin(2*pi*f*t).

  • seed (int or None, default 13) – Seed for numpy.random.default_rng; ignored when uniform_values is given.

  • uniform_values (numpy.ndarray, optional) – Pre-drawn uniform variates of shape (len(time), 2) for deterministic tests. Used by the native Python backend only.

  • backend ({‘auto’, ‘matlab’, ‘python’}, default 'auto') – Simulation backend. 'auto' uses MATLAB/Simulink when available and falls back to native Python with a warning. 'matlab' forces Simulink (raises if unavailable). 'python' forces the native implementation.

Returns:

Time grid, latent drive, per-bin spike probabilities, the two simulated spike trains (neuron_1, neuron_2), the coupling matrix and the kernels used. The per-bin eta, history_effect, ensemble_effect, spike_indicator and uniform_values diagnostics are populated by the Python backend only.

Return type:

NetworkSimulationResult

Raises:
  • ValueError – If duration_s or dt is not positive, backend is not one of the accepted values, or uniform_values has the wrong shape.

  • RuntimeError – If backend='matlab' is requested but MATLAB or the nSTAT MATLAB path is unavailable.