def test_train(input_units, hidden_units, batch_size, nr_samples, rgen): nn = FcClassifier(input_units, hidden_units) nn.init_random() x_in = rgen.randn(nr_samples, input_units) y_in = rgen.randint(2, size=nr_samples) cost_old = nn.evaluate(x_in.T, y_in) nn.train(x_in, y_in, learning_rate=0.0005, nr_epochs=1, batch_size=batch_size) cost_new = nn.evaluate(x_in.T, y_in) assert cost_old > cost_new
def test_evaluate(input_units, hidden_units, nr_samples, rgen): nn = FcClassifier(input_units, hidden_units) nn.init_random() parameters = nn.get_weights() weights = list(w for w, _ in parameters) biases = list(b for _, b in parameters) x_in = rgen.randn(input_units, nr_samples) y_in = rgen.randint(2, size=nr_samples) cost = nn.evaluate(x_in, y_in) y_ref = fcnn_predict(x_in, weights, biases, it.repeat(sigmoid)) cost_ref = cross_entropy(y_in, y_ref) assert_almost_equal(cost, cost_ref)