mcs#

Classes

DE(max_step, dim)

Difference equations simulation.

ODE(max_step, dim, dt)

ODEs simulation.

CA(max_step, size_x[, size_y, seed])

Cellular automata simulation.

PDE(max_step, dim, dt, dh, size)

PDEs simulation.

Net(max_step)

Dynamical networks simulation.

class mcs.DE(max_step: int, dim: int)[source]#

Difference equations simulation.

max_step#

The max step.

dim#

The number of variables.

x#

An ndarray representing the states of shape (max_step, dim).

step#

The current step.

initialize(*, x0: List[float] | None = None)[source]#

Sets up the initial values for the state variables.

Parameters:

x0 – A list of initial states.

update(*, f: Callable | None = None)[source]#

Updates the states in the next step.

Parameters:

f – A function, \(x_t = f(x_{t-1})\).

visualize(*, step: int = -1, indices: List[int] | None = None)[source]#

Visualizes the series of states of the system.

Parameters:
  • step – The step to plot.

  • indices – A list of indices of the states to plot. If None, plot all states.

Returns:

A matplotlib.figure.Figure object.

simulate(stop_step: int | None = None, **kwargs)#

Simulates the system till stop_step.

Parameters:
class mcs.ODE(max_step: int, dim: int, dt: float)[source]#

ODEs simulation.

max_step#

The max step.

dim#

The number of variables.

dt#

The time step.

x#

An ndarray representing the states of shape (max_step, dim).

t#

An ndarray of length max_step representing time.

step#

The current step.

initialize(*, x0: List[float] | None = None)[source]#

Sets up the initial values for the state variables.

Parameters:

x0 – A list of initial states.

update(*, f: Callable | None = None)[source]#

Updates the states in the next step.

Parameters:

f – A function, \(dx/dt = f(x)\).

static lv(a, b, c, d)[source]#

Returns Lotka-Volterra equations.

visualize(*, step: int = -1, indices: List[int] | None = None)[source]#

Visualizes the time series of the system.

Parameters:
  • step – The step to plot.

  • indices – A list of indices of the states to plot. If None, plot all states.

Returns:

A matplotlib.figure.Figure object.

simulate(stop_step: int | None = None, **kwargs)#

Simulates the system till stop_step.

Parameters:
class mcs.CA(max_step: int, size_x: int, size_y: int = 1, seed: int = 42)[source]#

Cellular automata simulation.

Override this class to customize configuration and state-transition function.

max_step#

The max step.

size_x#

Number of cells in x dimension.

size_y#

Number of cells in y dimension.

seed#

NumPy random seed.

s#

An ndarray of shape (max_step, size_x) or (max_step, size_y, size_x) representing the states.

step#

The current step.

initialize()[source]#

Sets up the initial configuration.

update(*, F: Callable | None = None)[source]#

Updates the states in the next step.

Parameters:

F – A state transition function which returns an ndarray.

simulate(stop_step: int | None = None, **kwargs)#

Simulates the system till stop_step.

Parameters:
visualize(*, step: int = -1)[source]#

Visualizes the states of the system using an image of shape (step, size_x) or (size_y, size_x).

Parameters:

step – The step to plot.

Returns:

A matplotlib.figure.Figure object.

class mcs.PDE(max_step: int, dim: int, dt: float, dh: float, size: int)[source]#

PDEs simulation.

Override this class to customize.

max_step#

The max step.

dim#

The number of variables.

dt#

The time step.

dh#

Spatial resolution.

size#

Size of grid.

f#

An ndarray of shape (max_step, size, size, dim) representing the states.

step#

The current step.

initialize()[source]#

Sets up the initial conditions.

update(*, F: Callable | None = None)[source]#

Updates the states in the next step.

Parameters:

F – A state transition function corresponding to \(\partial f/\partial t = F(f,...,x,y,t)\).

static turing(a, b, c, d, h, k, Du, Dv, dh)[source]#

Reaction-diffusion equations:

\[ \begin{align}\begin{aligned}\partial u/\partial t = a(u-h) + b(v-k) + D_u \Delta u\\\partial v/\partial t = c(u-h) + d(v-k) + D_v \Delta v.\end{aligned}\end{align} \]
visualize(*, step: int = -1, indices: List[int] | None = None)[source]#

Visualizes the states of the system using heatmap.

Parameters:
  • step – The step to plot.

  • indices – A list of indices of the states to plot. If None, plot all states.

Returns:

A list of matplotlib.figure.Figure objects.

simulate(stop_step: int | None = None, **kwargs)#

Simulates the system till stop_step.

Parameters:
class mcs.Net(max_step: int)[source]#

Dynamical networks simulation.

Override this class to customize.

max_step#

The max step.

graphs#

A list of networkx.Graph objects.

step#

The current step.

initialize()[source]#

Sets up the initial network.

update(**kwargs)[source]#

Updates the states in the next step.

coupled_oscillators(a, b, dt)[source]#

Linearly coupled dynamical nodes:

\[d\theta_i/dt = b\theta_i + a\sum_{j\in N_i}(\theta_j-\theta_i).\]
visualize(*, step: int = -1)[source]#

Visualizes the states of the network.

Parameters:

step – The step to plot.

Returns:

A matplotlib.figure.Figure object.

simulate(stop_step: int | None = None, **kwargs)#

Simulates the system till stop_step.

Parameters: