# fix seed of PyPolyaGamma, otherwise results aren't reproducible
ppgsseed=4
ifppgsseed==4:
print("Using default seed")
...
...
@@ -52,7 +52,7 @@ class Dynamic_GLM(GibbsSampling):
self.T=T
self.jumplimit=jumplimit
self.x_0=prior_mean
self.P_0,self.Q=P_0,Q
self.P_0,self.Q=P_0,Q# initial variance of regressors P_0, and variance for timesteps Q (can have different variances, we have it fixed)
self.psi_diff_saves=[]# this can be used to resample the variance, but is currently unused
self.noise_mean=np.zeros(self.n_regressors)# save this, so as to not keep creating it
self.identity=np.eye(self.n_regressors)# not really needed, but kinda useful for state sampling
...
...
@@ -81,8 +81,11 @@ class Dynamic_GLM(GibbsSampling):
returnoutputs
deflog_likelihood(self,input,timepoint):
"""
Given input from a single session (a matrix containing features and responses) and the timepoint information from that session, return log-likelihoods for observations.
"""
predictors,responses=input[:,:-1],input[:,-1]
nans=np.isnan(responses)
nans=np.isnan(responses)# can come from cross-validation
probs=np.zeros((input.shape[0],2))
out=np.zeros(input.shape[0])
# I could possibly save the 1 / ..., since it's logged it's just - log (but the other half of the probs is an issue)
...
...
@@ -97,17 +100,26 @@ class Dynamic_GLM(GibbsSampling):
# Gibbs sampling
defresample(self,data=[]):
"""
Resampling of dynamic logistic random variables.
We follow the resampling scheme of Windle: "Efficient Data Augmentation in Dynamic Models for Binary and Count Data".
This makes use of the forward filter backwards sample algorithm. Which uses Kalman filtering, for which we use Anderson & Moore 1979
Usually you just get one type of observation per timestep (one set of features), but we have a number of different feature sets per timestep. Thus,
we invent more timesteps, but we don't allow the regressors to change from these steps to steps, effectively making the observations occur at the same
time.
"""
# TODO: Clean up this mess, I always have to call delete_obs_data because of all the saved shit!