# `brainpy.analysis` module¶

## Summary¶

 `PhasePlane`(integrals, target_vars[, …]) A tool class for phase plane analyzer. `Bifurcation`(integrals, target_pars, target_vars) A tool class for bifurcation analysis. `FastSlowBifurcation`(integrals, fast_vars, …) Fast slow analysis analysis proposed by John Rinzel 1 2 3. Get the stability types of 1D system. Get the stability types of 2D system. Get the stability types of 3D system. `stability_analysis`(derivatives) Stability analysis for fixed points.

## Phase Plane Analysis¶

We provide a fundamental class PhasePlane to help users make phase plane analysis for 1D/2D dynamical systems. Five methods are provided, which can help you to plot:

• Fixed points

• Nullcline (zero-growth isoclines)

• Vector filed

• Limit cycles

• Trajectory

class brainpy.analysis.PhasePlane(integrals, target_vars, fixed_vars=None, pars_update=None, numerical_resolution=0.1, options=None)[source]

A tool class for phase plane analyzer.

PhasePlaneAnalyzer is used to analyze the phase portrait of 1D or 2D dynamical systems. It can also be used to analyze the phase portrait of high-dimensional system but with the fixation of other variables to preserve only one/two dynamical variables.

Parameters
• integrals (NeuType) – The neuron model which defines the differential equations by using brainpy.integrate.

• target_vars (dict) – The target variables to analyze, with the format of {‘var1’: [var_min, var_max], ‘var2’: [var_min, var_max]}.

• fixed_vars (dict, optional) – The fixed variables, which means the variables will not be updated.

• pars_update (dict, optional) – The parameters in the differential equations to update.

• numerical_resolution (float, dict) – The variable resolution for numerical iterative solvers. This variable will be useful in the solving of nullcline and fixed points by using the iterative optimization method. It can be a float, which will be used as `numpy.arange(var_min, var_max, resolution)`. Or, it can be a dict, with the format of `{'var1': resolution1, 'var2': resolution2}`. Or, it can be a dict with the format of ```{'var1': np.arange(x, x, x), 'var2': np.arange(x, x, x)}```.

• options (dict, optional) –

The other setting parameters, which includes:

lim_scale

float. The axis limit scale factor. Default is 1.05. The setting means the axes will be clipped to `[var_min * (1-lim_scale)/2, var_max * (var_max-1)/2]`.

sympy_solver_timeout

float, with the unit of second. The maximum time allowed to use sympy solver to get the variable relationship.

escape_sympy_solver

bool. Whether escape to use sympy solver, and directly use numerical optimization method to solve the nullcline and fixed points.

shgo_args

dict. Arguments of shgo optimization method, which can be used to set the fields of: constraints, n, iters, callback, minimizer_kwargs, options, sampling_method.

show_shgo

bool. whether print the shgo’s value.

perturbation

float. The small perturbation used to solve the function derivative.

fl_tol

float. The tolerance of the function value to recognize it as a condidate of function root point.

xl_tol

float. The tolerance of the l2 norm distances between this point and previous points. If the norm distances are all bigger than xl_tol means this point belong to a new function root point.

plot_fixed_point(*args, **kwargs)[source]

Plot fixed points.

Parameters

show (bool) – Whether show the figure.

plot_limit_cycle_by_sim(initials, duration, tol=0.001, show=False)[source]

Plot limit cycles according to the settings.

Parameters
• initials (list, tuple) – The initial value setting of the targets. It can be a tuple/list of floats to specify each value of dynamical variables (for example, `(a, b)`). It can also be a tuple/list of tuple to specify multiple initial values (for example, `[(a1, b1), (a2, b2)]`).

• duration (int, float, tuple, list) – The running duration. Same with the `duration` in `NeuGroup.run()`. It can be a int/float (`t_end`) to specify the same running end time, or it can be a tuple/list of int/float (`(t_start, t_end)`) to specify the start and end simulation time. Or, it can be a list of tuple (`[(t1_start, t1_end), (t2_start, t2_end)]`) to specify the specific start and end simulation time for each initial value.

• show (bool) – Whether show or not.

plot_nullcline(*args, **kwargs)[source]

Plot nullcline (only supported in 2D system).

Parameters

show (bool) – Whether show the figure.

plot_trajectory(initials, duration, plot_duration=None, axes='v-v', show=False)[source]

Plot trajectories according to the settings.

Parameters
• initials (list, tuple, dict) – The initial value setting of the targets. It can be a tuple/list of floats to specify each value of dynamical variables (for example, `(a, b)`). It can also be a tuple/list of tuple to specify multiple initial values (for example, `[(a1, b1), (a2, b2)]`).

• duration (int, float, tuple, list) – The running duration. Same with the `duration` in `NeuGroup.run()`. It can be a int/float (`t_end`) to specify the same running end time, or it can be a tuple/list of int/float (`(t_start, t_end)`) to specify the start and end simulation time. Or, it can be a list of tuple (`[(t1_start, t1_end), (t2_start, t2_end)]`) to specify the specific start and end simulation time for each initial value.

• plot_duration (tuple, list, optional) – The duration to plot. It can be a tuple with `(start, end)`. It can also be a list of tuple `[(start1, end1), (start2, end2)]` to specify the plot duration for each initial value running.

• axes (str) –

The axes to plot. It can be:

• ’v-v’

Plot the trajectory in the ‘x_var’-‘y_var’ axis.

• ’t-v’

Plot the trajectory in the ‘time’-‘var’ axis.

• show (bool) – Whether show or not.

plot_vector_field(*args, **kwargs)[source]

Plot vector filed of a 2D/1D system.

Parameters

show (bool) – Whether show the figure.

## Bifurcation Analysis¶

We also provide basic bifurcation analysis for 1D/2D dynamical systems.

class brainpy.analysis.Bifurcation(integrals, target_pars, target_vars, fixed_vars=None, pars_update=None, numerical_resolution=0.1, options=None)[source]

A tool class for bifurcation analysis.

The bifurcation analyzer is restricted to analyze the bifurcation relation between membrane potential and a given model parameter (co-dimension-1 case) or two model parameters (co-dimension-2 case).

Externally injected current is also treated as a model parameter in this class, instead of a model state.

Parameters
• integrals (function, functions) – The integral functions defined with brainpy.odeint or brainpy.sdeint or brainpy.ddeint, or brainpy.fdeint.

• target_vars (dict) – The target dynamical variables. It must a dictionary which specifies the boundary of the variables: {‘var1’: [min, max]}.

• fixed_vars (dict) – The fixed variables. It must a fixed value with the format of {‘var1’: value}.

• target_pars (dict, optional) – The parameters which can be dynamical varied. It must be a dictionary which specifies the boundary of the variables: {‘par1’: [min, max]}

• pars_update (dict, optional) – The parameters to update. Or, they can be treated as staitic parameters. Same with the fixed_vars, they are must fixed values with the format of {‘par1’: value}.

• numerical_resolution (float, dict) – The resolution for numerical iterative solvers. Default is 0.1. It can set the numerical resolution of dynamical variables or dynamical parameters. For example, set `numerical_resolution=0.1` will generalize it to all variables and parameters; set `numerical_resolution={var1: 0.1, var2: 0.2, par1: 0.1, par2: 0.05}` will specify the particular resolutions to variables and parameters. Moreover, you can also set `numerical_resolution={var1: np.array([...]), var2: 0.1}` to specify the search points need to explore for variable var1. This will be useful to set sense search points at some inflection points.

• options (dict, optional) –

The other setting parameters, which includes:

perturbation

float. The small perturbation used to solve the function derivatives.

sympy_solver_timeout

float, with the unit of second. The maximum time allowed to use sympy solver to get the variable relationship.

escape_sympy_solver

bool. Whether escape to use sympy solver, and directly use numerical optimization method to solve the nullcline and fixed points.

lim_scale

float. The axis limit scale factor. Default is 1.05. The setting means the axes will be clipped to `[var_min * (1-lim_scale)/2, var_max * (var_max-1)/2]`.

The parameters which are usefull for two-dimensional bifurcation analysis:

shgo_args

dict. Arguments of shgo optimization method, which can be used to set the fields of: constraints, n, iters, callback, minimizer_kwargs, options, sampling_method.

show_shgo

bool. whether print the shgo’s value.

fl_tol

float. The tolerance of the function value to recognize it as a candidate of function root point.

xl_tol

float. The tolerance of the l2 norm distances between this point and previous points. If the norm distances are all bigger than xl_tol means this point belong to a new function root point.

plot_bifurcation(*args, **kwargs)[source]

Plot bifurcation, which support bifurcation analysis of co-dimension 1 and co-dimension 2.

Parameters

show (bool) – Whether show the bifurcation figure.

Returns

points – The bifurcation points which specifies their fixed points and corresponding stability.

Return type

dict

plot_limit_cycle_by_sim(var, duration=100, inputs=(), plot_style=None, tol=0.001, show=False)[source]

Plot limit cycles by the simulation results.

This function help users plot the limit cycles through the simulation results, in which the periodic signals will be automatically found and then treated them as the candidate of limit cycles.

Parameters
• var (str) – The target variable to found its limit cycles.

• duration (int, float, tuple, list) – The simulation duration.

• inputs (tuple, list) – The simulation inputs.

• plot_style (dict) – The limit cycle plotting style settings.

• tol (float) – The tolerance to found periodic signals.

• show (bool) – Whether show the figure.

## Fast-slow System Analysis¶

For some 3D dynamical system, which can be treated as a fast-slow system, they can be easily analyzed through our provided FastSlowBifurcation.

class brainpy.analysis.FastSlowBifurcation(integrals, fast_vars, slow_vars, fixed_vars=None, pars_update=None, numerical_resolution=0.1, options=None)[source]

Fast slow analysis analysis proposed by John Rinzel 1 2 3.

(J Rinzel, 1985, 1986, 1987) proposed that in a fast-slow dynamical system, we can treat the slow variables as the bifurcation parameters, and then study how the different value of slow variables affect the bifurcation of the fast sub-system.

Parameters
• integrals (function, functions) – The integral functions defined with brainpy.odeint or brainpy.sdeint or brainpy.ddeint, or brainpy.fdeint.

• fast_vars (dict) – The fast dynamical variables. It must a dictionary which specifies the boundary of the variables: {‘var1’: [min, max]}.

• slow_vars (dict) – The slow dynamical variables. It must a dictionary which specifies the boundary of the variables: {‘var1’: [min, max]}.

• fixed_vars (dict) – The fixed variables. It must a fixed value with the format of {‘var1’: value}.

• pars_update (dict, optional) – The parameters to update. Or, they can be treated as staitic parameters. Same with the fixed_vars, they are must fixed values with the format of {‘par1’: value}.

• numerical_resolution (float, dict) – The resolution for numerical iterative solvers. Default is 0.1. It can set the numerical resolution of dynamical variables or dynamical parameters. For example, set `numerical_resolution=0.1` will generalize it to all variables and parameters; set `numerical_resolution={var1: 0.1, var2: 0.2, par1: 0.1, par2: 0.05}` will specify the particular resolutions to variables and parameters. Moreover, you can also set `numerical_resolution={var1: np.array([...]), var2: 0.1}` to specify the search points need to explore for variable var1. This will be useful to set sense search points at some inflection points.

• options (dict, optional) –

The other setting parameters, which includes:

perturbation

float. The small perturbation used to solve the function derivatives.

sympy_solver_timeout

float, with the unit of second. The maximum time allowed to use sympy solver to get the variable relationship.

escape_sympy_solver

bool. Whether escape to use sympy solver, and directly use numerical optimization method to solve the nullcline and fixed points.

lim_scale

float. The axis limit scale factor. Default is 1.05. The setting means the axes will be clipped to `[var_min * (1-lim_scale)/2, var_max * (var_max-1)/2]`.

References

1(1,2)

Rinzel, John. “Bursting oscillations in an excitable membrane model.” In Ordinary and partial differential equations, pp. 304-316. Springer, Berlin, Heidelberg, 1985.

2(1,2)

Rinzel, John , and Y. S. Lee . On Different Mechanisms for Membrane Potential Bursting. Nonlinear Oscillations in Biology and Chemistry. Springer Berlin Heidelberg, 1986.

3(1,2)

Rinzel, John. “A formal classification of bursting mechanisms in excitable systems.” In Mathematical topics in population biology, morphogenesis and neurosciences, pp. 267-281. Springer, Berlin, Heidelberg, 1987.

plot_bifurcation(*args, **kwargs)[source]

Plot bifurcation.

Parameters

show (bool) – Whether show the bifurcation figure.

Returns

points – The bifurcation points which specifies their fixed points and corresponding stability.

Return type

dict

## Useful Functions¶

```>>> get_1d_stability_types()
['saddle node', 'stable point', 'unstable point']
```
```>>> get_2d_stability_types()