Added instance compairing for bias and weights

pull/1/head
E. Almqvist 4 years ago
parent 3c9bffd797
commit 0a754de2e9
  1. 24
      rgbAI/lib/func.py

@ -53,18 +53,22 @@ class AIlib:
dCost = cost2 - cost1
return dCost
def compareInstance( obj, theta, layerIndex, neuronIndex_X=0, neuronIndex_Y=0 ):
# Create new instances of the object
obj2_w = copy(obj) # annoying way to create a new instance of the object
obj2_b = copy(obj)
def compareInstanceWeight( obj, theta, layerIndex, neuronIndex_X=0, neuronIndex_Y=0 ):
# Create new a instance of the object
obj2 = copy(obj) # annoying way to create a new instance of the object
obj2_w.weights[layerIndex][neuronIndex_X][neuronIndex_Y] += theta # mutate the second objects neuron
dCost_weight = AIlib.compareAIobjects( obj, obj2_w ) # compare the two and get the dCost with respect to the weights
obj2.weights[layerIndex][neuronIndex_X][neuronIndex_Y] += theta # mutate the second objects neuron
dCost = AIlib.compareAIobjects( obj, obj2 ) # compare the two and get the dCost with respect to the weights
obj2_b.bias[layerIndex][neuronIndex_X][neuronIndex_Y] += theta # do the same thing for the bias
dCost_bias = AIlib.compareAIobjects( obj, obj2_b )
return dCost
def compareInstanceBias( obj, theta, layerIndex, biasIndex ):
obj2 = copy(obj)
obj2.bias[layerIndex][biasIndex] += theta # do the same thing for the bias
dCost = AIlib.compareAIobjects( obj, obj2 )
return dCost_weight, dCost_bias
return dCost
def getChangeInCost( obj, theta, layerIndex ):
mirrorObj = copy(obj)
@ -73,6 +77,8 @@ class AIlib:
mirrorObj.weights[layerIndex].fill(None)
mirrorObj.bias[layerIndex].fill(None)
def gradient( inp:np.array, obj, theta:float, maxLayer:int, layerIndex: int=0, grads=None, obj1=None, obj2=None ): # Calculate the gradient for that prop
# Check if grads exists, if not create the buffer
if( not grads ):

Loading…
Cancel
Save