def _states(self, V, W): ms = [self._m0] Cs = [self._C0] structure = self._structure structure._W = W # pylint: disable=protected-access kalman = KalmanFilter(structure=structure, V=V) for t in range(1, self._nobs): m, C = kalman.filter(self._data[t], ms[t - 1], Cs[t - 1]) ms.append(m) Cs.append(C) return ms, Cs
def _states(self, V, W): ms = [self._m0] Cs = [self._C0] structure = self._structure structure._W = W kf = KalmanFilter(structure=structure, V=V) for t in range(1, self._nobs): m, C = kf.filter(self._data[t], ms[t - 1], Cs[t - 1]) ms.append(m) Cs.append(C) return ms, Cs
def univariate_ll_bs_elements_test(self): """Test how many states LL BS returns""" # Run Kalman filter ms = [np.array([0, 0])] Cs = [np.identity(2) * 1000] kf = KalmanFilter(structure=FFBSTests._ll["structure"], V=1.4) for t in range(1, FFBSTests._ll["nobs"]): m, C = kf.filter(FFBSTests._ll["obs"][t], ms[t - 1], Cs[t - 1]) ms.append(m) Cs.append(C) states = FFBS.backward_sampling(ms, Cs, np.identity(2)) assert_equals(len(states), FFBSTests._ll["nobs"] - 1)
def univariate_lc_bs_dimension_test(self): """Test states LC BS dimension""" # Run Kalman filter ms = [np.array([0])] Cs = [np.identity(1) * 1000] kf = KalmanFilter(structure=FFBSTests._lc["structure"], V=1.4) for t in range(1, FFBSTests._lc["nobs"]): m, C = kf.filter(FFBSTests._lc["obs"][t], ms[t - 1], Cs[t - 1]) ms.append(m) Cs.append(C) states = FFBS.backward_sampling(ms, Cs, np.identity(1)) assert_equals(states[50].shape, (1, ))
def univariate_lc_filter_dimension_test(self): """Test if the KF output has LC dimensions.""" lc = UnivariateStructure.locally_constant(1.0) m0 = np.array([0]) C0 = np.diag([1e3]) m, C = KalmanFilter(structure=lc, V=2.5).filter(y=0.0, m=m0, C=C0) assert_equals(m.shape, (1, ), "First moment dimensions are wrong") assert_equals(C.shape, (1, 1), "Second moment dimensions are wrong")
def univariate_ll_filter_dimension_test(self): """Test if the KF output has LL dimensions.""" ll = UnivariateStructure.locally_linear( W=np.matrix([[0.1, 0], [0, 0.1]])) print(ll.F.shape) m0 = np.array([0, 0]) C0 = np.diag([1e3, 1e3]) m, C = KalmanFilter(structure=ll, V=2.5).filter(y=0.0, m=m0, C=C0) assert_equals(m.shape, (2, ), "First moment dimensions are wrong") assert_equals(C.shape, (2, 2), "Second moment dimensions are wrong")