Exemplo n.º 1
0
        public Perceptron Optimize() {
            Settings.Instance.UseCustomLearningRate = true;

            data = TrainingSet.Load(Settings.Instance.DataDirectoryPath);
            tests = TrainingSet.Load(Settings.Instance.TestsDirectoryPath);

            Initialize();

            Evaluation();

            string info = -1 + " > best: " + population.First().Instance.Inspect() + "; " + population.First().LearningRate + "\n";
            Console.WriteLine(info);

            for (int i = 0; i < Settings.Instance.EvolutionEpochs; i++) {
                Selection();
                Crossover();
                Mutation();
                Evaluation();

                population = population.OrderBy(c => c.Unfitness).ToArray();

                info = i + " > best: " + population.First().Instance.Inspect() + "; " + population.First().LearningRate + "\n";

                Console.WriteLine(info);
            }

            return population.First().Instance;
        }
Exemplo n.º 2
0
        public double Learn(TrainingSet trainingSet, bool verbose = true) {
            if (Settings.Instance.UseCustomLearningRate)
                LearningRate = Settings.Instance.LearningRate;
            else
                LearningRate = 1.0 / trainingSet.Size();

            double maxError = 0;

            for (int step = 0; step < Settings.Instance.MaxLearningSteps; step++) {
                maxError = 0;

                foreach (Example example in trainingSet)
                    maxError = Math.Max(maxError, LearnExample(example));

                if (verbose)
                    Engine.Output.WriteLine(step + ": " + maxError);

                if (maxError <= Settings.Instance.MaxError)
                    break;

                trainingSet.Shuffle(random);
            }

            return maxError;
        }
Exemplo n.º 3
0
        public void Evaluate(TrainingSet data, TrainingSet tests) {
            Instantiate();

            Settings.Instance.LearningRate = LearningRate;

            double dataError = Instance.Learn(data, false);
            double testsError = Instance.Test(data);

            const double alpha = 0.75;
            Unfitness = alpha * dataError + (1.0 - alpha) * testsError;
        }
Exemplo n.º 4
0
        public double Test(TrainingSet trainingSet) {
            if (Settings.Instance.UseCustomLearningRate)
                LearningRate = Settings.Instance.LearningRate;
            else
                LearningRate = 1.0 / trainingSet.Size();

            double maxError = 0;

            foreach (Example example in trainingSet)
                maxError = Math.Max(maxError, TestExample(example));

            return maxError;
        }
Exemplo n.º 5
0
        public double Test(TrainingSet trainingSet)
        {
            if (Settings.Instance.UseCustomLearningRate)
            {
                LearningRate = Settings.Instance.LearningRate;
            }
            else
            {
                LearningRate = 1.0 / trainingSet.Size();
            }

            double maxError = 0;

            foreach (Example example in trainingSet)
            {
                maxError = Math.Max(maxError, TestExample(example));
            }

            return(maxError);
        }
Exemplo n.º 6
0
        public double Learn(TrainingSet trainingSet, bool verbose = true)
        {
            if (Settings.Instance.UseCustomLearningRate)
            {
                LearningRate = Settings.Instance.LearningRate;
            }
            else
            {
                LearningRate = 1.0 / trainingSet.Size();
            }

            double maxError = 0;

            for (int step = 0; step < Settings.Instance.MaxLearningSteps; step++)
            {
                maxError = 0;

                foreach (Example example in trainingSet)
                {
                    maxError = Math.Max(maxError, LearnExample(example));
                }

                if (verbose)
                {
                    Engine.Output.WriteLine(step + ": " + maxError);
                }

                if (maxError <= Settings.Instance.MaxError)
                {
                    break;
                }

                trainingSet.Shuffle(random);
            }

            return(maxError);
        }