def setUp(self):
     ivp = ode.Res2Bod(t0=0., tmax=0.011)
     ibm_prior = stsp.IBM(q=2, dim=4)
     solver = oso.ODESolver(ibm_prior)
     self.t, mean, stdev = solver.solve(ivp, stepsize=0.0001)
     self.m1 = oso.get_trajectory(mean, 0, 0)
     self.m2 = oso.get_trajectory(mean, 1, 0)
 def check_nonexistant_filterkey(self):
     """
     Entering any filterkey other than 'kalman', 'particle'
     or 'custom' raises AssertionError.
     """
     with self.assertRaises(NameError):
         oso.ODESolver(self.working_2d_prior, filtertype="rubbish")
 def setUp(self):
     """Setup odesolver and solve a scalar ode"""
     prior = stsp.IBM(q=1, dim=1)
     self.solver = oso.ODESolver(prior, filtertype="kalman")
     self.ode = ode.LinearODE(t0=0.0, tmax=1.2, params=2.0, initval=4.1)
     self.h = 0.1
     self.tsteps, self.means, self.stdevs = self.solver.solve(
         self.ode, stepsize=self.h)
 def setUp(self):
     pars = [0., 0.2, 0.2, 3.0]
     y0 = np.array([-1, 1])
     ivp = ode.FitzHughNagumo(t0=0., tmax=5., params=pars, initval=y0)
     ibm_prior = stsp.IBM(q=1, dim=2)
     solver = oso.ODESolver(ibm_prior)
     self.t, mean, stdev = solver.solve(ivp, stepsize=0.05)
     self.m1 = oso.get_trajectory(mean, 0, 0)
     self.m2 = oso.get_trajectory(mean, 1, 0)
 def test_inconsistent_prior_and_ssm(self):
     """
     Prior uses dim=2, so a scalar ODE should raise an AssertionError.
     """
     solver = oso.ODESolver(self.working_2d_prior, self.working_filtertype)
     wrong_dimensional_ode = ode.LinearODE(t0=0., tmax=1.,
                                           params=1.123, initval=1.)
     with self.assertRaises(AssertionError):
         solver.solve(wrong_dimensional_ode, stepsize=0.1)
 def test_solution_controlvar(self):
     """
     Controlvariate to the test_solution() test. For q < 2 or
     stepsize > 0.0001 the precision should not be achieved anymore. 
     """
     ivp = ode.Res2Bod(t0=0., tmax=0.011)
     ibm_prior = stsp.IBM(q=1, dim=4)
     solver = oso.ODESolver(ibm_prior)
     self.t, mean, stdev = solver.solve(ivp, stepsize=0.0001)
     self.m1 = oso.get_trajectory(mean, 0, 0)
     self.m2 = oso.get_trajectory(mean, 1, 0)
     x_benchmark = 0.986122388809302
     y_benchmark = -0.014199005665214861
     thresh = 1e-10
     self.assertEqual(traj_passes_pt(self.m1, x_benchmark, thresh), False)
     self.assertEqual(traj_passes_pt(self.m2, y_benchmark, thresh), False)
Exemplo n.º 7
0
Checks whether odesolver works up to high accuracy
via solving the restricted two-body problem.
This might take 20-30 seconds.
If the resulting orbit is periodic, the solution is correct.
"""

import numpy as np
import matplotlib.pyplot as plt

from difflikelihoods import ode
from difflikelihoods import odesolver
from difflikelihoods import statespace

# Solve ODE
stsp = statespace.IBM(q=2, dim=4)
solver = odesolver.ODESolver(ssm=stsp, filtertype="kalman")
r2b = ode.Res2Bod(t0=0, tmax=32)
t, m, s = solver.solve(r2b, stepsize=0.0001)

# Extract relevant trajectories
mtraj1 = odesolver.get_trajectory(m, 0, 0)
mtraj2 = odesolver.get_trajectory(m, 1, 0)

# Plot solution
plt.title("Restricted Two-Body Problem")
plt.plot(mtraj1, mtraj2, label="Trajectory")
plt.plot(mtraj1[0], mtraj2[0], "o", label="Starting point at t=t0")
plt.plot(mtraj1[-1], mtraj2[-1], "o", label="Endpoint at t=tmax")
plt.legend()
plt.show()
 def check_custom_filter_not_implemented(self):
     """Custom filter should be an option, yet raise an error."""
     with self.assertRaises(NotImplementedError):
         oso.ODESolver(self.working_2d_prior, filtertype="custom")
 def check_particle_filter_not_implemented(self):
     """Particle filter should be an option, yet raise an error."""
     with self.assertRaises(NotImplementedError):
         oso.ODESolver(self.working_2d_prior, filtertype="particle")