Пример #1
0
def test_xor():
    """
    This method will run the test on xor dataset.
    """
    dg = xor()  # Initialize a dataset creator
    training_data, training_labels = dg.query_data(samples=100)

    n = xor_net(training_data,
                training_labels)  # This call should return a net object
    params = n.get_params(
    )  # This call should reaturn parameters of the model that are
    # fully trained.

    testing_data, testing_labels = dg.query_data(
        samples=100)  # Create a random testing dataset.
    predictions = n.get_predictions(
        testing_data)  # This call should return predictions.

    print "Accuracy of predictions on XOR data = " + str(
        accuracy(testing_labels, predictions)) + "%"
import sys
sys.path.append('../')

from tools.trainer import trainer, poly_trainer
from network import expert, novice, judge

from dataset import xor
from globals import *

if __name__ == '__main__':
    dataset = xor()

    ################ Expert ################
    print(" \n\n Expert Assembly \n\n")
    expert_net = expert(images=dataset.images)
    expert_net.cook(labels=dataset.labels)
    expert_bp = trainer(expert_net,
                        dataset.feed,
                        init_vars=False,
                        tensorboard='expert')

    ################ Indpendent Novice ################
    """
    print (" \n\n Independent Novice Assembly \n\n")
    indep_net = novice(images = dataset.images, 
                    name = 'novice_independent')  
    indep_net.cook( labels = dataset.labels )
    indep_bp = trainer( indep_net, 
                        session = expert_bp.session,
                        dataset.feed)
    """
Пример #3
0
        num_classes = 26
        (X, y) = dataset.character()
        hidden_layer = 20
        data = np.array([
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
            0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0,
            0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]).reshape(1, 64)
    elif (args["type"] == '2'):
        num_classes = 6
        (X, y) = dataset.lima_bit()
        hidden_layer = 12
        data = np.array([0, 0, 0, 1, 0]).reshape(1, 5)
    elif (args["type"] == '3'):
        num_classes = 2
        (X, y) = dataset.xor()
        hidden_layer = 2
        data = np.array([0, 0]).reshape(1, 2)
    elif (args["type"] == '4'):
        num_classes = 2
        (X, y) = dataset.tiga_bit()
        hidden_layer = 3
        data = np.array([0, 1, 0]).reshape(1, 3)

    num_inputs = X.shape[1]
    shape = (num_inputs, hidden_layer, num_classes)

    # Set up
    cost_func = functools.partial(eval_neural_network, shape=shape, X=X, y=y)
    swarm = pso.ParticleSwarm(cost_func, dim=dim_weights(shape), size=50)