From bd7c52c927808953eb4234a701dea667eaed2c12 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 20 Oct 2020 15:54:34 +0200 Subject: [PATCH] Feed the AI random inputs per learn iteration --- rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc | Bin 4648 -> 4620 bytes rgbAI/lib/ailib/ai.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc b/rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc index fa2344de7cd910272901498e9be0dfed05e42a35..20dfc6028f3a104ea33c3af99441dabdcdfbbe43 100644 GIT binary patch delta 192 zcmZ3X(xbu`%FD~e00d88_r=SKZ{(ZB=f@7@IsGsK%y*g`N=~37L2}=z4=2~nH3n7 zm?tmgcU7rjDdMSNsbS1!DM~A0Sio4qkj1osIfb!?VIk8(#uO$=hFaFid;*S)43h%{ a4)9L_xkd;`FmUoPN-%Af7vx}MFN`3^oiv)hq;5Gf6VQR2K?N z=H^#s^qZ{DAIi$8$7sMbxs%^jrG#MtV+lhR(*ouc#u|o&ObZ!PfSN!~DN?CnsbS1! lDN39CiQkb?VzP&egf*g#DoB*StF6#gQ diff --git a/rgbAI/lib/ailib/ai.py b/rgbAI/lib/ailib/ai.py index afa9348..cd3d0cb 100644 --- a/rgbAI/lib/ailib/ai.py +++ b/rgbAI/lib/ailib/ai.py @@ -137,8 +137,11 @@ def mutateProps( inpObj, curCost:float, maxLen:int, gradient:list ): obj = copy(inpObj) for i in range(maxLen): - obj.weights[i] -= getLearningRate( curCost, gradient[i]["weight"], maxLen ) * gradient[i]["weight"] # mutate the weights - obj.bias[i] -= getLearningRate( curCost, gradient[i]["weight"], maxLen ) * gradient[i]["bias"] + # obj.weights[i] -= getLearningRate( curCost, gradient[i]["weight"], maxLen ) * gradient[i]["weight"] # mutate the weights + # obj.bias[i] -= getLearningRate( curCost, gradient[i]["weight"], maxLen ) * gradient[i]["bias"] + obj.weights[i] -= obj.learningrate * gradient[i]["weight"] # mutate the weights + obj.bias[i] -= obj.learningrate * gradient[i]["bias"] + return obj @@ -150,9 +153,10 @@ def learn( inputNum:int, targetCost:float, obj, theta:float, curCost: float=None # i.e. : W' = W - lr * gradient (respect to W in layer i) = 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 - inp = np.asarray(np.random.rand( 1, inputNum ))[0] # create a random learning sample - + while( not curCost or curCost > targetCost ): # targetCost is the target for the cost function + inp = np.asarray(np.random.rand( 1, inputNum ))[0] # create a random learning sample + maxLen = len(obj.bias) grads, costW, costB, curCost = gradient( inp, obj, theta, maxLen - 1 )