// Use this for initialization IEnumerator Start() { /*** Initialize experiment ***/ INeatExperiment experiment = new TestExperiment() as INeatExperiment; // Null because not reading settings from xmlFile experiment.Initialize("this is a test",null); /*** Randomly generate population ***/ // Set initial settings // ? means it is nullable int? popSize = experiment.DefaultPopulationSize; //double? initConnProportion = experiment.NeatGenomeParameters.InitialInterconnectionsProportion; // Create a genome factory appropriate for the experiment. IGenomeFactory<NeatGenome> genomeFactory = experiment.CreateGenomeFactory(); // Create an initial population of randomly generated genomes. // 0u is a struct for a 32 bit unsigned integer List<NeatGenome> genomeList = genomeFactory.CreateGenomeList(popSize.Value, 0u); // Check number of species is <= the number of the genomes. if (genomeList.Count < experiment.NeatEvolutionAlgorithmParameters.SpecieCount) { Debug.Log("Genome count must be >= specie count. Genomes=" + genomeList.Count + " Species=" + experiment.NeatEvolutionAlgorithmParameters.SpecieCount); return false; } /*** Run the algorithm ***/ ea = experiment.CreateEvolutionAlgorithm(genomeFactory, genomeList); //for (int j = 0; j < 100; j++) { yield return new WaitForSeconds(0.5f); //Debug.Log(j); ea.StartContinue(); NeatAlgorithmStats stats = ea.Statistics; Debug.Log(stats._generation+", "+stats._maxFitness+", "+stats._meanFitness+", "+stats._totalEvaluationCount+", "+stats._maxComplexity); //} //NeatAlgorithmStats stats = ea.Statistics; //Debug.Log(stats._generation+", "+stats._maxFitness+", "+stats._meanFitness+", "+stats._totalEvaluationCount+", "+stats._maxComplexity); IGenomeDecoder<NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); IBlackBox box = decoder.Decode(ea.CurrentChampGenome); FastAcyclicNetwork concrete = (FastAcyclicNetwork)box; Debug.Log("Num hidden nodes = " + concrete.hiddenNodeCount + ", num connections = " + concrete.connectionCount); box.InputSignalArray[0] = 0; box.InputSignalArray[1] = 0; box.Activate(); for (int i = 0; i < box.OutputCount; i++) { Debug.LogWarning("Output["+i+"] = " + box.OutputSignalArray[i]); } }
// Use this for initialization IEnumerator Start() { /*** Initialize experiment ***/ INeatExperiment experiment = new TestExperiment() as INeatExperiment; // Null because not reading settings from xmlFile experiment.Initialize("this is a test", null); /*** Randomly generate population ***/ // Set initial settings // ? means it is nullable int?popSize = experiment.DefaultPopulationSize; //double? initConnProportion = experiment.NeatGenomeParameters.InitialInterconnectionsProportion; // Create a genome factory appropriate for the experiment. IGenomeFactory <NeatGenome> genomeFactory = experiment.CreateGenomeFactory(); // Create an initial population of randomly generated genomes. // 0u is a struct for a 32 bit unsigned integer List <NeatGenome> genomeList = genomeFactory.CreateGenomeList(popSize.Value, 0u); // Check number of species is <= the number of the genomes. if (genomeList.Count < experiment.NeatEvolutionAlgorithmParameters.SpecieCount) { Debug.Log("Genome count must be >= specie count. Genomes=" + genomeList.Count + " Species=" + experiment.NeatEvolutionAlgorithmParameters.SpecieCount); return(false); } /*** Run the algorithm ***/ ea = experiment.CreateEvolutionAlgorithm(genomeFactory, genomeList); //for (int j = 0; j < 100; j++) { yield return(new WaitForSeconds(0.5f)); //Debug.Log(j); ea.StartContinue(); NeatAlgorithmStats stats = ea.Statistics; Debug.Log(stats._generation + ", " + stats._maxFitness + ", " + stats._meanFitness + ", " + stats._totalEvaluationCount + ", " + stats._maxComplexity); //} //NeatAlgorithmStats stats = ea.Statistics; //Debug.Log(stats._generation+", "+stats._maxFitness+", "+stats._meanFitness+", "+stats._totalEvaluationCount+", "+stats._maxComplexity); IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); IBlackBox box = decoder.Decode(ea.CurrentChampGenome); FastAcyclicNetwork concrete = (FastAcyclicNetwork)box; Debug.Log("Num hidden nodes = " + concrete.hiddenNodeCount + ", num connections = " + concrete.connectionCount); box.InputSignalArray[0] = 0; box.InputSignalArray[1] = 0; box.Activate(); for (int i = 0; i < box.OutputCount; i++) { Debug.LogWarning("Output[" + i + "] = " + box.OutputSignalArray[i]); } }