コード例 #1
0
ファイル: NetTrainer.cs プロジェクト: grozaserban/NeuralNet
        public static int TrainAdaptiveWithConfidenceAndPerformance(this NeuralNet net, List <List <double> > inputs, List <List <double> > expectedResults, double performanceThreshold, int iterationLimit, Reading testData)
        {
            Contract.Equals(inputs.Count, expectedResults.Count);
            bool          trained;
            int           iteration = 0;
            double        performanceOnOneBefore = -1;
            double        performance            = -1;
            List <double> performances;

            do
            {
                performances = new List <double>(inputs.Count);
                var setsTrained = inputs.Count;
                trained = true;
                performanceOnOneBefore = net.CalculatePerformance();
                for (int i = 0; i < inputs.Count; i++)
                {
                    performances.Add(net.CalculatePerformance());
                    net.ChangeData(inputs[i], expectedResults[i]);
                    var setTrained = performances[i] >= performanceThreshold;
                    trained &= setTrained;
                    if (setTrained)
                    {
                        setsTrained--;
                    }
                    net.UpdateAdjustment();
                }
                net.AdjustCumulatedWeights();
                net.ResetValues();
                net.ResetDerrivates();
                performance = net.CalculatePerformance();
                var performanceIncreased = performance > performanceOnOneBefore;
                var performanceIncreaseUnderThreshold = performance - performanceOnOneBefore < 0.0000000001;
                if (performanceIncreased && performanceIncreaseUnderThreshold) //+2
                {
                    Link.RenewalFactor = 0.000001;
                }
                else
                {
                    Link.RenewalFactor = 0;
                }

                iteration++;
                if (iteration % 1000 == 0)
                {
                    Debug.WriteLine("Iteration: " + iteration++ + " performance:" + net.CalculatePerformance() + "Performance average" + performances.Sum() / performances.Count + " Sets untrained:" + setsTrained);
                    ComputeResultsAndConfidence(iteration, net, testData);
                }

                if (iteration % iterationLimit == 0)
                {
                    Link.RenewalFactor = 1;
                }
            }while (!trained);
            Debug.WriteLine("Iteration: " + iteration);
            return(iteration);
        }
コード例 #2
0
ファイル: NetTrainer.cs プロジェクト: grozaserban/NeuralNet
        private static bool TrainIteration(this NeuralNet net, double performanceThreshold)
        {
            var performanceBeforeIteration = net.CalculatePerformance();

            if (!(performanceBeforeIteration > performanceThreshold / 100))
            {
                net.Learn();
            }

            var performance = net.CalculatePerformance();

            return(performanceBeforeIteration >= performanceThreshold);
        }
コード例 #3
0
ファイル: NetTrainer.cs プロジェクト: grozaserban/NeuralNet
        public static int TrainAdaptive(this NeuralNet net, List <List <double> > inputs, List <List <double> > expectedResults, double performanceThreshold)
        {
            Contract.Equals(inputs.Count, expectedResults.Count);
            bool   trained;
            int    iteration         = 0;
            double performanceBefore = -1;
            double performance       = -1;

            do
            {
                var setsTrained = inputs.Count;
                trained           = true;
                performanceBefore = performance;
                for (int i = 0; i < inputs.Count; i++)
                {
                    net.ChangeData(inputs[i], expectedResults[i]);
                    var setTrained = net.CalculatePerformance() >= performanceThreshold;
                    trained &= setTrained;
                    if (setTrained)
                    {
                        setsTrained--;
                    }
                    net.UpdateAdjustment();
                }
                net.AdjustCumulatedWeights();
                net.ResetValues();
                net.ResetDerrivates();
                performance = net.CalculatePerformance();
                if (performance - performanceBefore < 0.0000001)
                {
                    Link.RenewalFactor = 0.00003;
                }
                else
                {
                    Link.RenewalFactor = 0.00000000003;
                }

                if (iteration % 1000 == 0)
                {
                    Debug.WriteLine("Iteration: " + iteration++ + " performance:" + net.CalculatePerformance() + "Sets trained:" + setsTrained);
                }
                iteration++;
            }while (!trained);
            Debug.WriteLine("Iteration: " + iteration);
            return(iteration);
        }