Esempio n. 1
0
    def __init__(self, position):
        self.position = position
        self.rotation = random.random() * 2 * math.pi
        self.bearing = Vector(math.cos(self.rotation), math.sin(self.rotation))

        self.neural_net = NeuralNet(4, 1, 10, 3)
        self.fitness = 0
Esempio n. 2
0
    def __init__(self, position, usage, speed, angle):
        self.position = position
        self.rotation = angle
        self.bearing = Vector(math.cos(self.rotation), math.sin(self.rotation))

        self.neural_net = NeuralNet(5, 1, 10, 1)

        self.usage = usage
        self.speed = speed

        self.reset()
Esempio n. 3
0
def make_population(size,
                    input_size,
                    output_size,
                    hidden_layer_size=3,
                    numof_hidden_layers=1):
    population = []
    for i in range(size):
        population.append(
            NeuralNet(input_size, output_size, hidden_layer_size,
                      numof_hidden_layers))
    return population
Esempio n. 4
0
def train():
    neural_network = NeuralNet(row_size, row_size)
    neural_network.build_layers()

    (training_data, training_labels,
     label_mapper) = load_from_dataset('DS', row_size, row_size)
    #(training_data , training_labels ) = prepare_data('Datasets/DatasetSample0/Images',labels_dictionary,row_size,row_size)

    neural_network.fit_data(training_data, training_labels, 10, 0.998)
    neural_network.save_model('StoredModel')

    return "Finished Fitting/Saving Model"
Esempio n. 5
0
 def toggle(self):
     if self.toggle_btn.config('relief')[-1] == SUNKEN:
         self.toggle_btn.config(text="Learning", relief=RAISED)
         self.neural_net = None
     else:
         self.toggle_btn.config(text="Testing", relief=SUNKEN)
         self.neural_net = NeuralNet(
             "data.txt",
             algorithm=self.controller.learning_algorithm,
             layer_arch=self.controller.architecture,
             learning_rate=self.controller.learning_rate,
             max_iter=self.controller.max_iter)
         self.neural_net.learn()
Esempio n. 6
0
def the_method():
    if request.headers['Content-Type'] == 'text/plain':
        return "Text Message: " + request.data

    elif request.headers['Content-Type'] == 'application/json':
        return "JSON Message: " + json.dumps(request.json)

    elif request.headers['Content-Type'] == 'application/octet-stream':
        print(request.data)
        f = open('./binary', 'wb')
        f.write(request.data)
        f.close()
        return "Binary message written!"
    else:
        f = request.files['binarydata']
        f.seek(0)
        my_bytes = f.read()

        index = 0
        matrix = []
        row = []
        for byte in my_bytes:
            normalized = (float(byte) - 0) / (255 - 0)
            row.append(normalized)
            if (index % row_size == (row_size - 1)):
                matrix.append(row)
                row = []
            index = index + 1
        np_array = np.array([matrix], dtype=np.float64)

        print(np_array[0].shape)
        #print("np_array[0]. Type : {} | Value : {}".format(type(np_array[0][0][0]),np_array[0][0][0]))

        neural_network = NeuralNet(row_size, row_size)
        neural_network.load_model('StoredModel.modelconfig')

        arg_max, max_val = neural_network.predict_element(np_array)
        lb = labels_map[arg_max]
        print('ArgMax : {} | MaxVal : {} |Label : {}'.format(
            arg_max, max_val, lb))

        result = {
            'Confidence': max_val.item(),
            'Predicted': arg_max.item(),
            'Label': lb
        }
        return json.dumps(result)
Esempio n. 7
0
    def __init__(self, rows, cols, brain = None):
        self.rows, self.cols = rows, cols

        self.board = np.zeros((rows, cols), dtype = np.uint8)
        self.board[:, 0] = self.board[:, -1] = 1
        self.board[0, :] = self.board[-1, :] = 1

        self.board[rows // 2, cols // 2] = 2
        self.snake = [Vector(cols // 2, rows // 2)]

        self.add_food()

        self.dir = Vector(1, 0)
        self.score = 0
        self.age = 0
        self.health = 100

        if brain is None:
            self.brain = NeuralNet(rows * cols + 1, rows * cols // 2, 4)
        else:
            self.brain = brain.copy()
Esempio n. 8
0
import numpy as np
import sys
from neural import NeuralNet
from dataset import get_all_categories_shuffled, numpy_array_from_file, prepare_data

labels_dictionary = {'Circle': 0, 'L': 1, 'RightArrow': 2}
labels_map = ['Circle', 'L', 'RightArrow']

#Replace with your root folder that holds the dataset of images
all_bytes, all_labels = prepare_data("Datasets/DatasetSample0/Images",
                                     labels_dictionary, 56, 56)

nn = NeuralNet(56, 56)
nn.build_layers()
nn.fit_data(training_data=all_bytes,
            training_labels=all_labels,
            epochs=10,
            accuracy=0.999)
nn.save_model('easter_egg_ahlabikyafraise_')
#nn.load_model('easter_egg_ahlabikyafraise_')

image_path = sys.argv[1]
test_image = numpy_array_from_file(image_path)
test_image = test_image / 255

arg_max, prediction_level = nn.predict_element(test_image)
print('arg_max : {} which is {} with prediction : {}'.format(
    arg_max, labels_map[arg_max], prediction_level))
    ([1, 0, 1, 1, 0, 0], [1]),
    ([1, 0, 1, 0, 1, 0], [1]),
    ([1, 1, 0, 0, 1, 1], [1]),
    ([1, 1, 1, 1, 0, 0], [1]),
    ([1, 0, 0, 0, 1, 1], [1]),
    ([1, 0, 0, 0, 1, 0], [0]),
    ([0, 1, 1, 1, 0, 1], [1]),
    ([0, 1, 1, 0, 1, 1], [0]),
    ([0, 0, 0, 1, 1, 0], [0]),
    ([0, 1, 0, 1, 0, 1], [0]),
    ([0, 0, 0, 1, 0, 1], [0]),
    ([0, 1, 1, 0, 1, 1], [0]),
    ([0, 1, 1, 1, 0, 0], [0]),
]

nn = NeuralNet(6, 1, 1)
nn.train(rn_training_data)

print(nn.get_ih_weights())
print()
print(nn.get_ho_weights())

print(nn.evaluate([1, 1, 1, 1, 1, 1]))
print(nn.evaluate([0, 0, 0, 0, 0, 0]))
print()
print(nn.evaluate([1, 0, 0, 0, 0, 0]))  # 1
print(nn.evaluate([0, 1, 0, 0, 0, 0]))  # 0
print(nn.evaluate([0, 0, 1, 0, 0, 0]))  # 0
print(nn.evaluate([0, 0, 0, 1, 0, 0]))  # 0
print(nn.evaluate([0, 0, 0, 0, 1, 0]))  # 0
print(nn.evaluate([0, 0, 0, 0, 0, 1]))  # 0