Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    def setUp(self):
        """
        Set up Lotka-Volterra ODE (i.e. two-dim, four parameter) and
        multiple (two) evalpts.
        """
        # Set Model Parameters
        odeparam = np.array([0, 1, 1, 2])
        y0, y0_unc = np.ones(2), 0 * np.ones(2)
        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=len(y0))
        solver = linsolve.LinearisedODESolver(ibm)
        ivp = linode.LotkaVolterra(t0, tmax, odeparam, y0, y0_unc)
        tsteps, means, __, rhs_parts, uncerts = solver.solve(ivp, stepsize=h)
        self.mean = odesolver.get_trajectory_multidim(means, [0, 1], 0)

        # Set up BM and IBM covariance matrices
        evalpt = np.array(tsteps[[-1, -10]])
        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
        postmean = const + np.dot(jacob, odeparam)
        self.postmean = postmean.reshape((2, 2))