From e05ad561ea20e3c7e3813eeb5f905026cee15c58 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 20 Oct 2020 16:30:31 +0200 Subject: [PATCH] Added experimental lr function and more bugs --- rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc | Bin 4620 -> 4672 bytes rgbAI/lib/ailib/ai.py | 30 +++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc b/rgbAI/lib/ailib/__pycache__/ai.cpython-38.pyc index 20dfc6028f3a104ea33c3af99441dabdcdfbbe43..da4dd760a2c9ad7ca757faabf478a110b8bfb1cb 100644 GIT binary patch delta 1187 zcmZuw%}*0S6yMpM*=}pUfFhItCZ-5$`6xy{T0R1yRulPBG$Bn0LAGhyloqCIqGT(F za+7Gt#AuYngJ(}BUc8ui_8(ZU96jpQ_}-MS7^mrPW`FbMz2BSn<{9kwBHxD~-5CFMGl}~R54cK!fFzmvaMw#_<#`6I%XV|TQsq5p zF^wR-MsU@NfMNL*fEl_NL>%}&2j-BbC+fx0rEeKzcmlvR@_fT8W(KTR^?wZG>|1_)Di>1L&BbNtv;0Zs=KKm7ff8g=N3!aINk zH8Lx`R48wh@-8h`_?F8`mHcqRWc&`8NH19rMxM`=v$|!?q3=Oip7lU`hk@RSpBTia z@_BTsog5S|15vR+y?YOUwUj(@)X4cvj?|iFD~?(xX=N=@qc(A9oe;%V9mOGa)zK_9 zsyKA=BBM2!oo+{40r`tO4Zis;1gr$a#xl5Un-|JKP7B>^+0+Y8XIK4PyM! z87glk5tT0i2j^2Tae3$R{wSKB3=hos$Ffy-0YJV|CsKMN4XegLK5;aMMHP#HShcRz zbX#+DOwFNtMd~o7z=kfj&kQ5VxS}bOU{Yjf7MOp-0#>IMJ7KJ!sV!beTj#PxWeZ{+ zd;vjrsk|0XRxgydmmU?n{>iV=qyu1`RZCoCL!HqB_^1W}6k@1;5&^tQVvH|~=b=tr zwq#0t3>~NNe)uxNSv1qf?;&v?;k88{ez6kkJ&z}>QPX!~o`qqZc3r}QmWzk$(DnLsvi!V*{%o7PVhyDUE-rySm delta 1166 zcmZuwTTc@~6yDk0+1|E55rozdj48@mq?mvdD2j6N1qx_<*~FOIX-LtQGP_OGY~=xB zd@v+9ny4Z1!JnYv;RU=trTF`D=fjOWZ2B+=Q-w`aa{=GP27%Rdv@Z%=J7(yE10>U`Lc?8%Mo(oTc zXlZ;*+zC5lIphZsq?_=6-AtiA@PN{UI2M^8`8P`ua#`-D!20w-nQu6J04=5wq}MK# zx)Cre&jVQPM}vsn===B;r1e(zVm0>3K!#^U%1oV>;=YgEjS!-b3A(*lhTYPNm z+L~)pPhVF(N)^m+UGp@LCZWEh(xv1SP01sx|D%UG5A>TIo(@H5g&=>KI_2_G$x9;( zT7s}aRfcU;YW3yY>zL`*kyL{l)r*GVLx_On$Eppt=$2RbM%{S~gd?9N9G|J3B&RgK z44kF=Ves2<3yrEDb&Gth?Ban3FA1Ac!c#mL=mFaCwBvJr9z^NFr*&Sbx$*?8D95wr zs|fO0$}23Ji=7WTydXk}Gvt}bCT7}GKCLyX_4^#d@SJ#!B`%i;1>U`*er h7F}MsC-0!Ivr5U8XXxv9E0FiH_?1|sMrW+k`~zym)!_gD diff --git a/rgbAI/lib/ailib/ai.py b/rgbAI/lib/ailib/ai.py index cd3d0cb..f6288a2 100644 --- a/rgbAI/lib/ailib/ai.py +++ b/rgbAI/lib/ailib/ai.py @@ -119,28 +119,34 @@ def gradient( inp:np.array, obj, theta:float, maxLayer:int, layerIndex: int=0, g def calculateSteepness( cost:float, gradient:np.matrix ): gradLen = np.linalg.norm( gradient ) # basically calculate the hessian but transform the gradient into a scalar (its length) ddCost = cost / gradLen + out = np.log10(ddCost) - return np.arcsin( ddCost ) / 180 # the gradients "angle" cannot become steeper than 180. + return out -def getLearningRate( cost:float, gradient:dict, maxLen:int ): +def getLearningRate( cost:float, gradient:np.matrix, maxLen:int ): learningrate = { - "weight": [], - "bias": [] + "weight": [None] * maxLen, + "bias": [None] * maxLen } for i in range(maxLen): - learningrate["weights"][i] = calculateSteepness( cost, gradient["weight"][i] ) - learningrate["bias"][i] = calculateSteepness( cost, gradient["bias"][i] ) + learningrate["weight"][i] = calculateSteepness( cost, gradient ) + learningrate["bias"][i] = calculateSteepness( cost, gradient ) + return learningrate -def mutateProps( inpObj, curCost:float, maxLen:int, gradient:list ): + +def mutateProps( inpObj, curCost:float, maxLayer: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] -= obj.learningrate * gradient[i]["weight"] # mutate the weights - obj.bias[i] -= obj.learningrate * gradient[i]["bias"] + for layer in range(maxLayer): + lr = getLearningRate( curCost, gradient[layer]["weight"], maxLayer ) + print(lr) + + obj.weights[layer] -= lr["weight"] * gradient[layer]["weight"] # mutate the weights + obj.bias[layer] -= lr["bias"] * gradient[layer]["bias"] + # obj.weights[i] -= obj.learningrate * gradient[i]["weight"] # mutate the weights + # obj.bias[i] -= obj.learningrate * gradient[i]["bias"] return obj