def setUp(self): """ Set up linear ODE (i.e. one-dim, one parameter) and one evalpt. """ # Set Model Parameters odeparam = 1. y0, y0_unc = 1.0, 0 t0, tmax = 0.0, 1.25 # Set Method Parameters q = 1 h = 0.1 # Set up and solve ODE ibm = statespace.IBM(q=q, dim=1) solver = linsolve.LinearisedODESolver(ibm) ivp = linode.LinearODE(t0, tmax, odeparam, y0, y0_unc) tsteps, means, __, rhs_parts, uncerts = solver.solve(ivp, stepsize=h) self.mean = odesolver.get_trajectory(means, 0, 0) # Set up BM and IBM covariance matrices evalpt = np.array([tsteps[-1]]) derdat = (tsteps, rhs_parts, 0.) const, jacob = linearisation.compute_linearisation( ssm=ibm, initial_value=y0, derivative_data=derdat, prdct_tsteps=evalpt) # Compute GP Estimation of filter mean at t=tmax self.postmean = const + np.dot(jacob[:, 0], odeparam)
def test_uncert_not_scalar(self): """ We test whether the uncertainty (third element of derivative_data) is only accepted as a scalar. """ # Set Model Parameters odeparam = 1. y0, y0_unc = 1.0, 0 t0, tmax = 0.0, 1.25 # Set Method Parameters q = 1 h = 0.1 # Set up and solve ODE ibm = statespace.IBM(q=q, dim=1) solver = linsolve.LinearisedODESolver(ibm) ivp = linode.LinearODE(t0, tmax, odeparam, y0, y0_unc) tsteps, means, __, rhs_parts, should_not_work = solver.solve(ivp, stepsize=h) self.mean = odesolver.get_trajectory(means, 0, 0) # Set up BM and IBM covariance matrices evalpt = np.array(tsteps[[-1]]) with self.assertRaises(TypeError): derdat = (tsteps, rhs_parts, should_not_work) linearisation.compute_linearisation(ssm=ibm, initial_value=y0, derivative_data=derdat, prdct_tsteps=evalpt)
def setUp(self): """ Test passes if scalar LinearODE can be successfully initialised. """ self.lin_ode = linode.LinearODE(t0=0., tmax=1., params=3., initval=0.1, initval_unc=2.1)
def setUp(self): """ Set up linear ode and solve with stepsize h = 0.1. """ prior = stsp.IBM(q=1, dim=1) self.solver = linsolver.LinearisedODESolver(prior, filtertype="kalman") self.ode = linode.LinearODE(t0=0.0, tmax=1.2, params=2.0, initval=4.1) self.h = 0.1 output = self.solver.solve(self.ode, self.h) self.tsteps, self.means, self.stdevs, __, __ = output
def setUp(self): """ Set up linear ODE and linearised ODESolver. """ prior = stsp.IBM(q=1, dim=1) solver = linsolver.LinearisedODESolver(prior, filtertype="kalman") ode = linode.LinearODE(t0=0.0, tmax=1.2, params=2.0, initval=4.1) h = 0.1 output = solver.solve(ode, h) __, __, __, self.rhs_parts, self.uncert = output
def test_multidim_init_fails_initval(self): """ Test passes if multidimensional initial value is rejected """ initval = np.ones(2) with self.assertRaises(TypeError): linode.LinearODE(t0=0., tmax=1., params=1.0, initval=initval, initval_unc=2.1)
def test_multidim_init_fails_params(self): """ Test passes if matrix-valued parameter is rejected. """ params = np.eye(2) with self.assertRaises(TypeError): linode.LinearODE(t0=0., tmax=1., params=params, initval=0.1, initval_unc=2.1)
def test_inconsistent_prior_and_ssm(self): """ Prior uses dim=2, so a scalar ODE should raise an AssertionError. """ solver = linsolver.LinearisedODESolver(self.working_2d_prior, self.working_filtertype) wrong_dimensional_ode = linode.LinearODE(t0=0., tmax=1., params=1.123, initval=1.) with self.assertRaises(AssertionError): solver.solve(wrong_dimensional_ode, stepsize=0.1)
ivpnoise = 0.01 thetatrue = 0.25 # Set Method Parameters q = 1 h = 0.2 nsamps = 25 init_theta = 0.99 * np.ones(1) ibm = statespace.IBM(q=q, dim=1) solver = linsolver.LinearisedODESolver(ibm) pwidth = 0.004 # Create Data and Jacobian ivp = linode.LinearODE(initial_time, end_time, params=thetatrue, initval=initial_value, initval_unc=0.0) evalpt, data = create_data(solver, ivp, thetatrue, 1e-04, ivpnoise) tsteps, __, __, __, __ = solver.solve(ivp, stepsize=h) evalpt = np.array(tsteps[[-1]]) kernel_prefactor = linearisation.compute_kernel_prefactor( ibm, 0.0, tsteps, evalpt) # Sample states from Markov chain ivp.params = init_theta lklhd_grad = InvProblemLklhd(evalpt, data, solver, ivp, h,