예제 #1
0
    def test_two_dimensional_series(self):
        """ Is it possible to run 2D series? """
        int1_reg = InterceptRegressor()
        int2_reg = InterceptRegressor()
        lb = Lava(nominal_model=int2_reg, latent_model=int1_reg)

        ret = lb.step([1, 1], [2, 2])
        self.assertTrue(ret)
예제 #2
0
    def test_get_regressor(self):
        li = InterceptRegressor()
        y_history = np.array([[1, 1], [3, 4]])
        u_history = np.array([[1, 1], [3, 4]])

        one = li.update_regressor(y_history, u_history)
        self.assertEqual(np.array([1]), one)

        one = li.update_regressor(y_history, u_history, nominal_regressor=None)
        self.assertEqual(np.array([1]), one)
예제 #3
0
    def test_step_stacking(self):
        lb = Lava(InterceptRegressor(), InterceptRegressor())
        y = np.array([1, 4, 6]).T
        u = np.array([5, 4]).T
        lb.step(y, u)
        lb.step(y, u)

        self.assertEqual((2, 2), lb.u_history.shape,
                         f"the u history has shape {lb.u_history.shape}")
        self.assertEqual((3, 2), lb.y_history.shape,
                         f"the y history has shape {lb.y_history.shape}")
예제 #4
0
    def test_simulate(self):
        """Make sure that the simulation loop works with the simplest of regressor models"""

        from lava import RegressorModel
        from numpy.testing import assert_array_almost_equal

        # noinspection PyAbstractClass
        i1 = InterceptRegressor()
        i2 = InterceptRegressor()

        lb = Lava(i1, i2)

        # inject trained parameters
        lb.Theta = np.array([[2], [0]])
        lb.Z = np.array([[1], [1]])

        y_true = np.array([[3, 3, 3], [1, 1, 1]])
        y_hat, *_ = lb.simulate(np.array([1, 2, 3]))
        assert_array_almost_equal(y_true, y_hat)
예제 #5
0
    def test_step_regularized_ARX(self):
        """Can we step with some actual regressor models?"""
        arx_regressor = ARXRegressor(y_lag_max=2, u_lag_max=1)
        intercept_regressor = InterceptRegressor()
        lb = Lava(nominal_model=intercept_regressor,
                  latent_model=arx_regressor)

        ret = lb.step(np.array([3, 3]), np.array([3, 3]))
        self.assertFalse(ret)

        lb.step(np.array([1, 1]), np.array([2, 2]))
        ret = lb.step(np.array([1, 1]), np.array([2, 2]))
        self.assertTrue(ret)
예제 #6
0
 def test_get_regressor_stepwise(self):
     li = InterceptRegressor()
     one = li.update_regressor(None, None, None)
     self.assertEqual(np.array([1]), one)
예제 #7
0
 def test_init(self):
     lb = Lava(InterceptRegressor(), InterceptRegressor())
     self.assertEqual(1, 1)