MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_state_sequence

Method get_state_sequence

hmm_class/hmmd.py:162–179  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

160 return np.log(self.likelihood_multi(X))
161
162 def get_state_sequence(self, x):
163 # returns the most likely state sequence given observed sequence x
164 # using the Viterbi algorithm
165 T = len(x)
166 delta = np.zeros((T, self.M))
167 psi = np.zeros((T, self.M))
168 delta[0] = self.pi*self.B[:,x[0]]
169 for t in range(1, T):
170 for j in range(self.M):
171 delta[t,j] = np.max(delta[t-1]*self.A[:,j]) * self.B[j, x[t]]
172 psi[t,j] = np.argmax(delta[t-1]*self.A[:,j])
173
174 # backtrack
175 states = np.zeros(T, dtype=np.int32)
176 states[T-1] = np.argmax(delta[T-1])
177 for t in range(T-2, -1, -1):
178 states[t] = psi[t+1, states[t+1]]
179 return states
180
181def fit_coin():
182 X = []

Callers 1

fit_coinFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected