From c0a536c49a0d9d522b97360037c3c369ba857d2e Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 20 Oct 2020 19:20:44 +0200 Subject: [PATCH] Optimzed stuff --- rgbAI/lib/ailib/ai.py | 4 +++- rgbAI/main.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rgbAI/lib/ailib/ai.py b/rgbAI/lib/ailib/ai.py index 1f970f3..f47e8d3 100644 --- a/rgbAI/lib/ailib/ai.py +++ b/rgbAI/lib/ailib/ai.py @@ -1,5 +1,6 @@ import numpy as np from copy import deepcopy as copy +import os def sigmoid(x): return 1/(1 + np.exp(-x)) @@ -137,7 +138,7 @@ def mutateProps( inpObj, curCost:float, maxLayer:int, gradient:list ): for layer in range(maxLayer): lr = getLearningRate( curCost, gradient[layer], maxLayer ) - print(lr) + # print(lr) obj.weights[layer] -= lr["weight"] * gradient[layer]["weight"] # mutate the weights obj.bias[layer] -= lr["bias"] * gradient[layer]["bias"] @@ -162,6 +163,7 @@ def learn( inputNum:int, targetCost:float, obj, theta:float, curCost: float=None grads, costW, costB, curCost = gradient( inp, obj, theta, maxLen - 1 ) obj = mutateProps( obj, curCost, maxLen, grads ) # mutate the props for next round + os.system("clear") print(f"Cost: {curCost}") diff --git a/rgbAI/main.py b/rgbAI/main.py index 84b095c..a66903a 100755 --- a/rgbAI/main.py +++ b/rgbAI/main.py @@ -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, 8), ai.genRandomMatrix(8, 8), ai.genRandomMatrix(8, 3) ] # array of matrices of weights + self.weights = [ ai.genRandomMatrix(3, 8), ai.genRandomMatrix(8, 8), ai.genRandomMatrix(8, 8), ai.genRandomMatrix(8, 3) ] # array of matrices of weights # 3 input neurons -> 8 hidden neurons -> 8 hidden neurons -> 3 output neurons # Generate the biases - self.bias = [ ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 3) ] + self.bias = [ ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 3) ] # This doesn't look very good, but it works so... self.learningrate = 0.01 # the learning rate of this ai @@ -29,7 +29,7 @@ class rgb(object): return cost def learn( self ): - ai.learn( 3, 0.0001, self, 0.001 ) + ai.learn( 3, 0.0001, self, 0.000001 ) def think( self, inp:np.array ): print("\n-Input-")