From 3587e223d595d6181b43c0f8799467b331fbf275 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 29 Sep 2020 21:32:28 +0200 Subject: [PATCH] Removed stuff --- rgbAI/lib/func.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/rgbAI/lib/func.py b/rgbAI/lib/func.py index 56b86d6..03724f6 100644 --- a/rgbAI/lib/func.py +++ b/rgbAI/lib/func.py @@ -21,23 +21,25 @@ class AIlib: mat = np.random.rand(x, y) - 0.25 return mat - def think( inp:np.array, weights:list, bias:list, layerIndex: int=0, layers: list=[] ): # recursive thinking, hehe + def think( inp:np.array, weights:list, bias:list, layerIndex: int=0 ): # recursive thinking, hehe maxLayer = len(weights) - 1 weightedLayer = np.dot( inp, weights[layerIndex] ) # dot multiply the input and the weights layer = AIlib.sigmoid( np.add(weightedLayer, bias[layerIndex]) ) # add the biases - layers[layerIndex] = layer # save it to the layer buffer if( layerIndex < maxLayer ): - return AIlib.think( layer, weights, bias, layerIndex + 1, layers ) + return AIlib.think( layer, weights, bias, layerIndex + 1 ) else: out = np.squeeze(np.asarray(layer)) print("-Result-") print(out) print("\n") - return out, layers + return out def gradient( prop, cost:float, inp:np.array, predicted:np.array, correct:np.array ): # Calculate the gradient + # i.e. : W' = W - lr * gradient (respect to W) = W - lr*[ dC / dW[i] ... ] + # So if we change all the weights with i.e. 0.01 = theta, then we can derive the gradient with math and stuff + return gradient @@ -54,12 +56,3 @@ class AIlib: # Cost in respect to weights # Cost in respect to biases - predicted = AIlib.think( inp, obj.weights, obj.bias ) # Think the first result - correct = AIlib.correctFunc( inp ) - cost = AIlib.calcCost( predicted, correct ) # Calculate the cost of the thought result - - inp2 = np.asarray( inp + theta ) # make the new input with `theta` as diff - res2 = AIlib.think( inp2, obj.weights, obj.bias ) # Think the second result - cost2 = AIlib.calcCost( inp2, res2 ) # Calculate the cost - - print("Cost: ", cost1)