Beispiel #1
0
 def __init__(self, sdr_size=1000):
     super(CortexLocationAware, self).__init__(sdr_size=sdr_size)
     self.receptive_field_pixels = (28, 28)
     self.V1 = Area()
     self.V1.add_layer(Layer('L4', shape=sdr_size))
     self.V1.add_layer(
         LocationAwareLayer('L23',
                            canvas_shape=(50, 50),
                            patch_shape=(20, 20)))
     self.location_encoder = LocationEncoder(
         max_amplitude=np.linalg.norm(IMAGE_SIZE), shape=sdr_size)
     self.label_layer = LabelLayer(name="label", shape=sdr_size)
     self.retina = Layer('retina', shape=self.receptive_field_pixels)
     self.V1.layers['L4'].connect_input(self.retina)
     self.V1.layers['L23'].connect_input(self.V1.layers['L4'])
Beispiel #2
0
    def __init__(self, sdr_size=1000):
        self.receptive_field_pixels = (28, 28)
        self.V1 = Area()
        self.display = False

        self.V1.add_layer(Layer('L4', shape=sdr_size))

        self.V1.add_layer(Layer('L23', shape=sdr_size))
        self.V1.add_layer(Layer('motor_direction', shape=sdr_size))
        self.V1.add_layer(Layer('motor_amplitude', shape=sdr_size))

        self.location_encoder = LocationEncoder(
            max_amplitude=np.linalg.norm(IMAGE_SIZE), shape=sdr_size)
        self.label_layer = LabelLayer(name="label", shape=sdr_size)
        self.retina = Layer('retina', shape=self.receptive_field_pixels)

        self.V1.layers['L4'].connect_input(self.retina)

        self.V1.layers['L23'].connect_input(self.V1.layers['motor_direction'])
        self.V1.layers['L23'].connect_input(self.V1.layers['motor_amplitude'])
        self.V1.layers['L23'].connect_input(self.V1.layers['L4'])
Beispiel #3
0
from random import uniform
from time import time

from core.layer import Layer, InputLayer, OutputLayer
from core.network import Network


with open('snek-learning.yaml', 'r') as file:
    data = yaml.load(file)
    #data = data[:1000]

learning_data = [{'inputs': list(row[:5]), 'outputs': [row[5]]} for row in data]


inputs = InputLayer([1, 1, 1, 1, 1])
middle = Layer(5)
middle3 = Layer(3)
output = OutputLayer([1])

network = Network([inputs, middle, middle3, output], 'snek')
network.connect()
network.load_learning_data(learning_data)

network.print_data()
folds = 4
result = [0]
i = 0
start_time = time()
while sum(result) / folds < 90:
    results = network.learn_kfolds(folds, times=1)
    scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
Beispiel #4
0
    'Iris-versicolor': [0, 1, 0],
    'Iris-virginica': [1, 0, 0]
}

learning_data = []

with open('../data/training_data/iris.data', newline='') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        learning_data.append({
            'inputs': [float(x) for x in row[0:4]],
            'outputs': iris_map[row[4]]
        })

inputs = InputLayer([1, 1, 1, 1])
middle = Layer(5)
middle2 = Layer(3)
output = OutputLayer([1, 1, 1])

network = Network([inputs, middle, middle2, output], 'iris')
network.connect()

network.load_learning_data(learning_data)
network.normalize_learning_data()
print("------- learn -------")
network.print_data()

folds = 4
results = network.learn_kfolds(folds, times=1000)
scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
stuff = Counter(scores)
Beispiel #5
0
 def __init__(self, z_order):
     Layer.__init__(self, z_order)
Beispiel #6
0
learning_data = []

with open('../data/training_data/iris.data', newline='') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        learning_data.append({
            'inputs': [float(x) for x in row[0:4]],
            'outputs': iris_map[row[4]]
        })

map = load_som("../data/trained_networks/som.yaml")
inputs = InputLayer([1, 1, 1, 1], name='NormalInput')
inputs_som = InputSom([1, 1, 1, 1], map)
inputs_som.set_network_name('som')
middle = Layer(3)
output = OutputLayer([1, 1, 1])

network = Network([inputs, middle, output], 'som')
network.connect()
network.load_learning_data(learning_data)
middle.connect_layer(inputs_som, 'left')
network.dump_cypher('../data/cypher/som.cypher',
                    additional_neurons=inputs_som.neurons)
"""
#network.learn(times=5000) #input_layers=[inputs_som])
folds = 4
results = network.learn_kfolds(folds, times=1000)
scores = [(n, [round(x) for x in out] == check) for n, out, check in results]
stuff = Counter(scores)
print("folds results: ", [stuff[(i, True)] / (stuff[(i,False)] + stuff[(i, True)]) * 100 for i in range(folds)])
Beispiel #7
0
from core.neuron import BiasNeuron
from core.layer import Layer, InputLayer, OutputLayer
from core.network import Network


net_name = 'xor'
inputs = InputLayer([1, 1])
middle = Layer(2)
middle2 = Layer(2)
output = OutputLayer([1])

network = Network([inputs, middle, middle2, output], net_name)
network.connect()


learning_data = [
    {"inputs": [0, 0], "outputs": [0]},
    {"inputs": [0, 1], "outputs": [1]},
    {"inputs": [1, 1], "outputs": [0]},
    {"inputs": [1, 0], "outputs": [1]}
]

network.load_learning_data(learning_data)
network.normalize_learning_data()
print("------- learn -------")
network.print_data()

network.learn(times=10000)


i = [[0, 0], [0, 1], [1, 1], [1, 0]]
Beispiel #8
0
 def __init__(self, z_order):
     Layer.__init__(self, z_order)
     self.ground_type = GroundType.SAND
     self.item = None
Beispiel #9
0
from core.layer import Layer, InputLayer, OutputLayer
from core.network import Network

inputs = InputLayer([1, 1, 1])

middle1 = Layer(4)
middle2 = Layer(3)
output = OutputLayer([1, 1])

network = Network([inputs, middle1, middle2, output])
network.connect()

#print("changing weight of {} to 0.3".format(middle1.neurons[0]))
#middle1.neurons[0].outputs[0].update_weight(0.3)

for _ in range(100):
    print("-----middle1-------")
    [print(x.inputs) for x in middle1.neurons]
    [print(x.outputs) for x in middle1.neurons]
    print("-----middle2-------")
    [print(x.inputs) for x in middle2.neurons]
    [print(x.outputs) for x in middle2.neurons]

    network.stimulate()
    network.backpropagate()

    print("-----middle1-------")
    [print(x.inputs) for x in middle1.neurons]
    [print(x.outputs) for x in middle1.neurons]
    print("-----middle2-------")
    [print(x.inputs) for x in middle2.neurons]
Beispiel #10
0
 def __init__(self, z_order):
     Layer.__init__(self, z_order)
     self.move_time = time.monotonic()
Beispiel #11
0
from core.network import Network

learning_data = []

tic_tac_map = {'positive': 1, 'negative': 0, 'x': 1, 'o': 2, 'b': 3}

with open('data/training_data/tic-tac-toe.data', newline='') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        learning_data.append({
            'inputs': [tic_tac_map[x] for x in row[0:9]],
            'outputs': [tic_tac_map[row[9]]]
        })

inputs = InputLayer([1] * 9)
middle = Layer(5)
middle2 = Layer(7)
middle3 = Layer(5)
middle4 = Layer(2)
output = OutputLayer([1])

network = Network([inputs, middle, middle2, middle3, middle4, output])

network.connect()

network.load_learning_data(learning_data)
#network.normalize_learning_data()
print("------- learn -------")
network.print_data()

#network.learn(times=100)