本文整理汇总了C#中IGenomeFactory.CreateGenomeList方法的典型用法代码示例。如果您正苦于以下问题:C# IGenomeFactory.CreateGenomeList方法的具体用法?C# IGenomeFactory.CreateGenomeList怎么用?C# IGenomeFactory.CreateGenomeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGenomeFactory
的用法示例。
在下文中一共展示了IGenomeFactory.CreateGenomeList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Initialise log4net (log to console).
XmlConfigurator.Configure(new FileInfo("log4net.properties"));
// Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search.
XorExperiment experiment = new XorExperiment();
// Load config XML.
XmlDocument xmlConfig = new XmlDocument();
xmlConfig.Load("xor.config.xml");
experiment.Initialize("XOR", xmlConfig.DocumentElement);
// Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes.
_genomeFactory = experiment.CreateGenomeFactory();
// Create an initial population of randomly generated genomes.
_genomeList = _genomeFactory.CreateGenomeList(150, 0);
// Create evolution algorithm and attach update event.
_ea = experiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList);
_ea.UpdateEvent += new EventHandler(ea_UpdateEvent);
// Start algorithm (it will run on a background thread).
_ea.StartContinue();
// Hit return to quit.
Console.ReadLine();
}
示例2: NeatTrainer
public NeatTrainer(ExperimentSettings experimentSettings, NeatEvolutionAlgorithmParameters evolutionAlgorithmParameters, TrainingGameSettings gameSettings)
{
var neuromonPhenomeEvaluator = new NeuromonEvaluator(gameSettings, experimentSettings);
var neatGenomeParameters = new NeatGenomeParameters();
_neuromonExperiment = new NeuromonExperiment(experimentSettings, evolutionAlgorithmParameters, neuromonPhenomeEvaluator, neatGenomeParameters);
_genomeIo = new GenomeIo(_neuromonExperiment);
_genomeFactory = _neuromonExperiment.CreateGenomeFactory();
if (experimentSettings.LoadExistingPopulation)
{
_genomePopulation = _genomeIo.Read(experimentSettings.ExistingPopulationFilePath);
}
else
{
// Randomly generate a new population
_genomePopulation = _genomeFactory.CreateGenomeList(experimentSettings.PopulationSize, 0);
}
_genomeIo.CacheChampion(_genomePopulation.OrderByDescending(g => g.EvaluationInfo.Fitness).First());
_fitnessStagnationDetector = new FitnessStagnationDetector(experimentSettings.StagnationDetectionTriggerValue);
_desiredFitness = experimentSettings.DesiredFitness;
_previousGeneration = 0;
_overallBestFitness = 0.0;
}
示例3: Main
private static void Main(string[] args)
{
Debug.Assert(args != null && args.Length == 2,
"Experiment configuration file and number of runs are required!");
// Read in experiment configuration file
string experimentName = args[0];
int numRuns = Int32.Parse(args[1]);
// Initialise log4net (log to console).
XmlConfigurator.Configure(new FileInfo("log4net.properties"));
// Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search.
SteadyStateMazeNavigationNoveltyExperiment experiment = new SteadyStateMazeNavigationNoveltyExperiment();
// Load config XML.
XmlDocument xmlConfig = new XmlDocument();
xmlConfig.Load("./ExperimentConfigurations/" + experimentName);
experiment.Initialize("Novelty", xmlConfig.DocumentElement, null, null);
// Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes.
_genomeFactory = experiment.CreateGenomeFactory();
// Create an initial population of randomly generated genomes.
_genomeList = _genomeFactory.CreateGenomeList(experiment.DefaultPopulationSize, 0);
// Create evolution algorithm and attach update event.
_ea = experiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList);
_ea.UpdateEvent += ea_UpdateEvent;
// Start algorithm (it will run on a background thread).
_ea.StartContinue();
/*while (RunState.Terminated != _ea.RunState && RunState.Paused != _ea.RunState &&
_ea.CurrentGeneration < maxGenerations)
{
Thread.Sleep(2000);
}*/
// Hit return to quit.
//Console.ReadLine();
}
示例4: loadSeedGenomesToolStripMenuItem_Click
private void loadSeedGenomesToolStripMenuItem_Click(object sender, EventArgs e)
{
string popFilePath = SelectFileToOpen("Load seed genomes", "pop.xml", "(*.pop.xml)|*.pop.xml");
if(string.IsNullOrEmpty(popFilePath)) {
return;
}
// Parse population size from GUI field.
int? popSize = ParseInt(txtParamPopulationSize);
if(null == popSize) {
return;
}
try
{
// Get the currently selected experiment.
INeatExperiment experiment = GetSelectedExperiment();
// Load genome from file.
List<NeatGenome> genomeList;
using(XmlReader xr = XmlReader.Create(popFilePath))
{
genomeList = experiment.LoadPopulation(xr);
}
if(genomeList.Count == 0) {
__log.WarnFormat("No seed genomes loaded from file [{0}]", popFilePath);
return;
}
// Create genome list from seed genomes, assign to local variables and update GUI.
_genomeFactory = genomeList[0].GenomeFactory;
_genomeList = _genomeFactory.CreateGenomeList(popSize.Value, 0u, genomeList);
UpdateGuiState();
}
catch(Exception ex)
{
__log.ErrorFormat("Error loading seed genomes. Error message [{0}]", ex.Message);
}
}
示例5: Main
static void Main(string[] args)
{
// Initialise log4net (log to console).
XmlConfigurator.Configure(new FileInfo("log4net.properties"));
// Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search.
XorExperiment experiment = new XorExperiment();
// Load config XML.
XmlDocument xmlConfig = new XmlDocument();
xmlConfig.Load("xor.config.xml");
experiment.Initialize("XOR", xmlConfig.DocumentElement);
WriteHelp();
// Read key commands from the console.
for(;;)
{
// Read command.
Console.Write(">");
string cmdstring = Console.ReadLine();
// Parse command.
string[] cmdArgs = cmdstring.Split(' ');
try
{
// Process command.
switch(cmdArgs[0])
{
// Init commands.
case "randpop":
{
if(null != _ea && _ea.RunState == RunState.Running) {
Console.WriteLine("Error. Cannot create population while algorithm is running.");
break;
}
// Attempt to parse population size arg.
if(cmdArgs.Length <= 1) {
Console.WriteLine("Error. Missing {size} argument.");
break;
}
int populationSize;
if(!int.TryParse(cmdArgs[1], out populationSize)) {
Console.WriteLine(string.Format("Error. Invalid {size} argument [{0}].", cmdArgs[1]));
break;
}
// Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes.
_genomeFactory = experiment.CreateGenomeFactory();
// Create an initial population of randomly generated genomes.
_genomeList = _genomeFactory.CreateGenomeList(populationSize, 0);
Console.WriteLine(string.Format("Created [{0}] random genomes.", populationSize));
break;
}
case "loadpop":
{
if(null != _ea && _ea.RunState == RunState.Running) {
Console.WriteLine("Error. Cannot load population while algorithm is running.");
break;
}
// Attempt to get population filename arg.
if(cmdArgs.Length <= 1) {
Console.WriteLine("Error. Missing {filename} argument.");
break;
}
// Open and load population XML file.
using(XmlReader xr = XmlReader.Create(cmdArgs[1])) {
_genomeList = experiment.LoadPopulation(xr);
}
_genomeFactory = _genomeList[0].GenomeFactory;
Console.WriteLine(string.Format("Loaded [{0}] genomes.", _genomeList.Count));
break;
}
case "loadseed":
{
if(null != _ea && _ea.RunState == RunState.Running) {
Console.WriteLine("Error. Cannot load population while algorithm is running.");
break;
}
// Attempt to get genome filename arg.
if(cmdArgs.Length <= 1) {
Console.WriteLine("Error. Missing {filename} argument.");
break;
}
// Attempt to parse population size arg.
if(cmdArgs.Length <= 2) {
Console.WriteLine("Error. Missing {size} argument.");
break;
}
int populationSize;
if(!int.TryParse(cmdArgs[1], out populationSize)) {
//.........这里部分代码省略.........
示例6: Main
static void Main(string[] args)
{
// This program expects certain command line options, that are defined as annotated properties in the NeatSimConsole.Options class
// We instantiate this class...
_options = new Options();
// ... and pass the arguments to this program to the options parser, who uses it to set the properties in 'options'.
// If the command line options are incorrect, ParseArgumentsStrict prints a help message to the screen and exits...
if (!CommandLine.Parser.Default.ParseArgumentsStrict(args, _options))
{
// ... therefore, this should really never ever happen.
throw new SystemException("Something went wrong parsing arguments.");
}
// Now, all the properties in 'options' are set.
FastRandom.__seedRng = new FastRandom(_options.Seed);
// Initialise log4net (log to console).
// XmlConfigurator.Configure(new FileInfo("log4net.properties"));
// We instatiate a remote batch simulation experiment, and use the properties set in the XML file to initialize the experiment.
// The XML file contains properties like the number of generations to run the program for, and the number of individuals in the population.
// For properties that are not set in the XML file, we initialize default values.
_experiment = new RemoteBatchSimExperiment();
var xmlConfig = new XmlDocument();
try
{
xmlConfig.Load("neatsim.config.xml");
}
catch (FileNotFoundException e)
{
Console.WriteLine(@"Could not find neatsim.config.xml. Aborting.");
return;
}
_experiment.Initialize("NeatSim", xmlConfig.DocumentElement);
// The XML file cannot contain information about the inital number of connected neurons.
// We want to initialize our population minimally, and do this by setting an absurdly small initial connections proportion.
// The number of connected input neurons will always be at least one.
// Note that there is an absurdly small chance that more than a single neuron will be connected in generation one.
_experiment.NeatGenomeParameters.InitialInterconnectionsProportion = 0.0000000000001;
// Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes.
_genomeFactory = _experiment.CreateGenomeFactory();
// Create an initial population of randomly generated genomes ('born' in generation 0).
_genomeList = _genomeFactory.CreateGenomeList(_options.PopulationSize, 0);
// Create evolution algorithm and attach update events.
_ea = _experiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList);
_ea.PausedEvent += (s, e) => Console.WriteLine(_ea.RunState == RunState.Paused
? @"Program is paused"
: _ea.RunState == RunState.Running
? @"Program is unpaused."
: @"Program is in unknown state...");
_neatSimLogger = new NeatSimLogger(_options.LogFileName + '_' + DateTime.Now.ToString("yyyyMMdd"));
//
var nextGeneration = _ea.CurrentGeneration;
var doneEvent = new AutoResetEvent(false);
_ea.UpdateEvent += (s, e) =>
{
if (_ea.CurrentGeneration < nextGeneration)
{
Console.WriteLine("Aborting!");
return;
}
Console.WriteLine(string.Format("gen={0:N0} bestFitness={1:N6}", _ea.CurrentGeneration, _ea.Statistics._maxFitness));
SaveChampionGenome();
_neatSimLogger.Log(_ea);
if (_ea.CurrentGeneration >= _options.Generations)
{
_ea.Stop();
_neatSimLogger.Close();
doneEvent.Set();
}
nextGeneration++;
};
// Start algorithm (it will run on a background thread).
_ea.StartContinue();
// Hit return to quit.
//Console.ReadLine();
doneEvent.WaitOne();
}