public bool StopIterations(NeuralNetwork neuralNetwork, ProblemDescriptionModel neuralNetworkTrainModel)
        {
            var trainSetCount      = Convert.ToInt32(Math.Floor(neuralNetworkTrainModel.ValuesCount * .66));
            var validationSetCount = Convert.ToInt32(Math.Floor((neuralNetworkTrainModel.ValuesCount - trainSetCount) * .66));

            var innerLastOutputDeviation = 0d;

            for (var i = trainSetCount; i < trainSetCount + validationSetCount; i++)
            {
                _feedForward.Compute(neuralNetwork, neuralNetworkTrainModel.GetInputValues(i));
                innerLastOutputDeviation = Math.Max(innerLastOutputDeviation, _ouputDeviation.Compute(neuralNetwork, neuralNetworkTrainModel.GetOutputValues(i)));
            }
            //innerLastOutputDeviation /= validationSetCount;

            //check deviation to break training
            neuralNetwork.NeuralNetworkError = innerLastOutputDeviation;

            //check to stop cycles with this setup
            if (Math.Round(stopIterations_lasMaxtOutputDeviation, neuralNetwork.Divisor.ToString().Length)
                <= Math.Round(innerLastOutputDeviation, neuralNetwork.Divisor.ToString().Length) ||                                                  //if important digits stopped correcting, stop iterations
                innerLastOutputDeviation < neuralNetworkTrainModel.AcceptedError ||                                                                  //if we are in the accepted error range, stop iterations
                Math.Abs(Math.Abs(stopIterations_lasMaxtOutputDeviation) - Math.Abs(innerLastOutputDeviation)) < 1 / (neuralNetwork.Divisor * 1000)) //if the correction is too small stop iterations
            {
                stopIterations_lasMaxtOutputDeviation = double.MaxValue;
                return(true);
            }
            stopIterations_lasMaxtOutputDeviation = innerLastOutputDeviation;

            return(false);
        }
Exemple #2
0
        public void Test(NeuralNetwork neuralNetwork, ProblemDescriptionModel neuralNetworkTrainModel)
        {
            var trainSetCount      = Convert.ToInt32(Math.Floor(neuralNetworkTrainModel.ValuesCount * .66));
            var validationSetCount = Convert.ToInt32(Math.Floor((neuralNetworkTrainModel.ValuesCount - trainSetCount) * .66));
            var testSet            = Convert.ToInt32(neuralNetworkTrainModel.ValuesCount - trainSetCount - validationSetCount);

            var testError = 0d;

            for (var i = trainSetCount + validationSetCount; i < trainSetCount + validationSetCount + testSet; i++)
            {
                _feedForward.Compute(neuralNetwork, neuralNetworkTrainModel.GetInputValues(i));
                testError = Math.Max(testError, _ouputDeviation.Compute(neuralNetwork, neuralNetworkTrainModel.GetOutputValues(i)));
            }
            neuralNetwork.NeuralNetworkError = testError;// / testSet;//update with test error
        }