This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __init__(self, endog, exog, k_regimes=2, loglike=None, score=None, hessian=None, | |
missing='none', extra_params_names=None, **kwds): | |
super(PoissonHMM, self).__init__(endog=endog, exog=exog, loglike=loglike, score=score, | |
hessian=hessian, missing=missing, | |
extra_params_names=extra_params_names, kwds=kwds) | |
self.y = np.array(self.endog) | |
self.k_regimes = k_regimes | |
#k_regimes x exog.shape[1] size matrix of regime specific regression coefficients | |
self.beta_matrix = np.ones([self.k_regimes, self.exog.shape[1]]) | |
# k x k matrix of psuedo transition probabilities which can range from -inf to +inf during | |
# optimization. Initialized to 1.0/k | |
self.q_matrix = np.ones([self.k_regimes,self.k_regimes])*(1.0/self.k_regimes) | |
print('self.q_matrix='+str(self.q_matrix)) | |
#The regime wise matrix of Poisson means. These would be updated during the optimization | |
# loop | |
self.mu_matrix = [] | |
# k x k matrix of the real Markov transition probabilities which will be calculated from | |
# the q-matrix using a standardization technique. Initialized to 1.0/k | |
self.gamma_matrix = np.ones([self.k_regimes, self.k_regimes])*(1.0/self.k_regimes) | |
print('self.gamma_matrix='+str(self.gamma_matrix)) | |
# The Markov state probabilities. Also referred to as pi. but we'll use delta since pi is | |
# often used to refer to the mean | |
self.delta_matrix = np.ones([self.exog.shape[0],self.k_regimes])*(1.0/self.k_regimes) | |
print('self.delta_matrix='+str(self.delta_matrix)) | |
#The vector of initial values for all the parameters, beta and q, that the optimizer will | |
# optimize | |
self.start_params = np.repeat(np.ones(self.exog.shape[1]), repeats=self.k_regimes) | |
self.start_params = np.append(self.start_params, self.q_matrix.flatten()) | |
print('self.start_params='+str(self.start_params)) | |
#A very tiny number (machine specific). Used by the LL function. | |
self.EPS = np.MachAr().eps | |
#Optimization iteration counter | |
self.iter_num=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment