Caospy API

The modules are:

  • core: The core of the package, here we have: numerical integration, classification of one and two dimensional fixed points, Symbolic analysis; eigenvalues, eigenvectors and roots of systems.

  • trajectories: Treatment of numerically integrated trajectories of dynamical systems.

  • poincare: Generates the Poincare’s maps for periodic orbits.

  • predet_systems: It has predefined well known systems of ODE’s. Lorenz, Logistic, Duffing, RosslerChaos.


Module caospy.core

Stability and temporal analysis of dynamical systems.

class caospy.core.AutoSymbolic[source]

Bases: caospy.core.Symbolic

Initializes predetermined dynamical system.

class caospy.core.Functional(func, name, *variables)[source]

Bases: object

Dynamical system defined by its derivatives and name.

Callable type should take a state vector, a time value and a parameters vector and then must compute and return the derivative of the system in respect to a given state of it.

dy / dt = f(x, t, p)

Provides access to the attribute of the function that gives the derivatives for each variable, the name is also an attribute together with the variables in case these are defined.

Parameters
  • func (callable) –

    The func is used to compute the derivative of the system given a set of

    variable values, and parameters.

  • name (str) – System’s name.

  • *args – The variable arguments are the variable names, and sometimes are needed for implementing methods in subclasses.

func

This is where we store func.

Type

callable

name

This is where we store name.

Type

str

variables

System’s variable list.

Type

list, optional (default=[x_1, …, x_n])

Example

>>> def sample_function(x, t, p):
    x1, x2 = x
    p1, p2 = p
    dx1 = x1**2 + p1 * x2
    dx2 = -p2 * x2 + x1
    return [dx1, dx2]
>>> name = 'Sample System'
>>> sample_sys = Functional(sample_function, name)
>>> sample_sys.func
<function __main__.sample_function()>
>>> sample_sys.name
'Sample System'
poincare(x0, parameters, t_disc=5000, t_calc=50, n=None, met='RK45', rel_tol=1e-10, abs_tol=1e-12, mx_step=0.004)[source]

Integrates a system forward in time, eliminating the transient.

Then returns a Poincare type object, which can be worked with to get the Poincaré maps.

Parameters
  • x0 (list) – Set of initial conditions of the system. Values inside must be of int or float type.

  • parameters (list) – Set of parameter values for this particular case.

  • t_disc (int, optional (default=5000)) – Transient integration time to be discarded next.

  • t_calc (int, optional (default=50)) – Stationary integration time, the system’s states corresponding to this integration time interval are kept and pass to the Poincare object.

  • rel_tol (float, optional (default=1e-10)) – Relative tolerance of integrator.

  • abs_tol (float, optional (default=1e-12)) – Absolute tolerance of integrator.

  • mx_step (int, float, optional(default=0.01)) – Maximum integration step of integrator.

Returns

Poincare – Poincare object defined by t_calc time vector and matrix of states.

Return type

caospy.poincare.Poincare

Example

>>> sample_sys = Functional(sample_function, name)
>>> sample_x0 = [1, 0.5]
>>> sample_p = [2, 4]
>>> t_desc = 10000
>>> t_calc = 45
>>> p1 = sample_sys.poincare(sample_x0, sample_p, t_desc, t_calc)
>>> p1
<caospy.poincare.Poincare at 0x18d91028>
>>> type(p1)
caospy.poincare.Poincare
time_evolution(x0, parameters, ti=0, tf=200, n=None, met='RK45', rel_tol=1e-10, abs_tol=1e-12, mx_step=0.004)[source]

Integrates a system in forward time.

Parameters
  • x0 (list) – Set of initial conditions of the system. Values inside must be of int or float type.

  • parameters (list) – Set of the function’s parameter values for this particular case.

  • ti (int, float, optional (default=0)) – Initial integration time value.

  • tf (int, float, optional (default=200)) – Final integration time value.

  • rel_tol (float, optional (default=1e-10)) – Relative tolerance of integrator.

  • abs_tol (float, optional (default=1e-12)) – Absolute tolerance of integrator.

  • mx_step (int, float, optional (default=0.004)) – Maximum integration step of integrator.

Raises

ValueError – Final integration time must be greater than initial integration time.

Returns

Trajectory – Trajectory of a dynamical system in a given time interval.

Return type

caospy.trajectories.Trajectory

See also

scipy.integrate.solve_ivp, caospy.trajectories.Trajectory

Example

>>> sample_sys = Functional(sample_function, name)
>>> sample_x0 = [1, 0.5]
>>> sample_p = [2, 4]
>>> t1 = sample_sys.time_evolution(sample_x0, sample_p)
>>> t1
<caospy.trajectories.Trajectory at 0x18134df0>
>>> type(t1)
caospy.trajectories.Trajectory
exception caospy.core.LinearityError[source]

Bases: ValueError

Exception indicating unmatching number of equations and variables.

class caospy.core.MultiDim(x, f, params, name)[source]

Bases: caospy.core.MultiVarMixin, caospy.core.Symbolic

Multidimensional systems.

Implements the specific stability analysis tools and behaviorfor the multidimensional systems.

Example

>>> variables = ["x", "y"]
>>> functions = ["x+a*y", "b*x+c*y"]
>>> parameters = ["a", "b", "c"]
>>> sample_MultiDim = caospy.MultiDim(variables, functions, parameters,
                                      'sampleMultiDim')
>>> sample_MultiDim
<caospy.core.MultiDim object at 0x0000027861643A60>
class caospy.core.MultiVarMixin(x, f, params, name)[source]

Bases: caospy.core.Symbolic

Multivariable system’s specific implementations.

eigenvalues(p, initial_guess=[])[source]

Compute the eigenvalues, of all the system’s fixed points.

Parameters
  • p (list, tuple) – Set of parameter values, they should be int or float type.

  • initial_guess (list, tuple,) –

  • (default=[0 (optional) –

  • ...

  • 0])

Returns

out – Numpy array, of shape (i, j), where i is the number of fixed points, j is the number of variables.

Return type

array

Example

In order to implement the method, we initialize a MultiDim type object, see MultiDim class to know this implementation.

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 - x2']
>>> p = ['a', 'b', 'c']
>>> sample_multidim = caospy.MultiDim(v, f, p, 'sample_sys')
>>> p_values = [1, 1, 1]
>>> sample_multidim.eigenvalues(p_values)
array([[ 0.61803399, -1.61803399, -2.        ],
       [-0.61803399,  1.61803399,  2.        ]])
eigenvectors(p, initial_guess=[])[source]

Compute the eigenvectors, of all the system’s fixed points.

Parameters
  • p (list, tuple) – Set of parameter values, they should be int or float type.

  • initial_guess (list, tuple, optional (default=[0, …, 0])) –

Returns

out – Numpy array, of shape (i, j, k), where i is the number of fixed points, j is the number of variables.

The element i, j, k is the component in the kth direction, of the jth vector, of the ith root.

Return type

array

Example

In order to implement the method, we initialize a MultiDim type object, see MultiDim class to know this implementation.

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 - x2']
>>> p = ['a', 'b', 'c']
>>> sample_multidim = caospy.MultiDim(v, f, p, 'sample_sys')
>>> p_values = [1, 1, 1]
>>> sample_multidim.eigenvectors(p_values)
array([[[ 2.15353730e-01, -3.48449655e-01,  9.12253040e-01],
    [ 8.34001352e-01,  5.15441182e-01, -1.96881012e-01],
    [-7.07106781e-01, -7.07106781e-01, -1.76271580e-16]],
[[-2.15353730e-01, 3.48449655e-01, 9.12253040e-01],

[ 8.34001352e-01, 5.15441182e-01, 1.96881012e-01], [-7.07106781e-01, -7.07106781e-01, 1.76271580e-16]]])

full_linearize(p, initial_guess=[])[source]

Compute the roots, evaluated jacobians, eigenvalues and eigenvectors.

Parameters
  • p (list, tuple) – Set of parameter values, they should be int or float type.

  • initial_guess (list, tuple, optional (default=[0, …, 0])) –

Returns

out – List containing the roots as its first element, the evaluated jacobians as the second, the eigenvalues as third and finally the eigenvectors. The type and shape of each are the same as in their particular implementations. See fixed_points, jacob_eval, eigenvalues and eigenvectors for further detail.

Return type

list

Example

In order to implement the method, we initialize a MultiDim type object, see MultiDim class to know this implementation.

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 - x2']
>>> p = ['a', 'b', 'c']
>>> sample_multidim = caospy.MultiDim(v, f, p, 'sample_sys')
>>> p_values = [1, 1, 1]
>>> sample_symbolic.full_linearize(p_values)
       [array([[-1., -1.,  1.],
       [ 1.,  1.,  1.]]), array([[[-1., -1.,  0.],
        [ 0., -2., -1.],
        [ 1., -1.,  0.]],
       [[ 1.,  1.,  0.],
        [ 0.,  2., -1.],
        [ 1., -1.,  0.]]]), array([[ 0.61803399, -1.61803399, -2.],
       [-0.61803399,  1.61803399,  2.        ]]),
       array([[[ 2.15353730e-01, -3.48449655e-01,  9.12253040e-01],
        [ 8.34001352e-01,  5.15441182e-01, -1.96881012e-01],
        [-7.07106781e-01, -7.07106781e-01, -1.76271580e-16]],
       [[-2.15353730e-01,  3.48449655e-01,  9.12253040e-01],
        [ 8.34001352e-01,  5.15441182e-01,  1.96881012e-01],
        [-7.07106781e-01, -7.07106781e-01,  1.76271580e-16]]])]
jacob_eval(p, initial_guess=[])[source]

Compute the evaluated fixed points Jacobian matrix.

Parameters
  • p (list, tuple) – Set of parameter values, they should be int or float type.

  • initial_guess (list, tuple, optional (default=[0, …, 0])) –

Returns

out – Numpy array, of shape (i, j, k), where i is the number of fixed points, j is the number of equations of the system, and k the number of variables. For design reasons j=k.

The element i, j, k is the derivative of the function j respect to the variable k evaluated in the ith fixed point.

Return type

array

Example

In order to implement the method, we initialize a MultiDim type object, see MultiDim class to know this implementation.

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 - x2']
>>> p = ['a', 'b', 'c']
>>> p_values = [-1, 3, 5]
>>> sample_multidim = caospy.MultiDim(v, f, p, 'sample_sys')
>>> sample_multidim.jacob_eval(p_values)
array([[[ 0. -2.23606798j,  0. -0.4472136j ,  0. +0.j        ],
        [ 0. +0.j        ,  0.-13.41640786j, -1. +0.j        ],
        [ 5. +0.j        , -1. +0.j        ,  0. +0.j        ]],
[[ 0. +2.23606798j, 0. +0.4472136j , 0. +0.j ],

[ 0. +0.j , 0.+13.41640786j, -1. +0.j ], [ 5. +0.j , -1. +0.j , 0. +0.j ]]])

class caospy.core.OneDim(x, f, params, name)[source]

Bases: caospy.core.OneDimMixin, caospy.core.Symbolic

Captures the specific tools of analysis for onedimensional systems.

Has the same attributes as the Symbolic class.

Example

>>> v = ['x1']
>>> f = ['a * x1**2 + b * x1 + c']
>>> p = ['a', 'b', 'c']
>>> sample_onedim = caospy.OneDim(v, f, p, 'sample_1d')
>>> sample_onedim
<caospy.core.OneDim object at 0x0000027546C36850>
class caospy.core.OneDimMixin(x, f, params, name)[source]

Bases: caospy.core.Symbolic

Specific behaviors of onedimensional systems.

stability(parameters)[source]

Compute the slope of the derivative function at the fixed points.

It gives you the system’s stability

Parameters

parameters (list, tuple) – Set of values of the parameters, that specify the system.

Returns

out – Pandas data frame, which columns are “Fixed point”, “Slope”, “Stability”. It has a row for every fixed point of the system.

Return type

pd.DataFrame

Example

>>> v = ['x1']
>>> f = ['a * x1**2 + b * x1 + c']
>>> p = ['a', 'b', 'c']
>>> sample_onedim = caospy.OneDim(v, f, p, 'sample_1d')
>>> p_values = [1, 1, -4]
>>> sample_onedim.stability(p_values)
             Fixed Point     Slope  Stability
0   [1.5615528128088303]  4.123106      False
1  [-2.5615528128088303] -4.123106       True
class caospy.core.Symbolic(x, f, params, name)[source]

Bases: caospy.core.Functional

Dynamical system defined by variables, parameters and functions.

Variables, functions and parameters must be lists of strings, the number of variables must match the number of equations, and the name should be a string.

The available attributes are the inputed variables, functions, parameters and name just as they were given. And “privately” defined, are the variables and parameters dict, which will store the sympy.symbols for the parameters and variables, and lastly the sympy.Equations list containing the functions.

Parameters
  • x (list) – System’s list of variable names.

  • f (list) – System’s list of string functions.

  • params (list) – System’s list of parameter names.

  • name (str) – System’s name.

_name
Type

str

f

Here we store the f argument.

Type

list

x

Here we store the x argument.

Type

list

params

Here we store the params argument.

Type

list

_variables

Dictionary with variables stored with variable name of str type as keys and variables defined as sympy.Symbol as values.

Type

dict

_parameters

Dictionary with parameters stored with variable name of str type as keys and parameters defined as sympy.Symbol as values.

Type

dict

_equations

List with system’s functions stored as sympy.Equations, all equated to 0.

Type

list

Raises
  • TypeError – Name must be a string, got {type(name)} instead.

  • TypeError – The variables, functions and parameters should be lists, got {(type(x), type(f), type(params))} instead.

  • TypeError – All the elements must be strings.

  • ValueError – System must have equal number of variables and equations, instead has {len(x)} variables”and {len(f)} equations

Example

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 / x2']
>>> p = ['a', 'b', 'c']
>>> sample_symbolic = caospy.Symbolic(v, f, p, 'sample_sys')
>>> sample_symbolic
<caospy.core.Symbolic object at 0x000001A57CF094C0>

We can get the __init__ attributes as they were plugged:

>>> sample_symbolic.x
['x1', 'x2', 'x3']
>>> sample_symbolic.f
['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 / x2']
>>> sample_symbolic.params
['a', 'b', 'c']

In order to work with the sympy library, the arguments are adapted into sympy types and stored in different “private” attributes.

>>> sample_symbolic._name
'sample_sys'
>>> sample_symbolic._variables
{'x1': x1, 'x2': x2, 'x3': x3}
>>> sample_symbolic._parameters
{'a': a, 'b': b, 'c': c}
>>> sample_symbolic._equations
[Eq(-a + x1*x2, 0), Eq(b*x2**2 - x3, 0), Eq(c*x1/x2, 0)]
fixed_points(p, initial_guess=[])[source]

Return the roots of the system, given a set of parameters values.

If function is not implemented by sypmpy.solve, a set of initial guess values is needed.

Parameters
  • p (list, tuple) – Set of parameter values, they should be int or float type.

  • initial_guess (list, tuple, optional (default=[0, …, 0])) –

Returns

out – Numpy array containing one row per root, and one column per variable.

Return type

np.array

Example

>>> v = ['x1', 'x2', 'x3']
>>> f = ['x1 * x2 - a', '-x3 + b * (x2**2)', 'c * x1 - x2']
>>> p = ['a', 'b', 'c']
>>> p_values = [1, 1, 1]
>>> sample_symbolic.fixed_points(p_values)
array([[-1., -1.,  1.],
       [ 1.,  1.,  1.]])

Redefining the parameter values

>>> p_values = [-1, 3, 5]
>>> sample_symbolic.fixed_points(p_values)
array([[  0.-0.4472136j ,   0.-2.23606798j, -15.+0.j],
       [  0.+0.4472136j ,   0.+2.23606798j, -15.+0.j]])
class caospy.core.TwoDim(x, f, params, name)[source]

Bases: caospy.core.TwoDimMixin, caospy.core.Symbolic

Specific implementations 2D.

Englobes the specific implementations of the tools of analysis for systems.

Example

>>> variables = ["x", "y"]
>>> functions = ["x + a * y", "b * x + c * y"]
>>> parameters = ["a", "b", "c"]
>>> sample_TwoDim = caospy.TwoDim(variables, functions, parameters,
    "sample2d")
>>> sample_TwoDim
<caospy.core.TwoDim object at 0x0000027561643A60>
class caospy.core.TwoDimMixin(x, f, params, name)[source]

Bases: caospy.core.MultiVarMixin, caospy.core.Symbolic

Specific behaviors of twodimensional systems.

fixed_point_classify(params_values, initial_guess=[])[source]

Fix points classification in 2D.

Classifies the fixed points according to their linear stability, based on the values of the trace and determinant given by the evaluated jacobian matrix.

Parameters
  • params_values (list,``tuple``) – Set of specific parameter values to fix the system.

  • initial_guess (list, tuple, optional (default=[0, …, 0])) –

Returns

out – Pandas data frame with a row for every fixed point, and columns being: “var1”, “var2”, “λ_{1}$”, “$λ_{2}$”, “$σ$”, “$Δ$”, “$Type$”.

The first two columns have the values of the variables where the fixed point is. Then the two eigenvalues, the trace and determinant, and finally the classification of the fixed point.

Return type

DataFrame

Examples

>>> variables = ["x", "y"]
>>> functions = ["x + a * y", "b * x + c * y"]
>>> parameters = ["a", "b", "c"]
>>> sample_TwoDim = caospy.TwoDim(variables, functions, parameters,
                                  "sample2d")
>>> p_values = [2, 3, 4]
>>> sample_TwoDim.fixed_point_classify(p_values)
   $x$  $y$ $λ_{1}$ $λ_{2}$     $σ$      $Δ$  $Type$
0  0.0  0.0   -0.37    5.37  (5+0j)  (-2+0j)  Saddle
>>> functions = ["a * y", "-b * x - c * y"]
>>> p_values = [1, -2, 3]
>>> sample_TwoDim = caospy.TwoDim(variables, functions, parameters,
                                  'sample2d')
>>> sample_TwoDim.fixed_point_classify(p_values)
   $x$  $y$ $λ_{1}$ $λ_{2}$      $σ$     $Δ$       $Type$
0  0.0  0.0    -1.0    -2.0  (-3+0j)  (2+0j)  Stable Node

Module caospy.poincare

Poincare method for periodic orbits implemented.

class caospy.poincare.Map(t, n, i, var_names)[source]

Bases: object

Defines maps objects with iterations and values.

n0

n-th values of the variable map.

Type

np.array

n1

n+1-th values of the variable map.

Type

np.array

iterations

Values of the variable when intersecting the hyper-surface.

Type

np.array

t_iter

Values of the times when the trajectory intersects the hyper-surface.

Type

np.array

var_names

List of strings, whose first element is the name of the mapped variable and the second one is the name of the fitted variable.

Type

list

Example

>>> import caospy as cp
>>> lorenz = cp.Lorenz()
>>> x0 = [2.0, -1.0, 1.50]
>>> p = [10.0, 166.04, 8/3]
>>> poincare_lorenz = lorenz.poincare(x0, p, t_disc=500, t_calc=40)
>>> z_map = poincare_lorenz.map_v("z", "x")
>>> z_map.n0
array([ 0.        , 41.28553749, 41.2855924 , 41.28465165, 41.28434672,
       41.28455364, 41.28513428, 41.28593716, 41.28505819, 41.28443452,
       41.28438951, 41.28479233, 41.28549839, 41.28565587, 41.28468154,
       41.28434863, 41.2845339 , 41.28509986, 41.28589569, 41.28510502,
       41.28445035, 41.28438028, 41.28476469, 41.28545963, 41.28572109,
       41.28471292, 41.28435175, 41.28451505, 41.28506599, 41.28585437,
       41.28515349, 41.28446754, 41.28437212, 41.28473779, 41.28542123])
>>> z_map.n1
array([ 0.        , 41.2855924 , 41.28465165, 41.28434672, 41.28455364,
       41.28513428, 41.28593716, 41.28505819, 41.28443452, 41.28438951,
       41.28479233, 41.28549839, 41.28565587, 41.28468154, 41.28434863,
       41.2845339 , 41.28509986, 41.28589569, 41.28510502, 41.28445035,
       41.28438028, 41.28476469, 41.28545963, 41.28572109, 41.28471292,
       41.28435175, 41.28451505, 41.28506599, 41.28585437, 41.28515349,
       41.28446754, 41.28437212, 41.28473779, 41.28542123, 41.28578807])
>>> z_map.t_iter
array([ 0.96009601,  2.09620962,  3.22832283,  4.36043604,  5.49254925,
        6.62466247,  7.75677568,  8.89288929, 10.0250025 , 11.15711571,
       12.28922892, 13.42134213, 14.55745575, 15.68956896, 16.82168217,
       17.95379538, 19.08590859, 20.2180218 , 21.35413541, 22.48624862,
       23.61836184, 24.75047505, 25.88258826, 27.01870187, 28.15081508,
       29.28292829, 30.4150415 , 31.54715472, 32.67926793, 33.81538154,
       34.94749475, 36.07960796, 37.21172117, 38.34383438, 39.47994799])
>>> z_map.var_names
["z", "y"]
plot_cobweb(ax=None, kws_scatter=None, kws_rect=None)[source]

Plot the n > n + 1 map of the variable mapped.

Parameters
  • ax (matplotlib.pyplot.Axis, (optional)) – Matplotlib axis specification.

  • kws (`dict (optional)) – The parameters to send to set up the plot, like line colors, linewidth, marker face color, etc. Here is a list of available line properties: matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

Returns

A configuration representing the axis data.

Return type

AxesSubplot`

plot_iterations(ax=None, kws=None)[source]

Plot the axis variable versus the time of intersection.

Parameters
  • ax (matplotlib.pyplot.Axis, (optional)) – Matplotlib axis specification.

  • kws (`dict (optional)) – The parameters to send to set up the plot, like line colors, linewidth, marker face color, etc. Here is a list of available line properties: matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

Returns

A configuration representing the axis data.

Return type

AxesSubplot`

class caospy.poincare.Poincare(t, x, variables)[source]

Bases: caospy.trajectories.Trajectory

Implementation for Poincaré maps.

Is initialized from the poincare method in the Functional class of the core module.

Example

>>> v = ['x', 'y', 'z']
>>> f = ['sigma*(-x + y)', 'x*(rho - z) - y', '-beta*z + x*y']
>>> p = ['sigma', 'rho', 'beta']
>>> p_values = [166.04, 8/3, 10.0]
>>> sample_sys = caospy.Symbolic(v, f, p, 'sample')
>>> x0 = [2.0, -1.0, 150.0]
>>> sample_poincare = sample_sys.poincare(x0, p_values)
>>> sample_poincare
<caospy.poincare.Poincare object at 0x000002112AB322E0>
>>> sample_poincare.t
array([0.00000000e+00, 4.00032003e-03, 8.00064005e-03, ...,
       4.99919994e+01, 4.99959997e+01, 5.00000000e+01])
>>> sample_poincare.x
array([[4.0824829 , 4.0824829 , 4.0824829 , ..., 4.0824829 , 4.0824829 ,
        4.0824829 ],
       [4.0824829 , 4.0824829 , 4.0824829 , ..., 4.0824829 , 4.0824829 ,
        4.0824829 ],
       [1.66666667, 1.66666667, 1.66666667, ..., 1.66666667, 1.66666667,
        1.66666667]])
map_v(var, fixed, a=0, grade=2)[source]

Compute the Poincaré map of a trajectory.

Parameters
  • var (str, int) – Variable name or number whose map we want to generate.

  • fixed (str, int) – Variable name or number to fix a surface across which the stability will be evaluated.

  • a (float) – Value at which we want to fix the variable.

  • grade (int in (1, 2)) – Grade to fit the polynomial across the fixed surface.

Returns

map_var – Instance of class map.

Return type

Map

Example

>>> import caospy as cp
>>> lorenz = cp.Lorenz()
>>> x0 = [2.0, -1.0, 1.50]
>>> p = [10.0, 166.04, 8/3]
>>> poincare_lorenz = lorenz.poincare(x0, p, t_disc=500, t_calc=40)
>>> z_map = poincare_lorenz.map_v("z", "x")
>>> z_map.n0
array([ 0.        , 41.28553749, 41.2855924 , 41.28465165, 41.28434672,
    41.28455364, 41.28513428, 41.28593716, 41.28505819, 41.28443452,
    41.28438951, 41.28479233, 41.28549839, 41.28565587, 41.28468154,
    41.28434863, 41.2845339 , 41.28509986, 41.28589569, 41.28510502,
    41.28445035, 41.28438028, 41.28476469, 41.28545963, 41.28572109,
    41.28471292, 41.28435175, 41.28451505, 41.28506599, 41.28585437,
    41.28515349, 41.28446754, 41.28437212, 41.28473779, 41.28542123])

Module caospy.predet_systems

Set of predefined dynamical systems that are of common analysis.

class caospy.predet_systems.Duffing[source]

Bases: caospy.core.AutoSymbolic

Implementation for Duffing’s system defined by the following equations.

dx / dt = y dy / dt = -delta * y - alpha * x - beta x**3 + gamma * cos(omega * t) dt / dt = 1

The system has the same attributes as Symbolic and Functional types.

class caospy.predet_systems.Logistic[source]

Bases: caospy.core.OneDimMixin, caospy.core.AutoSymbolic

Implementation for Logistic system defined by the following equation.

dx / dt = r * N * (1 - N / k)

The system has the same attributes as Symbolic and Functional types.

Example

>>> sample_logistic = caospy.Logistic()
>>> sample_logistic.variables
['N']
>>> sample_logistic.f
['r * N * (1 - N / k)']
>>> sample_logistic.params
['r', 'k']
class caospy.predet_systems.Lorenz[source]

Bases: caospy.core.MultiVarMixin, caospy.core.AutoSymbolic

Implementation for Lorenz’s system defined by the following equations.

dx / dt = sigma * (y - x) dy / dt = x * (rho - z) - y dz / dt = x * y - beta * z

The system has the same attributes as Symbolic and Functional types.

Example

>>> sample_Lorenz = caospy.Lorenz()
>>> sample_Lorenz.variables
['x', 'y', 'z']
>>> sample_Lorenz.f
['sigma * (y - x)', 'x * (rho - z) - y', 'x * y - beta * z']
>>> sample_Lorenz.params
['sigma', 'rho', 'beta']
class caospy.predet_systems.RosslerChaos[source]

Bases: caospy.core.MultiVarMixin, caospy.core.AutoSymbolic

Implementation for Rossler’s (Chaos) system.

dx / dt = - (y + z) dy / dt = x + a * y dz / dt = b + z * (x - c)

The system has the same attributes as Symbolic and Functional types.

Example

>>> sample_RosslerChaos = caospy.RosslerChaos()
>>> sample_RosslerChaos.variables
['x', 'y', 'z']
>>> sample_RosslerChaos.f
['- (y + z)', 'x + a * y', 'b + z * (x - c)']
>>> sample_RosslerChaos.params
['a', 'b', 'c']
class caospy.predet_systems.RosslerHyperChaos[source]

Bases: caospy.core.MultiVarMixin, caospy.core.AutoSymbolic

Implementation for Rossler’s (Hyper Chaos) system.

dx / dt = - (y + z) dy / dt = x + a * y + w dz / dt = b + x * z dw / dt = c * w - d * z

The system has the same attributes as Symbolic and Functional types.

Example

>>> sample_RosslerHyperChaos = caospy.RosslerHyperChaos()
>>> sample_RosslerHyperChaos.variables
['x', 'y', 'z', 'w']
>>> sample_RosslerHyperChaos.f
['- (y + z)', 'x + a * y + w', 'b + x * z', 'c * w - d * z']
>>> sample_RosslerHyperChaos.params
['a', 'b', 'c', 'd']

Module caospy.trajectories

Treatment of integrated trajectories of dynamical systems.

class caospy.trajectories.Trajectory(t, x, variables)[source]

Bases: object

Time series and states matrix given from an integrated dynamical system.

The attributes defined for the object are the time vector, the state matrix, the number of variables and the column names. The time vector is a numpy.linspace defined by the integration time interval and the number of points or step defined.

The state matrix has the system’s variable values for every given time in the time vector.

If the vector’s name of the variables is empty, a name will automatically be assigned to each of them in the form $x_i$, where i = 0, 1 ,…, n with n variables.

x

Numpy array with shape (i, j). Being i the number of variables and j

the number of points of integration.

Type

np.array

t

Numpy array with the time interval defined in the integration.

Type

np.array

n_var

Number of variables of the system.

Type

int

cols

List with column names for data frame of trajectories.

Type

list

Example

>>> v = ['x', 'y']
>>> f = ['a * y', 'b * x - c * y']
>>> p = ['a', 'b', 'c']
>>> sample_sys = caospy.Symbolic(v, f, p, 'sample')
>>> p_values = [1, -2, 3]
>>> x0 = [1, 1]
>>> sample_trajectory = sample_sys.time_evolution(x0, p_values)
>>> sample_trajectory.t
array([0.00000e+00, 4.00008e-03, 8.00016e-03, ..., 1.99992e+02,
       1.99996e+02, 2.00000e+02])
>>> sample_trajectory.x
array([[ 1.00000000e+00,  1.00396022e+00,  1.00784126e+00, ...,
         4.18503698e-87,  4.16832993e-87,  4.15168958e-87],
       [ 1.00000000e+00,  9.80103295e-01,  9.60412752e-01, ...,
        -4.18503698e-87, -4.16832993e-87, -4.15168958e-87]])
>>> sample_trajectory.n_var
plot_trajectory(var='t-x', ax=None, kws=None)[source]

Plot the trajectories in 2D or 3D.

It uses the variables from the Trajectories Class init and plot the numerical variables obtained. The user can to set up all the sizes, colors, vars to plot, etc.

Parameters
  • var (string) – Variables to plot, you can use two (2D plot) o three (3D plot). They must be delimiter by - symbol.

  • ax (matplotlib.pyplot.Axis, (optional)) – Matplotlib axis specification.

  • kws (`dict (optional)) – The parameters to send to set up the plot, like line colors, linewidth, marker face color, etc. Here is a list of available line properties: matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

Returns

A configuration representing the axis data.

Return type

Axes3DSubplot or AxesSubplot

Example

>>> plot = plot_trajectorie("x-y-z", plt.axes(projection ='3d'))
Axes3DSubplot
to_table()[source]

Return a data frame of the trajectory.

Indicates variables states and time.

Returns

out – Pandas data frame with a row for every time point of the interval and a column for time and every variable of the system.

Return type

pandas.DataFrame

Example

>>> v = ["x1", "x2", "x3"]
>>> f = ["x1 * x2 - a", "b*x3 - (x2**2)", "d * x1 - x2"]
>>> p = ["a", "b", "d"]
>>> p_values = [2, -1, 3]
>>> sample_sys = caospy.Symbolic(v, f, p, 'sample')
>>> x0 = [1, 2, 1]
>>> t0 = 0
>>> tf = 2
>>> sample_trajectory = sample_sys.time_evolution(x0, p_values, t0, tf)
>>> sample_trajectory.to_table()
              t        x1        x2        x3
  0     0.00e+00        1.00    2.00    1.00
  1     2.72e-03        1.00    1.99    1.00
  2     6.72e-03        1.00    1.97    1.01
  3     1.07e-02        1.00    1.95    1.01
  4     1.47e-02        1.00    1.93    1.02
...         ...       ...       ...       ...
497     1.99e+00        -0.78   -5.56   0.60
498     1.99e+00        -0.77   -5.69   0.61
499     1.99e+00        -0.76   -5.82   0.63
500     2.00e+00        -0.75   -5.96   0.64
501     2.00e+00        -0.74   -6.01   0.65