public void PrintStats() { // MUST BE CALLED AFTER RunEA NeatAlgorithmStats stats = contentEA.Statistics; Debug.Log("************* NEAT STATS **************"); Debug.Log("Generation = " + stats._generation + ", Total Evaluation = " + stats._totalEvaluationCount + ", Max Fitness = " + stats._maxFitness + ", MeanFitness = " + stats._meanFitness); IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); IBlackBox box = decoder.Decode(contentEA.CurrentChampGenome); FastAcyclicNetwork concrete = (FastAcyclicNetwork)box; Debug.Log("Champ:Num hidden nodes = " + concrete.hiddenNodeCount + ", num connections = " + concrete.connectionCount); // Get highlevel features PCGSharpHighLevelFeatures featureCounts = new PCGSharpHighLevelFeatures(); PCGSharpHighLevelFeatures.C_HL_ROOMTYPE lastRoomType = PCGSharpHighLevelFeatures.C_HL_ROOMTYPE.NoPreviousRoom; for (int i = 0; i < (experiment as PCGNeatExperiment).geomNodeList.Count; i++) { // Get cppn output for each node box.InputSignalArray[0] = (experiment as PCGNeatExperiment).geomNodeList[i].normDepth; box.InputSignalArray[1] = (experiment as PCGNeatExperiment).geomNodeList[i].normSiblingIndex; box.ResetState(); box.Activate(); string outputString = box.OutputSignalArray[0].ToString(); double[] outputs = new double[box.OutputCount]; outputs[0] = box.OutputSignalArray[0]; for (int j = 1; j < box.OutputCount; j++) { outputString = outputString + "," + box.OutputSignalArray[j]; outputs[j] = box.OutputSignalArray[j]; } Debug.Log("(" + (experiment as PCGNeatExperiment).geomNodeList[i].normDepth + "," + (experiment as PCGNeatExperiment).geomNodeList[i].normSiblingIndex + ") -> (" + outputString + ")"); // Convert each nodes cppn output into a contentId int combinedContentID = featureCounts.CPPNOutputToSettingsId(outputs); lastRoomType = featureCounts.UpdateFeatures(combinedContentID, lastRoomType); } // Pass the highlevel features into the player model to get the fitness if ((experiment as PCGNeatExperiment).playerModel != null) { double[] distributions = (experiment as PCGNeatExperiment).playerModel.ClassifyNewData(featureCounts.ToDoubleArray()); Debug.Log("Classifier: Champ Distributions: Dislike = " + distributions[0] + ", Like = " + distributions[1]); (experiment as PCGNeatExperiment).playerModel.PrintClassifierTestReport(); } Debug.Log("**************END NEAT STATS**************"); }
static void ea_UpdateEvent(object sender, EventArgs e) { StreamWriter logWriter = new StreamWriter(LogFolder + NameFile + "_" + MaxTMin + "m" + ".log", true); Console.WriteLine(string.Format("gen={0:N0} bestFitness={1:N6}", _ea.CurrentGeneration, _ea.Statistics._maxFitness)); NeatAlgorithmStats stats = _ea.Statistics; now = DateTime.Now; logWriter.Flush(); logWriter.WriteLine("{0:yyyy-MM-dd HH:mm:ss.fff},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", now, stats._generation, stats._maxFitness, stats._meanFitness, stats._meanSpecieChampFitness, _ea.CurrentChampGenome.Complexity, stats._meanComplexity, stats._maxComplexity, stats._totalEvaluationCount, stats._evaluationsPerSec, _ea.ComplexityRegulationMode); if (_ea.StopConditionSatisfied == true) { Console.WriteLine("Stop condition staisfied."); logWriter.WriteLine("Stop condition satisfied."); next = true; } logWriter.Close(); logWriter.Dispose(); /*if ((now - T0).Seconds%60 == 1) * Console.WriteLine(now); * * if ((now - T0).Minutes >= 20) * next = true; */ }
/// <summary> /// Determine which complexity regulation mode the search should be in given the provided /// NEAT algorithm stats. /// </summary> public ComplexityRegulationMode DetermineMode(NeatAlgorithmStats stats) { if (ComplexityRegulationMode.Complexifying == _currentMode) { if (-1.0 == _complexityCeilingCurrent) { // First call to DetermineMode(). Continue complexifying and set threshold relative current complexity. _complexityCeilingCurrent = stats._meanComplexity + _complexityCeiling; } // Currently complexifying. Test if the complexity ceiling has been reached. else if (stats._meanComplexity > _complexityCeilingCurrent) { // Switch to simplifying mode. _currentMode = ComplexityRegulationMode.Simplifying; _lastTransitionGeneration = stats._generation; } } else { // Currently simplifying. Test if simplication (ongoing reduction in complexity) has stalled. // We allow simplification to progress for a few generations before testing of it has stalled, this allows // a lead in time for the effects of simplification to occur. // In addition we do not switch to complexifying if complexity is above the currently defined ceiling. if (((stats._generation - _lastTransitionGeneration) > MinSimplifcationGenerations) && (stats._meanComplexity < _complexityCeilingCurrent) && ((stats._complexityMA.Mean - stats._prevComplexityMA) >= 0.0)) { // Simplification has stalled. Switch back to complexification. _currentMode = ComplexityRegulationMode.Complexifying; _lastTransitionGeneration = stats._generation; // Redefine the complexity ceiling (for relative ceiling only). if (ComplexityCeilingType.Relative == _ceilingType) { _complexityCeilingCurrent = stats._meanComplexity + _complexityCeiling; } } } return(_currentMode); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return neatStats._meanComplexity > _ceiling; }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return (neatStats._generation - phasedSearchStats._currentPhaseFitnessMaxGeneration) > _generationStallLimit; }
/// <summary> /// Determine which complexity regulation mode the search should be in given the provided /// NEAT algorithm stats. /// </summary> public ComplexityRegulationMode DetermineMode(NeatAlgorithmStats stats) { return ComplexityRegulationMode.Complexifying; }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return (DateTime.Now - phasedSearchStats._currentPhaseFitnessMaxClockTime) > _clockTimeStallLimit; }
// 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]); } }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return neatStats._meanComplexity > (phasedSearchStats._lastComplexityBase + _relativeCeiling); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return (neatStats._generation - phasedSearchStats._lastTransitionGeneration) > _generations; }
/// <summary> /// Determine which complexity regulation mode the search should be in given the provided /// NEAT algorithm stats. /// </summary> public ComplexityRegulationMode DetermineMode(NeatAlgorithmStats stats) { return(ComplexityRegulationMode.Complexifying); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return((DateTime.Now - phasedSearchStats._lastTransitionClockTime) > _timespan); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return((phasedSearchStats._currentPhaseComplexityMinGeneration - neatStats._generation) > _generationStallLimit); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return(neatStats._meanComplexity > (phasedSearchStats._lastComplexityBase + _relativeCeiling)); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return (DateTime.Now - phasedSearchStats._lastTransitionClockTime) > _timespan; }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return(neatStats._meanComplexity > _ceiling); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return((DateTime.Now - phasedSearchStats._currentPhaseComplexityMinClockTime) > _clockTimeStallLimit); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return((neatStats._generation - phasedSearchStats._lastTransitionGeneration) > _generations); }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return (phasedSearchStats._currentPhaseComplexityMinGeneration - neatStats._generation) > _generationStallLimit; }
/// <summary> /// Determine which complexity regulation mode the search should be in given the provided /// NEAT algorithm stats. /// </summary> public ComplexityRegulationMode DetermineMode(NeatAlgorithmStats stats) { if(ComplexityRegulationMode.Complexifying == _currentMode) { if(-1.0 == _complexityCeilingCurrent) { // First call to DetermineMode(). Continue complexifying and set threshold relative current complexity. _complexityCeilingCurrent = stats._meanComplexity + _complexityCeiling; } // Currently complexifying. Test if the complexity ceiling has been reached. else if(stats._meanComplexity > _complexityCeilingCurrent) { // Switch to simplifying mode. _currentMode = ComplexityRegulationMode.Simplifying; _lastTransitionGeneration = stats._generation; } } else { // Currently simplifying. Test if simplication (ongoing reduction in complexity) has stalled. // We allow simplification to progress for a few generations before testing of it has stalled, this allows // a lead in time for the effects of simplification to occur. // In addition we do not switch to complexifying if complexity is above the currently defined ceiling. if(((stats._generation - _lastTransitionGeneration) > MinSimplifcationGenerations) && (stats._meanComplexity < _complexityCeilingCurrent) && ((stats._complexityMA.Mean - stats._prevComplexityMA) >= 0.0)) { // Simplification has stalled. Switch back to complexification. _currentMode = ComplexityRegulationMode.Complexifying; _lastTransitionGeneration = stats._generation; // Redefine the complexity ceiling (for relative ceiling only). if(ComplexityCeilingType.Relative == _ceilingType) { _complexityCeilingCurrent = stats._meanComplexity + _complexityCeiling; } } } return _currentMode; }
/// <summary> /// Returns true of the trigger criteria are met. /// </summary> public bool TestTrigger(NeatAlgorithmStats neatStats, PhasedSearchStats phasedSearchStats) { return((neatStats._generation - phasedSearchStats._currentPhaseFitnessMaxGeneration) > _generationStallLimit); }