Classes¶
Models¶
-
models.FitzHughNagumo(x, y, a=0.7, b=0.8, tau=12.5)[source]¶ FitzHugh-Nagumo neuron model
A simplification of the Hodgekin-Huxley model of a squid Neuron. \(y=(V, W)\) where V is the membrane potential and W the ion conductivity, a slower recovery variable. \(x\) is the magnitude of the stimulus current and \(\{a,b,\tau\}\) are fit parameters:
\[ \begin{align}\begin{aligned}\dot{V} &= V - V^3/3 - W + x(t)\\\dot{W} &= (V+a-bW)/\tau\end{aligned}\end{align} \]
-
models.Yamada_0(x, y, P=0.8, gamma=1, kappa=50, beta=0.5)[source]¶ A simplification to Yamada_1 with a single medium.
\(y=(I, J)\), with J the inversion of the gain medium (\(J=G+Q,\gamma_1=\gamma_2=\gamma, a=1\)) with pump rate \(P=A+B\) and decay rate \(\gamma\). \(x=i_{in}\) is input current, \(\kappa\) is cavity loss rate and \(\beta\) is photon noise:
\[ \begin{align}\begin{aligned}\dot{I} &= -\kappa(1-J)I+\beta\\\dot{J} &= \gamma(P-J-IJ)+i_{in}(t)\end{aligned}\end{align} \]
-
models.Yamada_1(x, y, a=2.0, A=6.5, B=-6.0, gamma1=1, gamma2=1, kappa=50, beta=0.2)[source]¶ Full yamada model with input into gain medium.
\(y=(I, G, Q)\), where I is the laser field intensity, and G and Q are gain and saturable absorber inversions. \(x=i_{in}\) is input current, A and B are gain and absorber pump rates, a is the medium gain ratio, \(\gamma_i\), are material decay rates, \(\kappa\) is cavity loss rate, and \(\beta\) is photon noise:
\[ \begin{align}\begin{aligned}\dot{I} &= -\kappa(1-G-Q)I+\beta\\\dot{G} &= \gamma_1(A-G-IG)+i_{in}(t)\\\dot{Q} &= \gamma_2(B-Q-aIQ)\end{aligned}\end{align} \]
-
models.Yamada_2(x, y, a=1.0, A=6.5, B=-6.0, gamma1=1, gamma2=1, kappa=50, beta=0.2)[source]¶ Yamada_1 with input to cavity directly instead of gain medium.
\[ \begin{align}\begin{aligned}\dot{I} &= -\kappa(1-G-Q)I+\beta )+i_{in}(t)\\\dot{G} &= \gamma_1(A-G-IG)\\\dot{Q} &= \gamma_2(B-Q-aIQ)\end{aligned}\end{align} \]
Network¶
-
class
network.Network(neurons, weights, delays=None, dt=None)[source]¶ A Network is a specific topology of connected Neuron objects. Connections between neurons can be weighted, and also can carry a time delay. There can be multiple input sources, which can be connected to any neurons. These connections also have associated weights and time delays.
Once initialized, a Network’s primary method is to take in a set of signals at a given time-step and reveal the updated neuron states.
Parameters: - neurons – A list of neuron objects.
- weights – An np.array matrix of weights.
- delays – An np.array matrix of time delays, in absolute time.
- dt – The time step for propagating the network.
-
neurons¶ a list of the neuron objects which make up the network
-
weights¶ the np.array matrix of weights for the network (num_neuron X num_neuron+num_inputs)
-
delays¶ The np.array matrix of delays for the network, in units of dt (num_neuron X num_neuron)
-
dt¶ the time step for propagating the network.
-
num_inputs¶ the number of external inputs in the network
-
num_neurons¶ the number of neurons in the network
-
generate_neuron_inputs(external_inputs)[source]¶ Builds input array for next network step.
Each element in the array corresponds to a neuron in the network, calculated by summing all weighted and delayed inputs to that neuron. For each element, first adds weighted external inputs, then adds appropriately delayed weighted outputs from other neurons.
Parameters: external_inputs – A 1D array with the external inputs (i.e. non-neuron inputs). Returns: array of summed inputs to each neuron at current time Return type: np.array
-
network_inputs(network_outputs, external_inputs)[source]¶ Calculate the time-dependent input to each neuron in the network
Uses the previously solved for time dependent neuron states and given external inputs (so call after network_solve).
Parameters: network_outputs – A 2D array (num_timesteps X num_neuron) of the state of each neuron in the network at each time, as calculated from network_solve. external_inputs A 2D array (num_timesteps X num_inputs) of the external inputs (i.e. non-neuron inputs). Returns: A 2D array (num_timesteps X num_neuron) of the total wieghter and delayed input (integrated internal and external) to each neuron at each time. Return type: np.array
-
network_solve(external_inputs)[source]¶ Solve the network given an array of time dependent external inputs.
Steps the network forward in time for each successive row of external_inputs using network_step, with the columns defining the input to each neuron. External inputs is a num_timesteps X num_inputs array Outputs a num_timesteps X num_neuron array which is the network state at each time-step.
Parameters: external_inputs – A 2D array (num_timesteps X num_inputs) with the external inputs (i.e. non-neuron inputs). Returns: A 2D array (num_timesteps X num_neuron) of the state of each neuron in the network at each time. Return type: np.array
-
network_solve_full(external_inputs)[source]¶ Solve the network given an array of time dependent external inputs, as in network_solve, but returns the full phase space of each neuron, rather than just the state variable.
Parameters: external_inputs – A 2D array (num_timesteps X num_inputs) with the external inputs (i.e. non-neuron inputs). Returns: A 3D array (num_timesteps X num_neuron X neuron.dim) of the full state of each neuron in the network at each time. Return type: np.array
-
network_step(external_inputs)[source]¶ Steps the network forward in time by dt.
Each Neuron updates based on its state and its input, using its internal ode solver to compute its next time step.
Parameters: external_inputs – A (num_inputs X 1) array with the external inputs at the current time (i.e. non-neuron inputs). Returns: The state (output) of each neuron after stepping forward by dt Return type: np.array
-
network_step_full(external_inputs, dim=1)[source]¶ - Steps the network forward in time by dt, just as network_step,
- with option to return full neuron state.
Use with network_solve_full or to see full phase space of each neuron as evolve. To return state of all of neurons internal variables (num_neurons X neuron.dim), include argument dims=dimension of neuron phase space
Parameters: - external_inputs – A (num_inputs X 1) array with the external inputs at the current time (i.e. non-neuron inputs).
- dims – Dimension of neuron state (1 if only want output)
Returns: The dims-dimensional state of each neuron after stepping forward by dt
Return type: np.array
-
return_states(dims=None)[source]¶ Return the state of the network (by querying each neuron).
If want the state of all of neurons internal variables, include argument dims=dimension of neuron phase space.
- dims
- Dimension of neuron
Returns: The state of each neuron at the current time (num_neurons X dims) Return type: np.array
-
visualize_animation(inputs=None, outputs=None, t_mov=10)[source]¶ Visualize the neural network as a graph. The colors of the nodes are animated in response to their outputs as a function of time :param inputs: The inputs to the neural network :param outputs: The outputs of each neuron in the network :param t_mov: approximate length of movie in seconds
Returns: A matplotlib animation of the network dynamics Return type: matplotlib.animation.FuncAnimation
-
visualize_plot(inputs, outputs, time=None)[source]¶ Generate a simple and easy to read plot of the network dynamics.
After solving a network for a given set of inputs, pass these inputs and the computed result from network_solve to generate a plot. Use returned figure handle to update plot parameters from defaults if desired.
Parameters: - time – an array of time points which inputs and outputs are plotted over
- inputs –
- the 2D array (num_timesteps X num_neurons) array of total inputs
- to each neuron in the network
- outputs – the 2D array (num_timesteps X num_neurons) of the state of each neuron in the network as a function of time
Returns: A matplotlib figure instance showing the network dynamics
Return type: matplotlib.figure.Figure
Neuron¶
-
class
neuron.Neuron(params={})[source]¶ A Neuron object is a specific instance of a neuron model, which can exits on its own or as a member of a network.
A Neuron is initialized with
myneuron = Neuron(params), where params is an optional dict of parameter values for myneuron. Once initialized, the primary method of a neuron object is to calculate its evolution given an input.Parameters: - params – A dictionary of parameter values, elements described below:
- model – name of the evolution function \(\dot{y}=f(x,y)\)
implemented by neuron and described in
models.py. defaults to “identity” - solver – name of ODE solver used to update neuron state and solve its dynamics, default is “Euler”
- dt – time-step to use in ODE solver, defaults to 1.e-4
- hist_len – length of list of previous neuron states to store. default is 10
- y0 – initial state of neuron, defaults to zeros
- mpar – a dictionary of model specific parameters describing
a specific neuron instance. See
models.pyfor a given model’s parameters
-
y¶ current neuron state
-
y0¶ initial sate of neuron
-
hist¶ list of previous neuron states: hist[0] = y(t); hist[1] = y(t-dt); and so on. For multidimensional neurons, history only stores output/state variable.
-
hist_len¶ length of hist list, number of previous states neuron stores
-
dt¶ time step
-
model¶ name of the evolution function \(\dot{y}=f(x,y)\)
-
mpars¶ list of parameters of evolution function
-
dim¶ dimensionality of neuron phase space
-
set_dt(dt)[source]¶ Constructor helper function, sets time-step for neuron
Parameters: dt – time-step for neuron ODE solver
-
set_history(hist_len)[source]¶ Constructor helper function, initializes empty history list of previous neuron states
Parameters: hist_len – length of history list
-
set_initial_state(y0=None)[source]¶ Sets neuron initial state and clears neuron history
Parameters: y0 – new initial state for neuron
-
set_model_params(mkwargs)[source]¶ Constructor helper function, sets neuron’s evolution function
Parameters: mkwargs – model specific list of parameters for evolution function
-
solve(x)[source]¶ Calculates the neuron’s dynamics in response to an input signal x(t).
Uses the solver defined in
solverto step trough each element of x(t) and compute the resultant neuron evolution.Parameters: x – the time-dependent input signal (1d array) Returns: the resultant neuron phase space dynamics as a (neuron.dim X num_timesteps) array Return type: np.array
-
steady_state(yguess=None)[source]¶ solve for the no-input steady-state of the neuron.
Choose yguess “wisely” to avoid unphysical roots. We recommend testing steady state by running
myneuron.solve(np.zeros(N))and verifying the dynamics converge to the calculated steady-stateParameters: yguess – an initial guess of the steady-state; method will return fixed-point closest to yguess. Default is myneuron.y0Returns: The steady state of the neuron as calculated by setting \(f(0, y)=0\) and solving for y nearest to yguess Return type: np.array
-
step_Euler(x)[source]¶ Steps the neuron forward one time step using Euler’s method
Computes the state of the neuron at the next time step, given the current input signal and neuron state: \(y(n+1)=y(n)+dt\cdot f(x(n), y(n))\)
Parameters: x – the input signal at the current time (a scalar) Returns: The state of the neuron at t+dt Return type: np.array
-
step_RK4(x)[source]¶ Steps the neuron forward one time step using the fourth-order Runge-Kutta method
Computes the state of the neuron at the next time step, given the current input signal and neuron state: \(y(n+1)=y(n)+dt\cdot f(x(n), y(n))\)
Parameters: x – the input signal at the current time (a scalar) Returns: The state of the neuron at t+dt Return type: np.array
-
visualize_plot(x_in, output, time=None, ysteady=None)[source]¶ Generate a simple and easy to read plot of the neuron dynamics.
After solving a neuron for a given input signal, pass this and computed dynamics to generate a plot. Use returned figure handle to update plot parameters from defaults if desired.
Parameters: - time – an array of time points which input and output are plotted over
- x_in – the time-dependent input signal (1d array)
- outputs – the resultant neuron phase space dynamics as a (neuron.dim X num_timesteps) array
- ysteady – Optional neuron steady state to include in plot
Returns: A matplotlib figure instance showing the network dynamics
Return type: matplotlib.figure.Figure