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

Function fit_coin

hmm_class/hmmd_theano2.py:126–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124
125
126def fit_coin():
127 X = []
128 for line in open('coin_data.txt'):
129 # 1 for H, 0 for T
130 x = [1 if e == 'H' else 0 for e in line.rstrip()]
131 X.append(x)
132
133 hmm = HMM(2)
134 hmm.fit(X)
135 L = hmm.get_cost_multi(X).sum()
136 print("LL with fitted params:", L)
137
138 # try true values
139 # remember these must be in their "pre-softmax" forms
140 pi = np.log( np.array([0.5, 0.5]) )
141 A = np.log( np.array([[0.1, 0.9], [0.8, 0.2]]) )
142 B = np.log( np.array([[0.6, 0.4], [0.3, 0.7]]) )
143 hmm.set(pi, A, B)
144 L = hmm.get_cost_multi(X).sum()
145 print("LL with true params:", L)
146
147
148if __name__ == '__main__':

Callers 1

hmmd_theano2.pyFile · 0.70

Calls 4

fitMethod · 0.95
get_cost_multiMethod · 0.95
setMethod · 0.95
HMMClass · 0.70

Tested by

no test coverage detected