def benes_daum(): """Benes-Daum testcase, example 10.17 in Applied SDEs.""" def f(t, x): return np.tanh(x) def df(t, x): return 1.0 - np.tanh(x)**2 def l(t): return np.ones(1) initmean = np.zeros(1) initcov = 3.0 * np.eye(1) initrv = Normal(initmean, initcov) dynamod = pnss.SDE(dimension=1, driftfun=f, dispmatfun=l, jacobfun=df) measmod = pnss.DiscreteLTIGaussian(np.eye(1), np.zeros(1), np.eye(1)) return dynamod, measmod, initrv, {}
def _setup(self, test_ndim, spdmat1): self.g = lambda t, x: np.sin(x) self.L = lambda t: spdmat1 self.dg = lambda t, x: np.cos(x) self.transition = pnss.SDE(test_ndim, self.g, self.L, self.dg)
def benes_daum( measurement_variance: FloatArgType = 0.1, process_diffusion: FloatArgType = 1.0, time_grid: Optional[np.ndarray] = None, initrv: Optional[randvars.RandomVariable] = None, ): r"""Filtering/smoothing setup based on the Beneš SDE. A non-linear state space model for the dynamics of a Beneš SDE. Here, we formulate a continuous-discrete state space model: .. math:: d x(t) &= \tanh(x(t)) d t + L d w(t) \\ y_n &= x(t_n) + r_n for a driving Wiener process :math:`w(t)` and Gaussian distributed measurement noise :math:`r_n \sim \mathcal{N}(0, R)` with measurement noise covariance matrix :math:`R`. Parameters ---------- measurement_variance Marginal measurement variance. process_diffusion Diffusion constant for the dynamics time_grid Time grid for the filtering/smoothing problem. initrv Initial random variable. Returns ------- regression_problem ``RegressionProblem`` object with time points and noisy observations. statespace_components Dictionary containing * dynamics model * measurement model * initial random variable Notes ----- In order to generate observations for the returned ``RegressionProblem`` object, the non-linear Beneš SDE has to be linearized. Here, a ``ContinuousEKFComponent`` is used, which corresponds to a first-order linearization as used in the extended Kalman filter. """ def f(t, x): return np.tanh(x) def df(t, x): return 1.0 - np.tanh(x) ** 2 def l(t): return process_diffusion * np.ones(1) if initrv is None: initrv = randvars.Normal(np.zeros(1), 3.0 * np.eye(1)) dynamics_model = statespace.SDE(dimension=1, driftfun=f, dispmatfun=l, jacobfun=df) measurement_model = statespace.DiscreteLTIGaussian( state_trans_mat=np.eye(1), shift_vec=np.zeros(1), proc_noise_cov_mat=measurement_variance * np.eye(1), ) # Generate data if time_grid is None: time_grid = np.arange(0.0, 4.0, step=0.2) # The non-linear dynamics are linearized according to an EKF in order # to generate samples. linearized_dynamics_model = filtsmooth.ContinuousEKFComponent( non_linear_model=dynamics_model ) states, obs = statespace.generate_samples( dynmod=linearized_dynamics_model, measmod=measurement_model, initrv=initrv, times=time_grid, ) regression_problem = problems.RegressionProblem( observations=obs, locations=time_grid, solution=states ) statespace_components = dict( dynamics_model=dynamics_model, measurement_model=measurement_model, initrv=initrv, ) return regression_problem, statespace_components
def test_notimplementederror(self): sde = pnss.SDE(1, None, None, None) # content is irrelevant. with self.assertRaises(NotImplementedError): pnfs.ContinuousUKFComponent(sde)