Skip to content

Commit

Permalink
identity intervention tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djpasseyjr committed Apr 11, 2024
1 parent db699b7 commit 75acbf5
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,35 @@ def test_signal_intervention():

g = interfere.SignalIntervention([1, 2], [np.sin, lambda t: t ** 2])
assert np.allclose(g(x, 0.0), np.array([1.1, 0.0, 0.0]))
assert np.allclose(g(x, np.pi/2), np.array([1.1, 1.0, (np.pi/2)**2]))
assert np.allclose(g(x, np.pi/2), np.array([1.1, 1.0, (np.pi/2)**2]))


def test_identity_intervention():

# Test identity intervention for discrete stochastic dynamics.
model = interfere.dynamics.coupled_map_1dlattice_chaotic_brownian(sigma=0.1)
x0 = np.random.rand(10)
t = np.arange(100)
rng = np.random.default_rng(11)

X = model.simulate(x0, t, rng=rng)

rng = np.random.default_rng(11)
X_ident = model.simulate(
x0, t, interfere.interventions.IdentityIntervention(), rng)

assert np.all(X == X_ident)

# Test identity intervention for continuous stochastic dynamics.
model = interfere.dynamics.Belozyorov3DQuad(sigma=0.01)
x0 = np.random.rand(3) * 0.1
t = np.linspace(0, 10, 1000)

rng = np.random.default_rng(11)
X = model.simulate(x0, t, rng=rng)

rng = np.random.default_rng(11)
X_ident = model.simulate(
x0, t, interfere.interventions.IdentityIntervention(), rng)

assert np.all(X == X_ident)

0 comments on commit 75acbf5

Please sign in to comment.