def setUp(self):

        self.red = NeuralNetwork(2, [1, 1])

        self.layer = NeuralLayer(2, 1)

        self.layer2 = NeuralLayer(1, 1)

        self.neuron = Neuron(2)

        self.neuron2 = Neuron(1)

        self.red2 = NeuralNetwork(2, [2, 2])

        self.lay1 = NeuralLayer(2, 2)

        self.lay2 = NeuralLayer(2, 2)

        self.neur1 = Neuron(2)

        self.neur2 = Neuron(2)

        self.neur3 = Neuron(2)

        self.neur4 = Neuron(2)
Exemplo n.º 2
0
    def learn_network(self):
        count_neurons1 = self.count_neurons_l1_spinbox.value()
        count_neurons2 = self.count_neurons_l2_spinbox.value()

        count_inputs_n1 = self.neuron_l1_count_inputs_spinbox.value()
        count_component_input_n1 = self.neuron_l1_count_input_components_spinbox.value(
        )
        count_inputs_n2 = self.neuron_l2_count_inputs_spinbox.value()

        self.ours = FileReader.read_matrix_files(self.ours_paths,
                                                 count_inputs_n1,
                                                 count_component_input_n1)
        self.aliens = FileReader.read_matrix_files(self.aliens_paths,
                                                   count_inputs_n1,
                                                   count_component_input_n1)

        self.network = nn.NeuralNetwork(h=count_inputs_n1,
                                        g=count_inputs_n2,
                                        components=count_component_input_n1,
                                        n1=count_neurons1,
                                        n2=count_neurons2)

        self.network.learn(self.k1, self.k2, self.ours, self.aliens)

        QMessageBox.about(None, "Learn neural network", "Done!")
 def __init__(self, nEpochs=500, nInputs=8, nNeurCapas=[8, 19]):
     self.red = NeuralNetwork(nInputs, nNeurCapas)
     self.lineList = trainReader()
     self.outputList = []
     shuffle(self.lineList)
     self.outlist(self.lineList, self.outputList)
     # self.datatrain(nEpochs)
     print("Funciono Entrenamiento: CheckPoint 1")
     self.dataList = dataReader()
     self.dataOut = []
     self.outlist(self.dataList, self.dataOut)
     self.curveTraining()
Exemplo n.º 4
0
    def load_network(self):
        fileName = self.__openFileNameDialog("Network config file (*.json)")

        if fileName:
            with open(fileName, 'r') as file_in:
                file_text = file_in.read()
                json_obj = json.loads(file_text)
                json_obj['mu'] = np.array(json_obj['mu'])
                json_obj['W'] = np.array(json_obj['W'])

                self.network = nn.NeuralNetwork()
                self.network.__dict__ = json_obj

            QMessageBox.about(None, "Loading neural network", "Done!")
Exemplo n.º 5
0
 def __init__(self, nTrain=1000, nInputs=2, nNeurCapas=(2, 3, 1)):
     self.Network = NeuralNetwork(nInputs, nNeurCapas)
     self.Inputs = []
     self.Outputs = []
     I1 = [0, 0]
     I2 = [0, 1]
     I3 = [1, 0]
     I4 = [1, 1]
     for i in range(nTrain):
         self.Inputs.append(I1)
         self.Inputs.append(I2)
         self.Inputs.append(I3)
         self.Inputs.append(I4)
         self.Outputs.append([xor(I1[0], I1[1])])
         self.Outputs.append([xor(I2[0], I2[1])])
         self.Outputs.append([xor(I3[0], I3[1])])
         self.Outputs.append([xor(I4[0], I4[1])])
     self.Network.realTraining(self.Inputs, self.Outputs)
     self.Network.feed([0, 0])
     print(self.Network.getOutput())
Exemplo n.º 6
0
from Network import NeuralNetwork
import random
import numpy as np
import matplotlib.pyplot as plt
import cv2

input_nodes = 9
hidden_nodes = 5
output_nodes = 2
learning_rate = 0.2

n = NeuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)

ppi = np.array([[0.3, 0.3]])

epochs = 1111

for i in range(epochs):
    a = np.random.permutation(18)
    for pro in a:
        number = pro
        # number = random.randint(0, 17)
        if number == 1 or number == 2 or number == 3:
            rightAnswers = np.array([[1, 0]])
        elif number == 4 or number == 5 or number == 6:
            rightAnswers = np.array([[0, 1]])
        elif 6 < number < 16 or number == 17:
            rightAnswers = np.array([[1, 1]])
        elif number == 0 or number == 16:
            rightAnswers = np.array([[0, 0]])
Exemplo n.º 7
0
def main():
    # Creating NN
    nn = NeuralNetwork([784, 64, 3])
    # Creating training data
    createTraining(cats_training, "cat")
    createTraining(trains_training, "train")
    createTraining(rainbows_training, "rainbow")
    # Creating test data
    createTest(cats_testing, "cat")
    createTest(trains_testing, "train")
    createTest(rainbows_testing, "rainbow")
    # make one array from all the training and test data
    training_data = cats_training + trains_training + rainbows_training
    testing_data = cats_testing + trains_testing + rainbows_testing
    # Normalize the training data and testing data, (0-1)
    normalizeValues(trains_training)
    normalizeValues(testing_data)
    # arrange the data in specific format that will fit to the NN library i created.
    for j in range(2400):
        for i in range(785):
            training_data[j][i] = [training_data[j][i]]
    for j in range(600):
        for i in range(785):
            testing_data[j][i] = [testing_data[j][i]]
    '''
    training the model with the training data (30 times),
    shuffle the training data every iteration.
    specific target to every label.
    '''
    for i in range(35):
        random.shuffle(training_data)
        for j in range(2400):
            target = [[0], [0], [0]]
            if (training_data[j][784] == ['cat']):
                target[0] = [1]
                nn.train(training_data[j][:-1], target, 1)
            if (training_data[j][784] == ['train']):
                target[1] = [1]
                nn.train(training_data[j][:-1], target, 1)
            if (training_data[j][784] == ['rainbow']):
                target[2] = [1]
                nn.train(training_data[j][:-1], target, 1)
    '''
    Calculate the acc. should be more various of training data.
    currently : 800 cats, 800 rainbows, 800 trains.
    '''
    acc = 0
    trains = 0
    rainbows = 0
    cats = 0
    for i in range(len(testing_data)):
        label = testing_data[i][784]
        guess = nn.feed_forword(testing_data[i][:-1])
        if max(guess) == guess[0] and label == ['cat']:
            acc += 1
            cats += 1
        if max(guess) == guess[1] and label == ['train']:
            acc += 1
            trains += 1
        if max(guess) == guess[2] and label == ['rainbow']:
            acc += 1
            rainbows += 1
    print("Acc : " + str(acc))
    print("length of testing data : " + str(len(testing_data)))
    print("Cats : " + str(cats))
    print("Rainbows : " + str(rainbows))
    print("trains : " + str(trains))
Exemplo n.º 8
0
from Network import NeuralNetwork
import cv2
import numpy as np
import matplotlib.pyplot as plt

n = NeuralNetwork(9, 5, 2, 0.3)

n.synaptic_weight1 = np.load('./weights/example_1.npy')
n.synaptic_weight2 = np.load('./weights/example_2.npy')


image = cv2.imread("dataset/test/test2.0.png", 0)

inputs = image.flatten()
inputs = np.asfarray(inputs / 255.0 * 0.99) + 0.01
answers = n.query(inputs)
print(str(answers[0]) + str(answers[1]))

plt.imshow(image)
plt.xlabel('test2.0.png')
plt.title(str(answers[0]) + '  --  ' + str(answers[1]))
plt.show()


for i in range(18):
    image = cv2.imread("dataset/test/" + str(i) + ".png", 0)

    inputs = image.flatten()
    inputs = np.asfarray(inputs / 255.0 * 0.99) + 0.01
    answers = n.query(inputs)
    print(str(answers[0]) + str(answers[1]))