(self, X, max_iter=10, print_period=1)
| 21 | self.session = session |
| 22 | |
| 23 | def fit(self, X, max_iter=10, print_period=1): |
| 24 | # train the HMM model using stochastic gradient descent |
| 25 | |
| 26 | N = len(X) |
| 27 | print("number of train samples:", N) |
| 28 | |
| 29 | costs = [] |
| 30 | for it in range(max_iter): |
| 31 | if it % print_period == 0: |
| 32 | print("it:", it) |
| 33 | |
| 34 | for n in range(N): |
| 35 | # this would of course be much faster if we didn't do this on |
| 36 | # every iteration of the loop |
| 37 | c = self.get_cost_multi(X).sum() |
| 38 | costs.append(c) |
| 39 | self.session.run(self.train_op, feed_dict={self.tfx: X[n]}) |
| 40 | |
| 41 | plt.plot(costs) |
| 42 | plt.show() |
| 43 | |
| 44 | def get_cost(self, x): |
| 45 | # returns log P(x | model) |
no test coverage detected