Пример #1
0
        internal double[] Evaluate(DataPoint p)
        {
            foreach (Neuron n in hiddenNeurons)
            {
                n.Clear();
            }

            foreach (Neuron n in outputNeurons)
            {
                n.Clear();
            }

            double[] hiddenOutputs = new double[nbHidden];
            for (int i = 0; i < nbHidden; i++)
            {
                hiddenOutputs[i] = hiddenNeurons[i].Evaluate(p);
            }
            double[] outputs = new double[nbOutput];
            for (int outputNb = 0; outputNb < nbOutput; outputNb++)
            {
                outputs[outputNb] = outputNeurons[outputNb].Evaluate(hiddenOutputs);
            }

            return outputs;
        }
Пример #2
0
        internal void AdjustWeights(DataPoint p, double learningRate)
        {
            // Delta sortie
            double[] outputDelta = new double[nbOutput];
            for (int i = 0; i < nbOutput; i++)
            {
                double output = outputNeurons[i].Output;
                double expectedOutput = p.Outputs[i];
                outputDelta[i] = output * (1 - output) * (expectedOutput - output);
            }

            //Delta neuron cachés

            double[] hiddenDeltas = new double[nbHidden];
            for (int i = 0; i < nbHidden; i++)
            {
                double hiddenOutput = hiddenNeurons[i].Output;
                double sum = 0.0;
                for (int j = 0; j < nbOutput; j++)
                {
                    sum += outputDelta[j] * outputNeurons[j].Weight(i);
                }
                hiddenDeltas[i] = hiddenOutput * (1 - hiddenOutput) * sum;
            }

            double value;
            for (int i = 0; i < nbOutput; i++)
            {
                Neuron outputNeuron = outputNeurons[i];
                for (int j = 0; j < nbHidden; j++)
                {
                    value = outputNeuron.Weight(j) + learningRate * outputDelta[i] * hiddenNeurons[j].Output;
                    outputNeuron.AdjustWeight(j, value);
                }
                value = outputNeuron.Weight(nbHidden) + learningRate * outputDelta[i] * 1.0;
                outputNeuron.AdjustWeight(nbHidden, value);
            }

            // ajustement poids
            for (int i = 0; i < nbHidden; i++)
            {
                Neuron hiddenNeuron = hiddenNeurons[i];
                
                for (int j = 0; j < nbInputs; j++)
                {
                    value = hiddenNeuron.Weight(j) + learningRate * hiddenDeltas[i] * p.Inputs[j];
                    hiddenNeuron.AdjustWeight(j, value);
                }
                value = hiddenNeuron.Weight(nbInputs) + learningRate * hiddenDeltas[i] * 1.0;
                hiddenNeuron.AdjustWeight(nbInputs, value);
            }
        }
Пример #3
0
 internal double Evaluate(DataPoint point)
 {
     double[] nbInput = point.Inputs;
     return Evaluate(nbInput);
 }