class BasicModelLearningTestCase(unittest.TestCase):
    def setUp(self):

        # Basic parameters
        self.K = 100
        self.ds = 3
        self.do = 3

        # System matrices
        params = dict()
        params['F'] = np.array([[0.9, 0.8, 0.7], [0, 0.9, 0.8], [0, 0, 0.7]])
        params['Q'] = np.array([[0.1, 0.05, 0], [0.05, 0.1, 0.05],
                                [0, 0.05, 0.1]])
        params['H'] = np.identity(self.do)
        params['R'] = 0.1 * np.identity(self.do)
        self.params = params

        # Create model
        prior = GaussianDensity(np.zeros(self.ds), np.identity(self.ds))
        self.model = BasicLinearModel(self.ds, self.do, prior, self.params)

        # Simulate data
        np.random.seed(1)
        self.state, self.observ = self.model.simulate_data(self.K)

        # Create initial estimated model
        est_params = dict()
        est_params['F'] = 0.5 * np.identity(self.ds)
        est_params['Q'] = np.identity(self.ds)
        est_params['H'] = np.identity(self.do)
        est_params['R'] = np.identity(self.do)
        est_model = BasicLinearModel(self.ds, self.do, prior, est_params)
        self.est_model = est_model

        # Set MCMC parameters
        self.num_iter = 200
        self.num_burn = int(self.num_iter / 5)
class BasicModelLearningTestCase(unittest.TestCase):
    def setUp(self):

        # Basic parameters
        self.K = 100
        self.ds = 3
        self.do = 3

        # System matrices
        params = dict()
        params['F'] = np.array([[0.9,0.8,0.7],[0,0.9,0.8],[0,0,0.7]])
        params['Q'] = np.array([[0.1,0.05,0],[0.05,0.1,0.05],[0,0.05,0.1]])
        params['H'] = np.identity(self.do)
        params['R'] = 0.1*np.identity(self.do)
        self.params = params

        # Create model
        prior = GaussianDensity(np.zeros(self.ds), np.identity(self.ds))
        self.model = BasicLinearModel(self.ds, self.do, prior, self.params)

        # Simulate data
        np.random.seed(1)
        self.state, self.observ = self.model.simulate_data(self.K)

        # Create initial estimated model
        est_params = dict()
        est_params['F'] = 0.5*np.identity(self.ds)
        est_params['Q'] = np.identity(self.ds)
        est_params['H'] = np.identity(self.do)
        est_params['R'] = np.identity(self.do)
        est_model = BasicLinearModel(self.ds, self.do, prior, est_params)
        self.est_model = est_model

        # Set MCMC parameters
        self.num_iter = 200
        self.num_burn = int(self.num_iter/5)
K = 10
ds = 2
do = 1

params = dict()
params['F'] = np.array([[0.9,0.81],[0,0.9]])
params['Q'] = np.array([[1,0],[0,1]])
params['H'] = np.array([[1,0]])
params['R'] = np.array([[1]])

prior = GaussianDensity(np.array([0,0]), np.array([[100,0],[0,100]]))
model = BasicLinearModel(ds, do, prior, params)

np.random.seed(0)
state, observ = model.simulate_data(K)

fig = plt.figure()
for dd in range(ds):
    ax = fig.add_subplot(ds,1,dd+1)
    ax.plot(state[:,dd])

fig = plt.figure()
for dd in range(do):
    ax = fig.add_subplot(do,1,dd+1)
    ax.plot(observ[:,dd])


# Kalman filter
t0 = timer()
flt, prd, lhood = model.kalman_filter(observ)