Python codes for Spikes, decisions, and actions, Wilson 1999¶
Installation, How to use¶
using on Colab (Recommended)
Go to examples
Open a notebook and click on “open on colab”
Uncomment the cell with pip install command to install the netsci package.
using on local machines
pip3 install -e .
# or
pip install "git+https://github.com/Ziaeemehr/spikes.git"
Indices and tables¶
Chapters¶
Contents:
- Chapter 3
- Chapter 4
- Chapter 5
- Chapter 6
- Nonlinear neurodynamics and bifurcations
- Step 1: Define the System of Differential Equations
- Step 2: Find the Nullclines
- Step 3: Use SymPy to Solve for Nullclines
- Step 4: Plot the Nullclines Using Matplotlib
- Example
- Explanation
- Tools Used
- pplane
- Stabiliby of steady states
- A short-term memory circuit
- Hysteresis, bifurcation, and memory
- Adaptation, forgetting, and catastrophe theory
- Competition and neural decisions
API and documentation¶
spikes.utils¶
- characteristic_polynomial(matrix)[source]¶
Computes the characteristic polynomial of a given matrix.
- Parameters:
- matrix: (list of lists)
A 2D list representing the matrix.
- Returns:
- sympy.Poly:
The characteristic polynomial of the matrix.
- routh(p)[source]¶
Construct the Routh-Hurwitz array given a polynomial in s
- Parameters:
- p: sympy.Poly
The characteristic polynomial of coefficient matrix
- Returns:
- value: sympy.Matrix
The Routh-Hurwitz array
- References https://github.com/alchemyst/Dynamics-and-Control/blob/master/tbcontrol/symbolic.py
spikes.plot¶
- plot_direction_field(A: ndarray, B: ndarray, x1_range: tuple = (-2, 2), x2_range: tuple = (-2, 2), num_points: int = 20, ax=None, xlabel: str = 'x1', ylabel: str = 'x2', title: str = 'Direction Field for the System $dX/dt = AX + B$', **kwargs)[source]¶
Plots the direction field for the system dx/dt = A * X + B.
- Parameters:
- Anumpy.ndarray
A 2x2 numpy array representing the coefficient matrix for the linear system.
- Bnumpy.ndarray
A 1x2 numpy array representing the constant vector.
- x1_rangetuple, optional
The range for x1 values. Default is (-10, 10).
- x2_rangetuple, optional
The range for x2 values. Default is (-10, 10).
- num_pointsint, optional
The number of points per axis in the grid. Default is 20.
- Returns:
- axmatplotlib.axes.Axes
The axis object with the direction field plotted.
- plot_nullclines(f, g, symbols: List[str], x_range=(-2, 2), y_range=(-2, 2), num_points=400, figsize: tuple = (4, 4), title: str = 'Nullclines of the system', grid=False, ax=None, loc='best', **kwargs: dict)[source]¶
Plots the nullclines of a two-dimensional system of differential equations.
- Parameters:
- fsympy expression
The right-hand side of the first differential equation dx/dt = f(x, y).
- gsympy expression
The right-hand side of the second differential equation dy/dt = g(x, y).
- x_rangetuple, optional
The range of x values for plotting (default is (-2, 2)).
- y_rangetuple, optional
The range of y values for plotting (default is (-2, 2)).
- num_pointsint, optional
The number of points to plot (default is 400).
- loc: string, optional
The location of the legend (default is ‘best’).
- **kwargsdict
Additional keyword arguments to be passed to
plt.plot
.
- Returns:
- axmatplotlib.axes.Axes
The axis object with the nullclines plotted.
spikes.solver¶
- solve_system_of_equations(A_np: ndarray, B_np: ndarray, X0_np: ndarray, t_range: ndarray, t0: float = 0, verbose: bool = True)[source]¶
Solve a system of first-order linear differential equations of any size.
- Parameters:
A_np (ndarray) – Coefficient matrix A.
B_np (ndarray) – Constant vector B.
X0_np (ndarray) – Initial condition vector X0.
t_range (array-like) – Range of time points over which to evaluate the solution.
t0 (float) – Initial time, default is 0.
- Returns:
A tuple containing: - final_solution (list): List of symbolic solutions. - x_values (list): List of evaluated solution values over t_range.
- Return type:
tuple
- solve_linear_system_numerical(A, B, X0, t)[source]¶
Solves the differential equation dX/dt = AX + B.
- Parameters:
A (numpy.ndarray) – Coefficient matrix.
B (numpy.ndarray) – Constant vector.
X0 (numpy.ndarray) – Initial condition vector.
t (numpy.ndarray) – Array of time points at which to solve.
- Returns:
Array of solution vectors at each time point.
- Return type:
numpy.ndarray