(self, X, max_iter=10)
| 141 | self.session.run([op1, op2, op3, op4, op5]) |
| 142 | |
| 143 | def fit(self, X, max_iter=10): |
| 144 | # train the HMM model using stochastic gradient descent |
| 145 | |
| 146 | N = len(X) |
| 147 | print("number of train samples:", N) |
| 148 | |
| 149 | costs = [] |
| 150 | for it in range(max_iter): |
| 151 | if it % 1 == 0: |
| 152 | print("it:", it) |
| 153 | |
| 154 | for n in range(N): |
| 155 | # this would of course be much faster if we didn't do this on |
| 156 | # every iteration of the loop |
| 157 | c = self.get_cost_multi(X).sum() |
| 158 | costs.append(c) |
| 159 | self.session.run(self.train_op, feed_dict={self.tfx: X[n]}) |
| 160 | |
| 161 | plt.plot(costs) |
| 162 | plt.show() |
| 163 | |
| 164 | def get_cost(self, x): |
| 165 | return self.session.run(self.cost_op, feed_dict={self.tfx: x}) |
no test coverage detected