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 compute_loglikelihood(self): | |
#Init the list of loglikelihhod values, one value for each y observation | |
ll = [] | |
for t in range(len(self.y)): | |
prob_y_t = 0 | |
mu_t = 0 | |
for j in range(self.k_regimes): | |
#To use the law of total probability, uncomment this row and comment out the next | |
# two rows | |
#prob_y_t += poisson.pmf(y[t], mu[t][j]) * self.delta_matrix[t][j] | |
#Calculate the Poisson mean mu_t as an expectation over all Markov state | |
# probabilities | |
mu_t += self.mu_matrix[t][j] * self.delta_matrix[t][j] | |
prob_y_t += poisson.pmf(self.y[t], mu_t) | |
#This is a bit of a kludge. If the likelihood turns out to be real tiny, fix it to | |
# the EPS value for the machine | |
if prob_y_t < self.EPS: | |
prob_y_t = self.EPS | |
#Push the LL into the list of LLs | |
ll.append(math.log(prob_y_t)) | |
ll = np.array(ll) | |
return ll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment