Ejemplo n.º 1
0
        public void Train(double[] input, double[] real)
        {
            var output = Calculate(input);

            if (output.Length != real.Length)
            {
                throw new Exception("[NeuralNetwork.Train] output.Length != real.Length.");
            }

            var loss = _lossFunction.DifferentialExecute(output, real);

            Layers.Last().CalculateLoss(loss);

            for (int i = Layers.Count - 2; i >= 0; i--)
            {
                Layers[i].CalculateLoss(Layers[i + 1]);
            }

            for (int i = Layers.Count - 1; i > 0; i--)
            {
                Layers[i].Train(Layers[i - 1], _learnRate);
            }
        }