示例#1
0
        private void CalculateErrorOut(double[] outPattern)
        {
            BackpropagationLayer outLayer = layers[layers.Count - 1];

            for (int x = 0; x < outPattern.Count(); x++)
            {
                BackpropagationNeuron neuronOut = outLayer.neurons[x];
                //Formula: Erro_saída[j] = (valor_desejado – valor_obtido)* valor_obtido * (1 – (valor_obtido))
                neuronOut.valueError = (outPattern[x] - neuronOut.GetValuePattern()) * neuronOut.GetValuePattern() * (1 - neuronOut.GetValuePattern());
            }
        }
示例#2
0
        private double[] GetDoubleArrayOutput()
        {
            BackpropagationLayer outLayer = layers[layers.Count - 1];

            double[] result = new double[outLayer.neurons.Count()];

            for (int x = 0; x < outLayer.neurons.Count(); x++)
            {
                BackpropagationNeuron neuron = outLayer.neurons[x];
                result[x] = neuron.GetValuePattern();
            }
            return(result);
        }
示例#3
0
        public BackpropagationLayer(int layerSize, BackpropagationLayer fatherLayer)
        {
            neurons = new List <BackpropagationNeuron>();
            for (int x = 0; x < layerSize; x++)
            {
                BackpropagationNeuron neuron = new BackpropagationNeuron();
                neurons.Add(neuron);

                foreach (BackpropagationNeuron fatherNeuron in fatherLayer.neurons)
                {
                    neuron.listConnection.Add(new BackpropagationConnection(fatherNeuron));
                }
            }
        }
示例#4
0
        private void DoBackPropagation(double[] outPattern)
        {
            //CALCULA ERRO NA CAMADA DE SAÍDA!
            CalculateErrorOut(outPattern);

            //Calcula o erro nas camadas intermediárias
            //ErrorA = Output A (1 - Output A)(ErrorB WAB + ErrorC WAC)
            //VEM PROPAGANDO DE TRÁS PARA FRENTE. COMEÇA NA PENÚLTIMA CAMADA E VAI ATÉ A PRIMEIRA
            for (int x = layers.Count - 2; x >= 0; x--)
            {
                BackpropagationLayer layerL = layers[x];
                BackpropagationLayer layerR = layers[x + 1];

                //PARA CADA NEURÔNIO DA CAMADA DA ESQUERDA
                for (int y = 0; y < layerL.neurons.Count; y++)
                {
                    BackpropagationNeuron neuronL = layerL.neurons[y];
                    neuronL.valueError = 0;

                    //CALCULA O ERRO
                    double sum = 0;
                    for (int z = 0; z < layerR.neurons.Count; z++)
                    {
                        //para cada neurônio da camada da direita, pega ele e encontra a conexão entre os 2
                        BackpropagationNeuron neuronR = layerR.neurons[z];
                        for (int c = 0; c < neuronR.listConnection.Count; c++)
                        {
                            BackpropagationConnection connection = neuronR.listConnection[c];
                            if (connection.neuron == neuronL)
                            {
                                //acumula a soma do  (erro do neuronio da direita * peso da ligacao)
                                sum += neuronR.valueError * connection.valueWeight;
                                //e
                                //atualiza peso da conexão
                                //WAB = WAB + (ErrorB x OutputA)
                                connection.valueWeight = connection.valueWeight + (neuronR.valueError * neuronL.valuePattern);
                            }
                        }
                    }
                    //ErrorA = Output A (1 - Output A)(ErrorB WAB + ErrorC WAC)
                    neuronL.valueError = neuronL.valuePattern * (1 - neuronL.valuePattern) * sum;
                }
            }
        }
示例#5
0
        private void CalculateSum(BackpropagationLayer layer)
        {
            for (int x = 0; x < layer.neurons.Count; x++)
            {
                BackpropagationNeuron neuron = layer.neurons[x];

                //CALCULA A SOMA PARA CADA NEURONIO DA CAMADA.
                //PARA ISSO, APURA CADA RELAÇÃO DE SUA CONEXAO (BACKWARD).
                double sum = 0;
                for (int y = 0; y < neuron.listConnection.Count; y++)
                {
                    BackpropagationConnection connection = neuron.listConnection[y];
                    // Formula: (E x*w)
                    sum += (connection.neuron.GetValuePattern() * connection.valueWeight);
                }

                //APLICA A FUNÇÃO DE TRANSFERÊNCIA.
                neuron.SetValuePattern(TransferFunction(sum));
            }
        }
示例#6
0
 public BackpropagationConnection(BackpropagationNeuron neuron)
 {
     this.neuron      = neuron;
     this.valueWeight = (Util.Randomizer.NextDouble(1) - 0.5); //RANDON VALUE BETWEEN [-0.5 AND +0.5]
     this.deltaWeight = 0;
 }