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)
Ejemplo n.º 2
0
 def setUp(self):
     
     # Basic parameters
     self.K = 10
     self.ds = 2
     self.do = 1
     
     # System matrices
     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]])
     
     # Create model
     prior = GaussianDensity(np.array([0,0]), np.array([[100,0],[0,100]]))
     self.model = BasicLinearModel(self.ds, self.do, prior, params)
Ejemplo n.º 3
0
from learners_mcmc import MCMCLearnerForBasicModelWithMNIWPrior

plt.close('all')

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])

Ejemplo n.º 4
0
est_params['F'] = np.vstack((np.hstack((Imat,Imat)), np.hstack((Zmat,Imat))))

est_params['Q'] = 0.001*np.vstack((np.hstack((Imat/3.0,Imat/2.0)), np.hstack((Imat/2.0,Imat/1.0))))
est_params['val'], est_params['vec'] = la.eigh(est_params['Q'])
est_params['rank'] = np.array([ds])
#val,vec = la.eigh(est_params['Q'])
#est_params['val'] = val[:1]
#est_params['vec'] = vec[:,:1]
#est_params['rank'] = np.array([1])

est_params['H'] = np.hstack((np.identity(d),np.zeros((d,d))))
est_params['R'] = 0.001*np.identity(d)

prior = GaussianDensity(np.zeros(ds), 1000*np.identity(ds))
est_degenerate_model = DegenerateLinearModel(ds, do, prior, est_params)
est_basic_model = BasicLinearModel(ds, do, prior, est_params)
est_naive_model = BasicLinearModel(ds, do, prior, est_params)

# Hyperparameters
hyperparams = dict()
hyperparams['nu0'] = ds
hyperparams['rPsi0'] = 0.001*np.identity(ds)
hyperparams['Psi0'] = ds*hyperparams['rPsi0']
hyperparams['M0'] = np.zeros((ds,ds))
hyperparams['V0'] = 1E2*np.identity(ds)
hyperparams['alpha'] = 0.01
hyperparams['a0'] = 1
hyperparams['b0'] = 0.001

# Algorithm parameters
algoparams = dict()
Ejemplo n.º 5
0
hyperparams['rPsi0'] = np.identity(ds)
hyperparams['Psi0'] = hyperparams['nu0'] * hyperparams['rPsi0']
hyperparams['alpha'] = 1
hyperparams['M0'] = np.zeros((ds, ds))
hyperparams['V0'] = 100 * np.identity(ds)
hyperparams['a0'] = 1
hyperparams['b0'] = hyperparams['a0'] * 0.1

algoparams = dict()
algoparams['rotate'] = 1E-2
algoparams['perturb'] = 1E-6

# Learning
if model_type == 'basic':

    est_model = BasicLinearModel(ds, do, prior, est_params)
    learner = MCMCLearnerB(est_model,
                           observ,
                           hyperparams,
                           algoparams=algoparams,
                           verbose=True)

    for ii in range(num_iter):
        print("Running iteration {} of {}.".format(ii + 1, num_iter))

        learner.sample_transition()
        learner.sample_observation_diagonal_covariance()
        learner.sample_state_trajectory()
        learner.save_link()

elif model_type == 'degenerate':