I'm using pykalman for regression, but I would like to estimate the error of the regression coefficient. Specifiacally, we have the following expressions:
Y(t) = B(t)X(t) + v
where the regression coefficient (B) itself is a random process given by:
B(t) = B(t-1) + w
So the "noise" I'm dealing with is given by v and w, representing gaussian noise where:
w ~ N(0, Q)
v ~ N(0, R)
Now - I would like detrmine the signal/noise ratio expressed as Q / R. My question is how to extract these values from the pykalman process. Currently, my code only returns the regression coefficient, but how to I get hold of Q and R?
def UpdateKalman(self, ins1, ins2):
obs_mat = np.array([[ins1, 1.0]])
means, covs = self.kf.filter_update(self.previous_state_means.T,
self.previous_state_covs[0],
observation=np.asarray(ins2),
observation_matrix=obs_mat)
self.previous_state_covs = covs
self.previous_state_means = means
beta = means[:, 0][0]
return beta
If you want to get the observation co-variance (which I understand you have termed R in your question), and the transition co-variance (which I understand you have termed Q), you can get them directly from the pykalman.standard.KalmanFilter
class object.
Assuming in your example self.kf
is suck an object you can get these as:
R = self.kf.observation_covariance
Q = self.kf.transition_covariance
It's my understanding that this object, and these matrices are updated in your code by the filter_update
step even through it is not returned as an output from that function.