def test_solve(self): y0 = np.array([0.3]) ivp = logistic(t0=0, tmax=4, y0=y0) odesol = self.solver.solve(ivp=ivp, ) # this is the actual part of the test # quick check that the result is sensible self.assertAlmostEqual(odesol.locations[-1], ivp.tmax) self.assertAlmostEqual(odesol.states[-1].mean[0], 1.0, places=2)
def case_logistic(perturbfun, steprule): y0 = np.array([0.1]) ode = diffeq_zoo.logistic(t0=0.0, tmax=1.0, y0=y0) return setup_solver(y0, ode, perturbfun, steprule=steprule)
def problem_logistic(): return diffeq_zoo.logistic()
def ivp(): y0 = np.array([0.1]) return diffeq_zoo.logistic(t0=0.0, tmax=1.5, y0=y0)
import numpy as np import pytest import probnum.problems as pnpr import probnum.problems.zoo.diffeq as diffeqzoo ODE_LIST = [ diffeqzoo.vanderpol(), diffeqzoo.threebody(), diffeqzoo.rigidbody(), diffeqzoo.lotkavolterra(), diffeqzoo.logistic(), diffeqzoo.seir(), diffeqzoo.fitzhughnagumo(), diffeqzoo.lorenz63(), diffeqzoo.lorenz96(), ] all_odes = pytest.mark.parametrize("ivp", ODE_LIST) @all_odes def test_isinstance(ivp): assert isinstance(ivp, pnpr.InitialValueProblem) @all_odes def test_eval(ivp): f0 = ivp.f(ivp.t0, ivp.y0) assert isinstance(f0, np.ndarray) if ivp.df is not None:
def logistic_ode( y0: Optional[Union[np.ndarray, FloatLike]] = None, timespan: Tuple[FloatLike, FloatLike] = (0.0, 2.0), step: FloatLike = 0.1, params: Tuple[FloatLike, FloatLike] = (6.0, 1.0), initrv: Optional[randvars.RandomVariable] = None, evlvar: Optional[Union[np.ndarray, FloatLike]] = None, ek0_or_ek1: IntLike = 1, exclude_initial_condition: bool = True, order: IntLike = 3, forward_implementation: str = "classic", backward_implementation: str = "classic", ): r"""Filtering/smoothing setup for a probabilistic ODE solver for the logistic ODE. This state space model assumes an integrated Brownian motion prior on the dynamics and constructs the ODE likelihood based on the vector field defining the logistic ODE. Parameters ---------- y0 Initial conditions of the Initial Value Problem timespan Time span of the problem params Parameters for the logistic ODE initrv Initial random variable of the probabilistic ODE solver evlvar See :py:class:`probnum.diffeq.ODEFilter` ek0_or_ek1 See :py:class:`probnum.diffeq.ODEFilter` exclude_initial_condition Whether the resulting regression problem should exclude (i.e. not contain) the initial condition of the ODE. Optional. Default is True, which means that the initial condition is omitted. order Order of integration for the Integrated Brownian Motion prior of the solver. forward_implementation Implementation of the forward transitions inside prior and measurement model. Optional. Default is `classic`. For improved numerical stability, use `sqrt`. backward_implementation Implementation of the backward transitions inside prior and measurement model. Optional. Default is `classic`. For improved numerical stability, use `sqrt`. Returns ------- regression_problem ``TimeSeriesRegressionProblem`` object with time points and zero-observations. info Dictionary containing additional information like the prior process. See Also -------- :py:class:`probnum.diffeq.ODEFilter` """ if y0 is None: y0 = np.array([0.1]) y0 = np.atleast_1d(y0) if evlvar is None: evlvar = np.zeros((1, 1)) t0, tmax = timespan # Generate ODE regression problem logistic_ivp = diffeq_zoo.logistic(t0=t0, tmax=tmax, y0=y0, params=params) time_grid = np.arange(*timespan, step=step) ode_residual = diffeq.odefilter.information_operators.ODEResidual( num_prior_derivatives=order, ode_dimension=logistic_ivp.dimension) if ek0_or_ek1 == 0: ek = diffeq.odefilter.approx_strategies.EK0() else: ek = diffeq.odefilter.approx_strategies.EK1() regression_problem = diffeq.odefilter.utils.ivp_to_regression_problem( ivp=logistic_ivp, locations=time_grid, ode_information_operator=ode_residual, approx_strategy=ek, ode_measurement_variance=evlvar, exclude_initial_condition=exclude_initial_condition, ) # Generate prior process if initrv is None: initmean = np.array([0.1, 0, 0.0, 0.0]) initcov = np.diag([0.0, 1.0, 1.0, 1.0]) initrv = randvars.Normal(initmean, initcov) dynamics_model = randprocs.markov.integrator.IntegratedWienerTransition( num_derivatives=order, wiener_process_dimension=1, forward_implementation=forward_implementation, backward_implementation=backward_implementation, ) prior_process = randprocs.markov.MarkovProcess(transition=dynamics_model, initrv=initrv, initarg=time_grid[0]) # Return problems and info info = dict( ivp=logistic_ivp, prior_process=prior_process, ) return regression_problem, info
def doprisolver(): y0 = np.array([0.1]) ode = diffeq_zoo.logistic(t0=0.0, tmax=1.0, y0=y0) return rk.DOP853(ode.f, ode.t0, y0, ode.tmax)