|
4 | 4 | # pylint: skip-file |
5 | 5 |
|
6 | 6 | import numpy as np |
7 | | -from pynumdiff.utils import utility, simulate, evaluate |
| 7 | +from pynumdiff.utils import utility, evaluate |
| 8 | +from pynumdiff.utils.simulate import sine, triangle, pop_dyn, linear_autonomous, pi_cruise_control, lorenz_x |
8 | 9 | np.random.seed(42) # The answer to life, the universe, and everything |
9 | 10 |
|
10 | 11 |
|
@@ -88,8 +89,26 @@ def identity(x, dt): return x, 0 # should come back the same |
88 | 89 | assert np.allclose(x, x_hat) |
89 | 90 |
|
90 | 91 |
|
91 | | -# def test_simulate(): |
92 | | -# return |
| 92 | +def test_simulations(request): |
| 93 | + if request.config.getoption("--plot"): |
| 94 | + from matplotlib import pyplot |
| 95 | + fig, axes = pyplot.subplots(2, 3, figsize=(18,7), constrained_layout=True) |
| 96 | + |
| 97 | + for i,(sim,title) in enumerate(zip( |
| 98 | + [pi_cruise_control, sine, triangle, pop_dyn, linear_autonomous, lorenz_x], |
| 99 | + ["Cruise Control", "Sum of Sines", "Triangles", "Logistic Growth", "Linear Autonomous", "Lorenz First Dimension"])): |
| 100 | + |
| 101 | + y, x, dxdt = sim(duration=4, dt=0.01, noise_type='normal', noise_parameters=[0,0.1]) |
| 102 | + assert len(y) == len(x) == len(dxdt) |
| 103 | + |
| 104 | + if request.config.getoption("--plot"): |
| 105 | + t = np.arange(len(y))*0.01 |
| 106 | + ax = axes[i//3, i%3] |
| 107 | + ax.plot(t, x, 'k--', linewidth=3, label=r"true $x$") |
| 108 | + ax.plot(t, y, '.', color='blue', zorder=-100, markersize=5, label="noisy data") |
| 109 | + if i//3 == 0: ax.set_xticklabels([]) |
| 110 | + ax.set_title(title, fontsize=18) |
| 111 | + if i == 5: ax.legend(loc='lower right', fontsize=12) |
93 | 112 |
|
94 | 113 | # def test_evaluate(): |
95 | 114 | # return |
0 commit comments