private static void RunExperiment(ExperimentParameters experimentParameters)//, DatabaseContext databaseX) { var database = new DatabaseContext(DatabaseFullPath); var version = new Version(DateTime.Now); var stoper = new Stopwatch(); //if (database.Exists(experimentParameters)) //{ // Console.WriteLine("BYLEM WIDZIALEM"); // //database.Dispose(); // return; //} database.Insert(version); database.Insert(experimentParameters); database.Insert(experimentParameters.EvolutionParameters); IDictionary <int, EvolutionStep> evolutionSteps = null; try { var enginesFactory = new EnginesFactory(); var engine = enginesFactory.Create(experimentParameters); var distanceCalculator = new CanberraDistanceCalculator(); var positivePointsGenerator = new PositivePointsGenerator(); stoper.Restart(); var positiveTrainingPoints = positivePointsGenerator.GeneratePoints(experimentParameters.NumberOfPositivePoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); stoper.Stop(); engine.Statistics.PositiveTrainingPointsGenerationTime = stoper.Elapsed; var negativePointsGenerator = new NegativePointsGenerator(positiveTrainingPoints, distanceCalculator, new NearestNeighbourDistanceCalculator(distanceCalculator)); //var negativeTrainingPoints = negativePointsGenerator.GeneratePoints(experimentParameters.NumberOfNegativePoints, engine.Benchmark.Domains); stoper.Restart(); var negativeTrainingPoints = negativePointsGenerator.GeneratePoints(experimentParameters.NumberOfNegativePoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); stoper.Stop(); engine.Statistics.NegativeTrainingPointsGenerationTime = stoper.Elapsed; //Console.WriteLine("Evolution starts!"); var trainingPoints = positiveTrainingPoints.Concat(negativeTrainingPoints).ToArray(); stoper.Restart(); var mathModel = engine.SynthesizeModel(trainingPoints); stoper.Stop(); engine.Statistics.TotalSynthesisTime = stoper.Elapsed; database.Insert(mathModel); var testPointsGenerator = new TestPointsGenerator(); stoper.Restart(); var testPoints = testPointsGenerator.GeneratePoints(experimentParameters.NumberOfTestPoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); stoper.Stop(); engine.Statistics.TestPointsGenerationTime = stoper.Elapsed; var statistics = engine.EvaluateModel(testPoints); database.Insert(statistics); evolutionSteps = engine.CoreEvolutionSteps; //Logger.Instance.Log(experimentParameters); //Logger.Instance.Log(mathModel); //Logger.Instance.Log(statistics); //database.Insert(Logger.Instance.GetLogAsString()); } catch (Exception exception) { database.Insert(exception); } database.Save(); if (evolutionSteps != null && experimentParameters.TrackEvolutionSteps) { Logger.Instance.Log(evolutionSteps); var logsFullPath = Path.GetFullPath(LogsDirPath + experimentParameters.GetFileName("Log", ".cmplog")); File.WriteAllText(logsFullPath, StringCompressor.CompressString(Logger.Instance.GetLogAsString())); } //GlobalStoper.Stop(); //Console.WriteLine(GlobalStoper.ElapsedMilliseconds); //Console.ReadKey(); database.Dispose(); }
static void Main(string[] args) { //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); //CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US"); //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var experimentParameters = new ExperimentParameters( numberOfDimensions: 2, basePopulationSize: 10, offspringPopulationSize: 100, numberOfGenerations: 100, //seed: new Random().Next(), seed: 1, //seed: 1971749862, //oneFifthRuleCheckInterval: 10, //individualLearningRate: 0.1, //0.47287080450158792 //globalLearningRate: 0.1, //0.31622776601683794 typeOfParentsSelection: ParentsSelectionType.Even, typeOfStdDeviationsRecombination: RecombinationType.Intermediate, typeOfRotationsRecombination: RecombinationType.Intermediate, useRedundantConstraintsRemoving: true, useDataNormalization: true, allowQuadraticTerms: true, useRecombination: false, trackEvolutionSteps: true, useSeeding: true, numberOfParentsSolutionsToSelect: 5, numberOfPositivePoints: 500, numberOfNegativePoints: 1500, //ballnBoundaryValue: 10, //simplexnBoundaryValue: 10, typeOfBenchmark: BenchmarkType.Simplexn); var enginesFactory = new EnginesFactory(); var engine = enginesFactory.Create(experimentParameters); var distanceCalculator = new CanberraDistanceCalculator(); var positivePointsGenerator = new PositivePointsGenerator(); var positiveTrainingPoints = positivePointsGenerator.GeneratePoints(experimentParameters.NumberOfPositivePoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); var negativePointsGenerator = new NegativePointsGenerator(positiveTrainingPoints, distanceCalculator, new NearestNeighbourDistanceCalculator(distanceCalculator)); //var negativeTrainingPoints = negativePointsGenerator.GeneratePoints(experimentParameters.NumberOfNegativePoints, engine.Benchmark.Domains); var negativeTrainingPoints = negativePointsGenerator.GeneratePoints(experimentParameters.NumberOfNegativePoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); var trainingPoints = positiveTrainingPoints.Concat(negativeTrainingPoints).ToArray(); var testPointsGenerator = new TestPointsGenerator(); var testPoints = testPointsGenerator.GeneratePoints(experimentParameters.NumberOfTestPoints, engine.Benchmark.Domains, engine.Benchmark.Constraints); Console.WriteLine("Evolution starts!"); var mathModel = engine.SynthesizeModel(trainingPoints); var statistics = engine.EvaluateModel(testPoints); var visualization = PrepareVisualisation(experimentParameters, engine, positiveTrainingPoints, negativeTrainingPoints, testPoints); visualization.Show(); Console.WriteLine("=========================================="); Console.WriteLine("=============== PARAMETERS ==============="); Console.WriteLine("=========================================="); Console.WriteLine(experimentParameters.ToPrintableString()); Console.WriteLine(); Console.WriteLine("=========================================="); Console.WriteLine("============= REFERENCE MODEL ============"); Console.WriteLine("=========================================="); Console.WriteLine(mathModel.ReferenceModelInLpFormat); Console.WriteLine(); Console.WriteLine("=========================================="); Console.WriteLine("============ SYNTHESIZED MODEL ==========="); Console.WriteLine("=========================================="); Console.WriteLine(mathModel.SynthesizedModelInLpFormat); Console.WriteLine(); Console.WriteLine("=========================================="); Console.WriteLine("=============== STATISTICS ==============="); Console.WriteLine("=========================================="); Console.WriteLine(statistics.ToPrintableString()); Console.WriteLine(); Console.ReadKey(); }