From 4942feae8b9b3456af48dd10a3789d193b591c35 Mon Sep 17 00:00:00 2001 From: eynard Date: Wed, 15 Dec 2021 22:18:03 +0100 Subject: [PATCH] reglage de bugs --- sobek/network.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sobek/network.py b/sobek/network.py index c188b5d..8f2714d 100755 --- a/sobek/network.py +++ b/sobek/network.py @@ -35,16 +35,19 @@ class network: # raise TypeError("The input vector must contain floats!") if (__storeValues): - self.activations = [] - self.outputs = [] + self.activations = np.array([]) + self.outputs = np.array([]) for layerWeights, bias in zip(self.__weights, self.__biases): _input = np.matmul(_input, layerWeights) _input = np.add(_input, bias) if (__storeValues): - self.activations.append(_input) - np.insert(self.activations, 0, bias) + print("-------------------") + print(bias) + print("-------------------") + self.activations = np.append(self.activations, _input) + self.activations[len(self.activations)-1] = np.insert(self.activations[len(self.activations)-1], 0, bias) #reLu application with np.nditer(_input, op_flags=['readwrite'], flags=['refs_ok']) as layer: @@ -53,8 +56,8 @@ class network: #On peut comparer la performance si on recalcul plus tard if (__storeValues): - self.outputs.append(_input) - np.insert(self.outputs, 0, 1) + self.outputs = np.append(self.outputs, _input) + self.outputs[len(self.outputs)-1] = np.insert(self.outputs[len(self.outputs)-1], 0, 1) return _input @@ -63,9 +66,10 @@ class network: for _input, desiredOutput in zip(inputs, desiredOutputs): self.__output = self.process(_input, True) self.__desiredOutput = desiredOutput - for layerNumber in range(len(ErrorSums)): + for layerNumber in range(len(ErrorSums)-1, -1, -1): ErrorSums[layerNumber][0] += self.__partialDerivative(layerNumber, 0) for neuronNumber in range(1, len(ErrorSums[layerNumber])): + print("layer : " + str(layerNumber) + " neuron : " + str(neuronNumber)) ErrorSums[layerNumber][neuronNumber] += self.__partialDerivative(layerNumber, neuronNumber) for i in range(len(ErrorSums)): for j in range(len(ErrorSums[i])): @@ -74,9 +78,10 @@ class network: def __Error(self, layer, neuron): - return self.__ErrorFinalLayer(neuron) if (layer == len(self.__weights)) else self.__ErrorHiddenLayer(layer, neuron) + return self.__ErrorFinalLayer(neuron) if (layer == len(self.__weights)-1) else self.__ErrorHiddenLayer(layer, neuron) def __ErrorFinalLayer(self, neuron): + print(self.activations) return network.__reLu(self.activations[len(self.activations)-1][neuron], True) * (self.__output[neuron] - self.__desiredOutput[neuron]) def __ErrorHiddenLayer(self, layer, neuron):