()
| 18 | return diff |
| 19 | |
| 20 | def example_0(): |
| 21 | # learns to repeat simple sequence from random inputs |
| 22 | np.random.seed(0) |
| 23 | |
| 24 | # parameters for input data dimension and lstm cell count |
| 25 | mem_cell_ct = 100 |
| 26 | x_dim = 50 |
| 27 | concat_len = x_dim + mem_cell_ct |
| 28 | lstm_param = LstmParam(mem_cell_ct, x_dim) |
| 29 | lstm_net = LstmNetwork(lstm_param) |
| 30 | y_list = [-0.5,0.2,0.1, -0.5] |
| 31 | input_val_arr = [np.random.random(x_dim) for _ in y_list] |
| 32 | |
| 33 | for cur_iter in range(100): |
| 34 | print "cur iter: ", cur_iter |
| 35 | print "input_val_arr=", input_val_arr |
| 36 | print "y_list=", y_list |
| 37 | for ind in range(len(y_list)): |
| 38 | lstm_net.x_list_add(input_val_arr[ind]) |
| 39 | print "y_pred[%d] : %f" % (ind, lstm_net.lstm_node_list[ind].state.h[0]) |
| 40 | |
| 41 | loss = lstm_net.y_list_is(y_list, ToyLossLayer) |
| 42 | print "loss: ", loss |
| 43 | lstm_param.apply_diff(lr=0.1) |
| 44 | lstm_net.x_list_clear() |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | example_0() |
no test coverage detected