In [1]:
%matplotlib inline

import h5py
import matplotlib.pyplot as plt
import numpy as np

from sklearn import mixture
from mvn import MVN

In [2]:
# constants
RESAMPLE = 6
GMM_DYN_COMPONENTS = 10
INITIAL_VARIANCE_RATIO = 0.1

In [3]:
# load data
f = h5py.File( 'data.h5', 'r' )
x = f[ 'x' ]
x = x[ ::RESAMPLE ]

In [4]:
# plot data
fig, ax1 = plt.subplots()
ax1.plot( x[ :,1 ], 'g-' )
ax1.set_ylabel( r'$\theta$' )

ax2 = ax1.twinx()
ax2.plot( x[ :, 5 ], 'b' )
ax2.set_ylabel( '$F$' )


Out[4]:
<matplotlib.text.Text at 0xaf6af7f0>

In [5]:
g1 = MVN( x[ 10, 1:], np.array( [ 0.5, 0.5, 0.5, 0.5, 0.5  ] ) )

In [6]:
x_dyn = np.column_stack( ( x[ 1:, 1:5 ], x[ :-1, 1:6 ] ) )

In [7]:
gmm = mixture.GMM( n_components=GMM_DYN_COMPONENTS, covariance_type='full' )
gmm.fit( x_dyn )


Out[7]:
GMM(covariance_type='full', init_params='wmc', min_covar=0.001,
  n_components=10, n_init=1, n_iter=100, params='wmc', random_state=None,
  thresh=None, tol=0.001)

In [8]:
g1 = MVN( x_dyn[ 13, :], np.diag( x_dyn[ 13, :] * INITIAL_VARIANCE_RATIO ) )

In [10]:
g = g1.cond( x_dyn[ 13,4: ] )


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-a62bc3925394> in <module>()
----> 1 g = g1.cond( x_dyn[ 13,4: ] )

/home/user/work/gps/mvn.py in cond(self, a)
     49 
     50                 t = np.dot( cov12, np.linalg.inv( cov22 ) )
---> 51                 mi = mi1 + np.dot( t, a - mi2 )
     52                 cov = cov11 - np.dot( t, cov21 )
     53 

ValueError: operands could not be broadcast together with shapes (5,) (4,) 

In [ ]: