Simple causal models

Simple causal models#

Here, we showcase how to generate data for the simple case, in which we solve single separate dynamical systems such as the Lorenz system. The ODE systems are integrated using the dysts package.

Let’s start by solving a single Lorenz system for 1000 time-steps.

from causaldynamics.systems import solve_system

data = solve_system(num_timesteps=1000, num_systems=1, system_name='Lorenz')
data.shape # [num_timesteps, num_systems, node_dim]
torch.Size([1000, 1, 3])

Let’s visualize the result using the xarray package.

import xarray as xr
import matplotlib.pyplot as plt

from causaldynamics.plot import plot_3d_trajectories

da = xr.DataArray(data, dims=['time', 'node', 'dim'])
plot_3d_trajectories(da)
plt.show()
../_images/c3d17d56b5ef432a28919da4cd798152a054854e0de4a0f00a053254e8c2ab21.png

We can also solve a randomly selected dynamical system.

from causaldynamics.systems import solve_random_systems

data = solve_random_systems(num_timesteps=1000, num_systems=1)
da = xr.DataArray(data, dims=['time', 'node', 'dim'])
plot_3d_trajectories(da)
plt.show()
../_images/1f4e7e2df979e8049c07550e6e02c31b4c9335fc4f831f378ef726aec66c24b2.png

We can also provide kwargs to the underlying dysts.make_trajectory function, e.g. add noise.

from causaldynamics.systems import solve_random_systems

data = solve_random_systems(num_timesteps=1000, num_systems=1, make_trajectory_kwargs={'noise': 0.5})
da = xr.DataArray(data, dims=['time', 'node', 'dim'])
plot_3d_trajectories(da)
plt.show()
../_images/885d4029e8af8d97366bf339c9cce6e55c3cb6f4ebf6461cde9a9cbd8d5de75c.png

Also, by increasing num_systems we can compute multiple uncoupled dynamical system trajectories in parallel using the same command.

from causaldynamics.systems import solve_random_systems

data = solve_random_systems(num_timesteps=1000, num_systems=5)
da = xr.DataArray(data, dims=['time', 'node', 'dim'])
plot_3d_trajectories(da)
plt.show()
../_images/32ce9b6a1f020493a86d9fe486cf89d8ef741e1819b666c4fdffd1c33566aad3.png