Exemplo n.º 1
0
 private static void AddPopulationSizeExperiment(ExperimentSet newSet, int populationSize)
 {
     var newExperiment = new Experiment();
     newSet.Experiments.Add(newExperiment);
     newExperiment.PopulationSize = populationSize;
     newExperiment.Label = "Population Size: " + populationSize;
 }
Exemplo n.º 2
0
 private static void AddMutationPercentExperiment(ExperimentSet newSet, double mutationPercent)
 {
     var newExperiment = new Experiment();
     newSet.Experiments.Add(newExperiment);
     newExperiment.PercentToMutate = mutationPercent;
     newExperiment.Label = "Mutation Percent: " + mutationPercent;
 }
Exemplo n.º 3
0
 private static void AddCrossoverPercentExperiment(ExperimentSet newSet, double crossoverPercent)
 {
     var newExperiment = new Experiment();
     newSet.Experiments.Add(newExperiment);
     newExperiment.PercentToCrossover = crossoverPercent;
     newExperiment.Label = "Crossover Percent: " + crossoverPercent;
 }
Exemplo n.º 4
0
 private static void AddCrossoverMethodExperiment(ExperimentSet newSet, ICrossoverMethod crossoverMethod, string title)
 {
     var newExperiment = new Experiment();
     newSet.Experiments.Add(newExperiment);
     newExperiment.CrossoverMethod = crossoverMethod;
     newExperiment.Label = "Crossover Method: " + title;
 }
Exemplo n.º 5
0
 private static void AddCrossoverHandlerExperiment(ExperimentSet newSet, ICrossoverHandler crossoverHandler, string title)
 {
     var newExperiment = new Experiment();
     newSet.Experiments.Add(newExperiment);
     newExperiment.CrossoverHandler = crossoverHandler;
     newExperiment.Label = "Selection Process: " + title;
 }
Exemplo n.º 6
0
 public static float fitness(float[,] groundTruth, float[] userTrusts, UserUpdate[,,] updates, FitnessParameter fitnessParams)
 {
     return(Experiment.execute(groundTruth, userTrusts, updates, fitnessParams));
 }
Exemplo n.º 7
0
        private static int ExecuteExperiment(Experiment experiment)
        {
            //returns milliseconds to get target string
            const int timesToTest = 20;

            var tests = 0;
            //var generationTotal = 0;
            var timeTotal = 0;
            while (tests < timesToTest)
            {
                var time = DateTime.Now;
                tests++;
                var hypothesisList = new List<Hypothesis>();
                for (var i = 0; i < experiment.PopulationSize; i++)
                {
                    hypothesisList.Add(Hypothesis.CreateRandomHypothesis());
                }

                var generations = 0;
                while (true)
                {
                    SortAndCull(Program.Comparer, experiment.PopulationSize, experiment.Evaluator, hypothesisList);
                    var bestHypothesis = hypothesisList.FirstOrDefault();
                    if (bestHypothesis != null)
                    {
                        var bestString = bestHypothesis.String;
                        if (bestString.Equals(experiment.TargetString)) break;
                    }
                    var newHypothesisList = experiment.CrossoverHandler.CrossoverPopulation(hypothesisList, experiment.PercentToCrossover, experiment.ChildPerPair);
                    MutatePopulation(newHypothesisList, experiment.PercentToMutate, experiment.MutationIntensity);
                    hypothesisList.AddRange(newHypothesisList);

                    generations++;
                }

                var timeElapsed = (DateTime.Now - time).Milliseconds;
                //generationTotal += generations;
                timeTotal += timeElapsed;
                //Console.WriteLine("Test "+tests+" Found in: " + generations + " generations, "+timeElapsed+" ms");
            }

            //Console.WriteLine("Average to find the goal over "+timesToTest+" trials: "+(generationTotal/timesToTest)+" generations, "+(timeTotal/timesToTest)+" ms");
            //Console.ReadLine();
            return timeTotal / timesToTest;
        }