Beispiel #1
0
        public void Train(TrainData[] data, int maxEpoch = 50000, int hiddenLayersCount = 1, double e = 0.7, double a = 0.3)
        {
            PrepareData(data, hiddenLayersCount);

            double mse = 0;

            for (int i = 0; i < maxEpoch; i++)
            {
                foreach (TrainData dataItem in data)
                {
                    Calculate(dataItem.Input);
                    _outputLayer.CalcSigma(dataItem.Output);

                    // Calc sigma and update weights for other layers
                    for (int j = _layers.Length - 2; j >= 0; j--)
                    {
                        _layers[j].UpdateWeights(e, a);
                    }
                }
            }

            // calc mse
            foreach (TrainData dataItem in data)
            {
                Calculate(dataItem.Input);
                mse += _outputLayer.GetMse(dataItem.Output);
            }

            mse /= data.Length;

            Console.WriteLine($"mse: {mse}");
        }