def AddOutLayer(self, cNeurons): layer = ntl.NetLayer() cIn = len(self.layers[len(self.layers) - 1].neurons) + 1 for i in range(cNeurons): layer.addNeuron(cIn) print("Agregando capa de salida...") self.layers.append(layer)
def neuRandom(self, cIn, cLayers, cNeurons): for i in range(cLayers): layer = ntl.NetLayer() self.layers.append(layer) for j in range(0, cNeurons): self.layers[i].addNeuron(cIn + 1) if i > 0: cIn = len(self.layers[i - 1].neurons)
def load(file): #instanciamos la red neuralNet = nn.NeuralNetwork() with open(file) as oFile: #leemos el archivo en formato JSON jsonF = json.load(oFile) #Iteramos por capas y neuronas for layer in jsonF['capas']: nLayer = ntl.NetLayer() for neuron in layer['neuronas']: w = neuron['pesos'] #Añadimos la neurona como arreglos [baias, arregloPesos, g(n), delta) nLayer.neurons.append([1, w, 0, 0]) #Añadimos la capa con las neuronas a la red neuralNet.layers = np.append(neuralNet.layers, nLayer) return neuralNet
def load(file): neuralNet = nn.NeuralNetwork() with open(file) as oFile: jsonF = json.load(oFile) for layer in jsonF['capas']: nLayer = ntl.NetLayer() for neuron in layer['neuronas']: print(neuron['pesos']) w = neuron['pesos'] nLayer.neurons.append([1, w, 0, 0]) neuralNet.layers = np.append(neuralNet.layers, nLayer) for i in range(0, 2): for j in range(0, 2): vector = [i, j] neuralNet.evaluar(vector) neuralNet.printG(vector)
def evaluar(self, vector): ban = 0 before = ntl.NetLayer() for layer in self.layers: for neuron in layer.neurons: x = 0.0 if ban != 0: x = neuron[0] * neuron[1][0] for i in range(len(before.neurons)): x += neuron[1][i + 1] * before.neurons[i][2] else: x = neuron[0] * neuron[1][0] for i in range(len(vector)): x += neuron[1][i + 1] * vector[i] neuron[2] = layer.sigmoide(x) ban = 1 before = layer
def AddHiddenLayer(self, cNeurons, cIn): layer = ntl.NetLayer() for i in range(cNeurons): layer.addNeuron(cIn + 1) print("Agregando Capa oculta...") self.layers.append(layer)