Fixed matrix bug

pull/1/head
E. Almqvist 4 years ago
parent ba5662b371
commit 3cdd15e8fa
  1. 9
      lib/func.py
  2. 8
      main.py

@ -30,11 +30,16 @@ class AIlib:
print("Neural Network Error: Length of weights and bias are not equal.")
print("Weights: ${maxLayer}, Bias: ${biasLen}")
exit()
try:
weightedInput = np.dot( weights[layerIndex], inp ) # dot multiply the input and the weights
layer = np.add( weightedInput, bias[layerIndex] ) # add the biases
if( layerIndex >= maxLayer ):
return layer
else:
think( layer, weights, bias, layerIndex + 1 )
print("New think " + str(layerIndex + 1))
AIlib.think( layer, weights, bias, layerIndex + 1 )
except ValueError as err:
print("\n---------")
print( "Error: " + str(err) )
print( "Layer index: " + str(layerIndex) )

@ -7,11 +7,11 @@ class rgb(object):
if( not loadedWeights or not loadedBias ): # if one is null (None) then just generate new ones
print("Generating weights and biases...")
self.weights = [ ai.genRandomMatrix(3, 4), ai.genRandomMatrix(4, 4), ai.genRandomMatrix(4, 3) ] # array of matrices of weights
self.weights = [ ai.genRandomMatrix(4, 3), ai.genRandomMatrix(4, 4), ai.genRandomMatrix(3, 4) ] # array of matrices of weights
# 3 input neurons -> 4 hidden neurons -> 4 hidden neurons -> 3 output neurons
# Generate the biases
self.bias = [ ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 3) ]
self.bias = [ ai.genRandomMatrix(4, 1), ai.genRandomMatrix(4, 1), ai.genRandomMatrix(3, 1) ]
# This doesn't look very good, but it works so...
else: # if we want to load our progress from before then this would do it
@ -22,8 +22,8 @@ class rgb(object):
print("learn")
def think(self, inp:np.array):
res = ai.think( np.asmatrix(inp), self.weights, self.bias )
print(res)
res = ai.think( inp, self.weights, self.bias )
print( "Result: " + str(res) )
# print(self.weights)
# print(self.bias)

Loading…
Cancel
Save