dynpy.dynsys - Base module for dynamical systems

Module implementing some base classes useful for implementing dynamical systems

class dynpy.dynsys.DynamicalSystem(discrete_time=True)[source]

Bases: object

Base class for dynamical systems.

Parameters:
discrete_timebool, optional

Whether updating should be done using discrete (default) or continuous time dynamics.

discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

iterate(start_state, max_time)[source]

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)[source]

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

get_trajectory(start_state, max_time, num_points=None, logscale=False)[source]

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

class dynpy.dynsys.DeterministicDynamicalSystem(discrete_time=True)[source]

Bases: DynamicalSystem

discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

class dynpy.dynsys.StochasticDynamicalSystem(discrete_time=True)[source]

Bases: DynamicalSystem

discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

class dynpy.dynsys.DiscreteStateDynamicalSystem(discrete_time=True)[source]

Bases: DynamicalSystem

states()[source]
get_attractor_basins(sort=False, start_state_iter=None)[source]

Computes the attractors and basins of the current discrete-state dynamical system.

Parameters:
sortbool, optional

Whether to sort attractors and basin states (slower).

start_state_iteriterator, optional

Iterator to indicate which start-states to start from. If not specified, tries all states.

Returns:
basin_attslist of lists

A list of the the attractor states for each basin (basin order is from largest basin to smallest).

basin_stateslist of lists

A list of all the states in each basin (basin order is from largest basin to smallest).

print_attractor_basins()[source]

Prints the attractors and basin of the dynamical system

>>> import dynpy
>>> rules = [ ['a',['a','b'],[1,1,1,0]],['b',['a','b'],[1,0,0,0]]]
>>> bn = dynpy.bn.BooleanNetwork(rules=rules)
>>> bn.print_attractor_basins()
* BASIN 1 : 2 States
ATTRACTORS:
      a      b
      1      0
--------------------------------------------------------------------------------
* BASIN 2 : 1 States
ATTRACTORS:
      a      b
      0      0
--------------------------------------------------------------------------------
* BASIN 3 : 1 States
ATTRACTORS:
      a      b
      1      1
--------------------------------------------------------------------------------
discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

class dynpy.dynsys.VectorDynamicalSystem(num_vars, var_names=None, discrete_time=True)[source]

Bases: DynamicalSystem

Mix-in for classes implementing dynamics over multivariate systems.

Parameters:
num_varsint, optional

How many variables (i.e., how many ‘dimensions’ or ‘nodes’ are in the dynamical system). Default is 1

var_nameslist, optional

Names for the variables (optional). Default is simply the numeric indexes of the variables.

discrete_timebool, optional

Whether dynamical system is discrete or continuous time.

num_vars = None

The number of variables in the dynamical system

var_names

The names of the variables in the dynamical system

property var_name_ndxs

A mapping from variables names to their indexes

discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

class dynpy.dynsys.DiscreteStateVectorDynamicalSystem(num_vars, var_names=None, discrete_time=True)[source]

Bases: VectorDynamicalSystem, DiscreteStateDynamicalSystem

get_ndx2state_mx()[source]
get_ndx2state_map()[source]
get_state2ndx_map()[source]
discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_attractor_basins(sort=False, start_state_iter=None)

Computes the attractors and basins of the current discrete-state dynamical system.

Parameters:
sortbool, optional

Whether to sort attractors and basin states (slower).

start_state_iteriterator, optional

Iterator to indicate which start-states to start from. If not specified, tries all states.

Returns:
basin_attslist of lists

A list of the the attractor states for each basin (basin order is from largest basin to smallest).

basin_stateslist of lists

A list of all the states in each basin (basin order is from largest basin to smallest).

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

num_vars = None

The number of variables in the dynamical system

print_attractor_basins()

Prints the attractors and basin of the dynamical system

>>> import dynpy
>>> rules = [ ['a',['a','b'],[1,1,1,0]],['b',['a','b'],[1,0,0,0]]]
>>> bn = dynpy.bn.BooleanNetwork(rules=rules)
>>> bn.print_attractor_basins()
* BASIN 1 : 2 States
ATTRACTORS:
      a      b
      1      0
--------------------------------------------------------------------------------
* BASIN 2 : 1 States
ATTRACTORS:
      a      b
      0      0
--------------------------------------------------------------------------------
* BASIN 3 : 1 States
ATTRACTORS:
      a      b
      1      1
--------------------------------------------------------------------------------
states()
property var_name_ndxs

A mapping from variables names to their indexes

var_names

The names of the variables in the dynamical system

class dynpy.dynsys.ProjectedStateSpace(keep_vars, base_sys, *kargs, **kwargs)[source]

Bases: DiscreteStateVectorDynamicalSystem

states()[source]
discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_attractor_basins(sort=False, start_state_iter=None)

Computes the attractors and basins of the current discrete-state dynamical system.

Parameters:
sortbool, optional

Whether to sort attractors and basin states (slower).

start_state_iteriterator, optional

Iterator to indicate which start-states to start from. If not specified, tries all states.

Returns:
basin_attslist of lists

A list of the the attractor states for each basin (basin order is from largest basin to smallest).

basin_stateslist of lists

A list of all the states in each basin (basin order is from largest basin to smallest).

get_ndx2state_map()
get_ndx2state_mx()
get_state2ndx_map()
get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

num_vars = None

The number of variables in the dynamical system

print_attractor_basins()

Prints the attractors and basin of the dynamical system

>>> import dynpy
>>> rules = [ ['a',['a','b'],[1,1,1,0]],['b',['a','b'],[1,0,0,0]]]
>>> bn = dynpy.bn.BooleanNetwork(rules=rules)
>>> bn.print_attractor_basins()
* BASIN 1 : 2 States
ATTRACTORS:
      a      b
      1      0
--------------------------------------------------------------------------------
* BASIN 2 : 1 States
ATTRACTORS:
      a      b
      0      0
--------------------------------------------------------------------------------
* BASIN 3 : 1 States
ATTRACTORS:
      a      b
      1      1
--------------------------------------------------------------------------------
property var_name_ndxs

A mapping from variables names to their indexes

var_names

The names of the variables in the dynamical system

class dynpy.dynsys.LinearDynamicalSystem(transition_matrix, discrete_time=True)[source]

Bases: VectorDynamicalSystem

This class implements linear dynamical systems, whether continuous or discrete-time. It is also used by dynpy.dynsys.MarkovChain to implement Markov Chain (discrete-case) or master equation (continuous-case) dynamics.

For attribute definitions, see documentation of dynpy.dynsys.DynamicalSystem.

Parameters:
transition_matrixnumpy array or scipy.sparse matrix

Matrix defining the evolution of the dynamical system, i.e. the \(\mathbf{A}\) in \(\mathbf{x_{t+1}} = \mathbf{x_{t}}\mathbf{A}\) (in the discrete-time case) or \(\dot{\mathbf{x}} = \mathbf{x}\mathbf{A}\) (in the continuous-time case)

discrete_timebool, optional

Whether updating should be done using discrete (default) or continuous time dynamics.

discrete_time = True

Whether the dynamical system obeys discrete- or continuous-time dynamics

get_trajectory(start_state, max_time, num_points=None, logscale=False)

This method get a trajectory of a dynamical system starting from a particular starting state.

Parameters:
start_stateobject

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

num_pointsint, optional

How many timepoints to sample the trajectory at. This determines how big each ‘step size’ is. By default, equal to int(max_time)

logscalebool, optional

Whether to sample the timepoints on a logscale or not (default)

Returns:
trajectory: numpy array

Array of states corresponding to trajectory

iterate(start_state, max_time)

This method runs the dynamical system for max_time starting from start_state and returns the result. In fact, this method is set at run-time by the constructor to either _iterateDiscrete or _iterateContinuous depending on whether the dynamical system object is initialized with discrete_time=True or discrete_time=False. Thus, sub-classes should override _iterateDiscrete and _iterateContinuous instead of this method. See also dynpy.dynsys.DynamicalSystem.iterateOneStep()

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

max_timefloat

Until which point to run the dynamical system (number of iterations for discrete-time systems or time limit for continuous-time systems)

Returns:
numpy array or scipy.sparse matrix

End state

iterate_1step(start_state)

This method runs a discrete-time dynamical system for 1 timestep. At run-time, the construct either repoints this method to _iterateOneStep for discrete-time systems, or removes it for continuous time systems.

Parameters:
start_statenumpy array or scipy.sparse matrix

Which state to start from

Returns:
numpy array or scipy.sparse matrix

Iterated state

num_vars = None

The number of variables in the dynamical system

property var_name_ndxs

A mapping from variables names to their indexes

var_names

The names of the variables in the dynamical system

transition_matrix = None

Transition matrix for linear system.

get_equilibrium_distribution()[source]

Get equilibrium state of dynamical system using eigen-decomposition

Returns:
numpy array or scipy.sparse matrix

Equilibrium state