-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrainTrainer.py
More file actions
33 lines (25 loc) · 804 Bytes
/
BrainTrainer.py
File metadata and controls
33 lines (25 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from NeuralNetwork.NeuralNetwork import NeuralNetwork
global cbrain
cbrain = None
def get_new_brain(sensor_count):
global cbrain
if cbrain is None:
brain = NeuralNetwork([sensor_count, 2, 2])
database = []
for line in open('memory.txt','r'):
line = [float(x) for x in line.split()]
database.append((line[:-2], line[-2:]))
for _ in range(15):
err = brain.teach_by_sample(database)
print(err)
cbrain = brain
return cbrain
def algorythm(sensors):
forward = 1.0 - (sum(sensors) / len(sensors))
half_len = len(sensors) / 2
l = sum(sensors[:half_len])/half_len
r = sum(sensors[half_len:])/half_len
if l==0 and r==0:
l=0.005
rotate = (l-r)*2.0
return forward, rotate