Käänsin itse tehdyn neural network:in JavaScript:stä Python:iin:
from random import *
import math
class NN:
def __init__(self, I, Hx, Hy, O):
self.weights = [];
self.O = O;
for x in range(I * (Hx * Hy) * O):
self.weights.insert(x, uniform(-1.5, 1.5));
def mutate(self, R):
for z in range(len(self.weights)):
self.weights[z] += uniform(-R, R)
def calc(self, I):
output = [];
for x in range(self.O):
SummedValue = 0;
Add = 0;
for y in I:
Add += y
Add = float(math.sqrt(Add));
SummedValue = Add;
for z in self.weights:
SummedValue *= z;
output.insert(x, (SummedValue*2));
return output;
nn = NN(2, 3, 3, 1);
a = 2;
b = 3;
print(nn.calc([a,b]));
Ei kommentteja:
Lähetä kommentti