def main(): training, dev = get_data() window_size = 5 n_input = window_size n_hidden = 100 n_output = 1 A = 1 num_hidden_layers = 1 mlp = MLP(n_input, num_hidden_layers, n_hidden, n_output) n_epochs = 50 step = False l = loss(mlp, training, window_size, window_size/2) print "initial loss: " + str(l) for j in range(0, n_epochs): print "epoch " + str(j) random.shuffle(training) c = 0 for xs, y in training: if c == 10: break c += 1 if step: train(mlp, xs, y, window_size, window_size/2) else: train(mlp, xs, y, window_size, 1) if step: error(mlp, training, window_size, window_size/2) else: error(mlp, training, window_size, 1) if step: l = loss(mlp, training, window_size, window_size/2) else: l = loss(mlp, training, window_size, 1) print "loss: " + str(l) eta = A / float(j/float(n_epochs) + 1) mlp.eta = eta print "lr:", mlp.eta print "Getting Dev Accuracy..." if step: error(mlp, dev, window_size, window_size/2) else: error(mlp, dev, window_size, 1)
def main(): training, count_c0, count_c1 = get_data(122) dev, _, _ = get_data(122,True) series_c0, series_c1 = get_time_series() # A window of 240 corresponds to two hours of heart rate window_size = 240 print "#class0: ", count_c0/float(window_size), "#class1:", count_c1/float(window_size) c1 = 0 c0 = 0 print "len training = " + str(len(training)) count0 = 0 count1 = 0 random.shuffle(training) n_input = window_size n_hidden = 100 n_output = 1 num_hidden_layers = 1 eta_c = .005 A = .0008 eta = eta_c mlp = MLP(n_input, num_hidden_layers, n_hidden, n_output, eta) n_epochs = 400 step = True l = loss(mlp, training, window_size, window_size/2) print "initial loss: " + str(l) for j in range(0, n_epochs): print "epoch " + str(j) random.shuffle(training) c = 0 grad = None for xs, y in training: if c == 10: break c += 1 part_grad = None if step: part_grad = train(mlp, xs, y, window_size, window_size/2) else: part_grad = train(mlp, xs, y, window_size, 1) grad = sum_grad(grad, part_grad) mlp.update_weights(grad) if step: error(mlp, training, window_size, window_size/2) else: error(mlp, training, window_size, 1) if step: l = loss(mlp, training, window_size, window_size/2) else: l = loss(mlp, training, window_size, 1) print "loss: " + str(l) eta = A / float(j/float(n_epochs) + 1) mlp.eta = eta print "lr:", mlp.eta if n_epochs % 10 == 0: if step: error(mlp, dev, window_size, window_size/2, True) else: error(mlp, dev, window_size, 1, True) print "Getting training accuracy..." if step: error(mlp, training, window_size, window_size/2) else: error(mlp, training, window_size, 1) print "Getting dev accuracy..." if step: error(mlp, dev, window_size, window_size/2, True) probs(mlp, series_c0, series_c1, window_size, window_size/2) else: error(mlp, dev, window_size, 1, True) probs(mlp, series_c0, series_c1, window_size, 1)