Esempio n. 1
0
def test_thetas_size():
    errors = []
    desired_layers = [4, 3, 4, 3, 3]
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    for i in xrange(len(desired_layers) - 1):
        if not nn._theta[i].size == desired_layers[i + 1]:
            errors.append("error")
    assert not errors
Esempio n. 2
0
def test_activations_size():
    errors = []
    desired_layers = [4, 3, 4, 3, 3]
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    for i in xrange(len(desired_layers)):
        if not nn._activations[i].size == desired_layers[i]:
            errors.append("error")
    assert not errors
Esempio n. 3
0
def test_layers_sizes():
    errors = []
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    if not nn._layers == [4, 3, 4, 3, 3]:
        errors.append("error")
    if not nn._C == 5:
        errors.append("error")
    assert not errors
Esempio n. 4
0
def test_weights_size():
    errors = []
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    if not len(nn._weights) == 4:
        errors.append("error")
    for i in xrange(1, 5):
        if nn._weights[i - 1].shape != (nn._layers[i - 1], nn._layers[i]):
            errors.append("error")
    assert not errors
#! /usr/bin/python
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import aux_funcs as aux
import numpy as np
import classes as g_c
    
if __name__ == '__main__':
    my_seed = 42 #SEED
    max_iter = 300 #Max iterations for training
    learning_rate = 0.02 #learning rate (alfa)
    
    print "Start dummy test with XORG problem..."

    nn = g_c.MLPerceptron(2, [2], 1)

    print "MLPerceptron created with layers ", nn._layers

    classes = np.array([0,0,1,1])
    data = np.array([np.array([0, 0]), np.array([1, 1]), np.array([1, 0]), np.array([0, 1])])

    print "Classes and data ready"

    print "Starting training by hand..."
    test = range(4)
    for i in xrange(5000):
        to_train = np.random.choice(test)
        nn.train(classes[to_train], data[to_train], learning_rate)
    print "trained"
Esempio n. 6
0
def test_layers():
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    assert nn._layers == [4, 3, 4, 3, 3] and nn._C == 5
Esempio n. 7
0
def test_net_input():
    nn = cl.MLPerceptron(4, [3, 4, 3], 3)
    nn.net_input(np.array([1, 2, 3, 4]))
    assert np.array_equal(nn._activations[0], np.array([1, 2, 3, 4]))