From 63ae5b65ca34434eddca94df2ac770ac8201a5dd Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 28 Aug 2020 19:58:54 +0200 Subject: [PATCH] Imporvements to the AIs init function --- lib/__pycache__/func.cpython-38.pyc | Bin 436 -> 787 bytes lib/func.py | 13 +++++++------ main.py | 22 +++++++++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/__pycache__/func.cpython-38.pyc b/lib/__pycache__/func.cpython-38.pyc index f29ca806b835279723ed3fd856cd408cb565e21c..bee87e9649c7dd10bd174dd099ad732b4555e4cc 100644 GIT binary patch literal 787 zcmZva&2H2%5P-*avKzWx5K;>&JV7MXoVX#>3Iy6iBLw1-iZ_-cs@_^bv)h!l=S^X{$K!ibl4SvhZ9`w3sedes~}?^ zL2)J4pu|s}amBts9BeQSX+e5dw)L;jtFcxARVcoOOemoO+yfozP=&v^8mQqq$ObCH z8y~swbW)Y)1!8T5>=4>4t4Nt(#H> z)SIIM_I>OTkN-ygL8VlW`V5T~!XA<4UW+5R5Hz`TLzh{alqGBriNFF8yxprIhTN!V ztVP}r$V85Nj;B4xPV|;r8kA$p!n2}HLiU#GF&;X&V%K~HD|W+?hNZEvl#mT7 zh`NnXIZ>L<66a2H`iPcZZ|OBOx0YNHi$o;6FBVy7=JjmppWTZlX-=vg$i`w81_o9J4kiv}0PjO6fdBvi diff --git a/lib/func.py b/lib/func.py index 3d1c1d2..4e3f7e0 100644 --- a/lib/func.py +++ b/lib/func.py @@ -1,10 +1,11 @@ import numpy as np -def sigmoid(x): - return 1/(1 + np.exp(-x)) +class AIlib: + def sigmoid(x): + return 1/(1 + np.exp(-x)) -def correctFunc(rgb): # generates the correct answer for the AI - return ( rgb[2], rgb[1], rgb[0] ) # basically invert the rgb values + def correctFunc(rgb): # generates the correct answer for the AI + return ( rgb[2], rgb[1], rgb[0] ) # basically invert the rgb values -def genRandomMatrix( x:int, y:int ): - return np.random.rand(x, y) + def genRandomMatrix( x:int, y:int ): # generate a matrix with x, y dimensions with random values from 0-1 in it + return np.random.rand(x, y) diff --git a/main.py b/main.py index f20d8f0..379363c 100755 --- a/main.py +++ b/main.py @@ -1,14 +1,26 @@ #!/usr/bin/env python -from lib.func import * +from lib.func import AIlib as ai class rgb(object): - def __init__(self): - self.weights = 1 + def __init__(self, loadedWeights = None, loadedBias = None): - def think(self, inputMatrix): - print("thonk: " + str( sigmoid(self.weights) )) + if( not loadedWeights or not loadedBias ): + self.weights = [ ai.genRandomMatrix(3, 4), ai.genRandomMatrix(4, 4), ai.genRandomMatrix(4, 3) ] # array of matrices of weights + # 3 input neurons -> 4 hidden neurons -> 4 hidden neurons -> 3 output neurons + + # Will be needing biases too + self.bias = [ ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 3) ] + # This doesn't look very good, but it works so... + # This is all we need + else: # if we want to load our progress from before then this would do it + print("Loading neural net...") + self.weights = loadedWeights + self.bias = loadedBias + def think(self, inputMatrix): + print(self.weights) + print(self.bias) def init(): # init func bot = rgb()