/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome population and their associated/parent genome factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new KMeansClusteringStrategy <NeatGenome>(distanceMetric); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. TestEvaluator evaluator = new TestEvaluator(); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> innerEvaluator = new SerialGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator); // Wrap the list evaluator in a 'selective' evaulator that will only evaluate new genomes. That is, we skip re-evaluating any genomes // that were in the population in previous generations (elite genomes). This is determiend by examining each genome's evaluation info object. IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); // Initialize the evolution algorithm. ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
private void evaluateChromosome(int index, TestEvaluator evaluator) { Chromosome chromosome = population.getChromosomes()[index]; evaluator.startEvaluation(chromosome.getWeights(), index); ++chromosomesInEvaluation; }
void Start() { TestEvaluator simulator = Instantiate(simulatorPrefab); simulator.evolutionator = this; simulators.Add(simulator); population = new Population(null, CreateNeuralNet(simulators[0]), populationSize, .03, .5, .7); runEvaluation(); }
private string BuildHeader(Subject subject) { TestEvaluator evaluation = new TestEvaluator(); string header = $"<head><meta charset='UTF8'> " + "<style>table{font-family: arial, sans-serif;border-collapse: collapse;width:100%;}td,th{border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #dddddd;}</style></head>" + "<h1 style=text-align:center;background-color:lightblue;font-size:xx-large;>Teszt eredmények</h1>" + "<p>tesztvezető neve:</p>" + $"<p>tesztalany neve: {subject.Nickname}</p>" + $"<p><b>életkor: {subject.Age}</b></p>" + $"<p><b>nem: {subject.Gender.ToString()}</b></p>" + $"<p><b>kitöltés időpontja: {subject.SessionStartDate.ToString("yyyy.MM.dd HH:mm:ss")}</b></p>" + $"<p><i>eredmény: {evaluation.Evaluate(subject).ToString()}</i><p >" + "<hr>"; return(header); }
public void Test1() { TestEvaluator evaluator = new TestEvaluator(); var expression = BindingExpression.ParseExpression("{eval path=Name}"); Assert.AreEqual(expression.Name, "eval", "测试解析绑定表达式失败"); object value; Assert.IsTrue(expression.TryGetValue(evaluator, "path", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "Name", "测试解析绑定表达式失败"); expression = BindingExpression.ParseExpression("{eval path=Name , key==@#$}"); Assert.AreEqual(expression.Name, "eval", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "path", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "Name ", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "key", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "=@#$", "测试解析绑定表达式失败"); expression = BindingExpression.ParseExpression("{eval path={{abc,,}},key=abc}"); Assert.AreEqual(expression.Name, "eval", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "path", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "{abc,}", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "key", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "abc", "测试解析绑定表达式失败"); expression = BindingExpression.ParseExpression("{eval path={},,key=abc}"); Assert.IsNull(expression, "错误的解析了错误的表达式"); expression = BindingExpression.ParseExpression("{eval path={eval a=b, c=d},key=abc}"); Assert.AreEqual(expression.Name, "eval", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "path", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "a:b,c:d", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "key", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "abc", "测试解析绑定表达式失败"); expression = BindingExpression.ParseExpression("{eval a, b=}"); Assert.AreEqual(expression.Name, "eval", "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "a", out value), "测试解析绑定表达式失败"); Assert.IsNull(value, "测试解析绑定表达式失败"); Assert.IsTrue(expression.TryGetValue(evaluator, "b", out value), "测试解析绑定表达式失败"); Assert.AreEqual(value, "", "测试解析绑定表达式失败"); }
public void Test_SynchronizerConstruct_Steps() { Model model = new Model("SFC Test 1"); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid()); IPfcStepNode t0 = pfc.CreateStep("S_Alice", "", Guid.Empty); IPfcStepNode t1 = pfc.CreateStep("S_Bob", "", Guid.Empty); IPfcStepNode t2 = pfc.CreateStep("S_Charley", "", Guid.Empty); IPfcStepNode t3 = pfc.CreateStep("S_David", "", Guid.Empty); IPfcStepNode t4 = pfc.CreateStep("S_Edna", "", Guid.Empty); IPfcStepNode t5 = pfc.CreateStep("S_Frank", "", Guid.Empty); IPfcStepNode t6 = pfc.CreateStep("S_Gary", "", Guid.Empty); IPfcStepNode t7 = pfc.CreateStep("S_Hailey", "", Guid.Empty); pfc.Synchronize(new IPfcStepNode[] { t0, t1, t2, t3 }, new IPfcStepNode[] { t4, t5, t6, t7 }); string structureString = PfcDiagnostics.GetStructure(pfc); structureString = structureString.Replace("SFC 1.Root", "SFC 1.Root"); string shouldBe = "{S_Alice-->[L_000(SFC 1.Root)]-->T_000}\r\n{S_Bob-->[L_001(SFC 1.Root)]-->T_000}\r\n{S_Charley-->[L_002(SFC 1.Root)]-->T_000}\r\n{S_David-->[L_003(SFC 1.Root)]-->T_000}\r\n{T_000-->[L_004(SFC 1.Root)]-->S_Edna}\r\n{T_000-->[L_005(SFC 1.Root)]-->S_Frank}\r\n{T_000-->[L_006(SFC 1.Root)]-->S_Gary}\r\n{T_000-->[L_007(SFC 1.Root)]-->S_Hailey}\r\n"; Console.WriteLine("After a synchronization of steps, structure is \r\n" + structureString); Assert.AreEqual(structureString, shouldBe, "Structure should have been\r\n" + shouldBe + "\r\nbut it was\r\n" + structureString + "\r\ninstead."); if (m_runSFCs) { TestEvaluator testEvaluator = new TestEvaluator(new IPfcStepNode[] { t0, t1, t2, t3, t4, t5, t6, t7 }); pfc.Synchronize(new IPfcStepNode[] { t0, t1, t2, t3 }, new IPfcStepNode[] { t4, t5, t6, t7 }); testEvaluator.NextExpectedActivations = new IPfcStepNode[] { t0, t1, t2, t3, t4, t5, t6, t7 }; foreach (IPfcNode ilinkable in new IPfcStepNode[] { t0, t1, t2, t3 }) { Console.WriteLine("Incrementing " + ilinkable.Name + "."); //ilinkable.Increment(); throw new ApplicationException("PFCs are not currently executable."); } testEvaluator.NextExpectedActivations = new IPfcTransitionNode[] { }; // Ensure it's empty and all have fired. } }
public void reportFitness(TestEvaluator evaluator, double fitness, int index) { totalFitness += fitness; --chromosomesInEvaluation; Chromosome chromosome = population.getChromosomes()[index]; chromosome.setFitness(fitness); print("current index: " + currentChromosomeIndex); if (currentChromosomeIndex < populationSize - 1) { if (currentChromosomeIndex + chromosomesInEvaluation < populationSize - 1) { evaluateChromosome(currentChromosomeIndex + chromosomesInEvaluation + 1, evaluator); } ++currentChromosomeIndex; } else { print("restart generation"); startNextGeneration(); } }
public static NeuralNet CreateNeuralNet(TestEvaluator evaluator) { return(new NeuralNet(NeuronMode.NEURON, true, 2, evaluator.getOutputsRequired(), 7, 2)); }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome population and their associated/parent genome factory. /// </summary> public NeatEvolutionAlgorithm<NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory<NeatGenome> genomeFactory, List<NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy<NeatGenome> speciationStrategy = new KMeansClusteringStrategy<NeatGenome>(distanceMetric); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm<NeatGenome> ea = new NeatEvolutionAlgorithm<NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. TestEvaluator evaluator = new TestEvaluator(); // Create genome decoder. IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator<NeatGenome> innerEvaluator = new SerialGenomeListEvaluator<NeatGenome, IBlackBox>(genomeDecoder, evaluator); // Wrap the list evaluator in a 'selective' evaulator that will only evaluate new genomes. That is, we skip re-evaluating any genomes // that were in the population in previous generations (elite genomes). This is determiend by examining each genome's evaluation info object. IGenomeListEvaluator<NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator<NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator<NeatGenome>.CreatePredicate_OnceOnly()); // Initialize the evolution algorithm. ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return ea; }