Initialize() 공개 메소드

Initialize the experiment with some optional XML configutation data.
public Initialize ( string name, XmlElement xmlConfig ) : void
name string
xmlConfig System.Xml.XmlElement
리턴 void
예제 #1
0
        void RunExperiment(string XMLFile, string filename)
        {
            _filename = filename;
            _experiment = new SocialExperiment();

            // Write the header for the results file in CSV format.
            using (TextWriter writer = new StreamWriter(_filename))
                writer.WriteLine("Generation,Average,Best,Updates");

            using (TextWriter writer = new StreamWriter(_filename.Replace(".csv", "_diversity_after.csv")))
                writer.WriteLine("Generation,Orientation Variance,Velocity Variance");

            using (TextWriter writer = new StreamWriter(_filename.Replace(".csv", "_diversity_before.csv")))
                writer.WriteLine("Generation,Orientation Variance,Velocity Variance");

            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(XMLFile);
            _experiment.Initialize("EgalitarianSocialLearning", xmlConfig.DocumentElement);
            _experiment.TrialId = _trialNum;

            // Create the evolution algorithm and attach the update event.
            _ea = _experiment.CreateEvolutionAlgorithm();
            _ea.UpdateScheme = new SharpNeat.Core.UpdateScheme(1);
            _ea.UpdateEvent += new EventHandler(_ea_UpdateEvent);

            _experiment.Evaluator.TrialId = _trialNum;
            _experiment.Evaluator.DiversityFile = _filename.Replace(".csv", "_diversity.csv");

            // Start algorithm (it will run on a background thread).
            _ea.StartContinue();
        }
예제 #2
0
        static void RunTrial(int offset)
        {
            RESULTS_FILE = EXPERIMENTS_DIR + RESULTS_FILE_BASE + offset + ".csv";
            _random = new FastRandom();

            _experiment = new SocialExperiment();
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(CONFIG_FILE);
            _experiment.Initialize("SimpleEvolution", xmlConfig.DocumentElement);
            _experiment.NeatGenomeParameters.AddConnectionMutationProbability = 0;
            _experiment.NeatGenomeParameters.AddNodeMutationProbability = 0;
            _experiment.NeatGenomeParameters.DeleteConnectionMutationProbability = 0;
            
            SocialExperiment.CreateNetwork(FEED_FORWARD_NETWORK_FILE, _experiment.InputCount, _experiment.OutputCount);

            // Record the changes at each step
            _experiment.World.Stepped += new social_learning.World.StepEventHandler(World_Stepped);

            // Read in the seed genome from file. This is the prototype for our other population of networks.
            var seed = _experiment.LoadPopulation(XmlReader.Create(FEED_FORWARD_NETWORK_FILE))[0];

            // Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes.
            IGenomeFactory<NeatGenome> genomeFactory = _experiment.CreateGenomeFactory();

            // Create an initial population of randomly generated genomes.
            List<NeatGenome> genomeList = genomeFactory.CreateGenomeList(_experiment.DefaultPopulationSize, 0, seed);

            // Randomize the genomes
            RandomizeGenomes(genomeList);

            // Create genome decoder.
            IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder = _experiment.CreateGenomeDecoder();

            // Create the evaluator that will handle the simulation
            _evaluator = new ForagingEvaluator<NeatGenome>(genomeDecoder, _experiment.World, AgentTypes.Social)
                {
                    MaxTimeSteps = 200000UL,
                    BackpropEpochsPerExample = 1
                };

            using (TextWriter writer = new StreamWriter(RESULTS_FILE))
                writer.WriteLine("Step,Best,Average");

            // Start the simulation
            _evaluator.Evaluate(genomeList);
        }
예제 #3
0
        static void Main(string[] args)
        {
            _random = new FastRandom();

            _experiment = new SocialExperiment();
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(CONFIG_FILE);
            _experiment.Initialize("SimpleEvolution", xmlConfig.DocumentElement);
            _experiment.NeatGenomeParameters.AddConnectionMutationProbability = 0;
            _experiment.NeatGenomeParameters.AddNodeMutationProbability = 0;
            _experiment.NeatGenomeParameters.DeleteConnectionMutationProbability = 0;

            SocialExperiment.CreateNetwork(FEED_FORWARD_NETWORK_FILE, _experiment.InputCount, 20, _experiment.OutputCount);

            // Record the changes at each step
            _experiment.World.Stepped += new social_learning.World.StepEventHandler(World_Stepped);

            // Read in the teacher genome from file.
            var agentGenome = _experiment.LoadPopulation(XmlReader.Create(FEED_FORWARD_NETWORK_FILE));

            // Create genome decoder.
            IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder = _experiment.CreateGenomeDecoder();

            // Create the evaluator that will handle the simulation
            _evaluator = new ForagingEvaluator<NeatGenome>(genomeDecoder, _experiment.World, AgentTypes.QLearning)
            {
                MaxTimeSteps = 50000000UL,
                BackpropEpochsPerExample = 1
            };

            using (TextWriter writer = new StreamWriter(RESULTS_FILE))
                writer.WriteLine("Step,Score");

            // Start the simulation
            _evaluator.Evaluate(agentGenome);
        }
예제 #4
0
        private void evolve_Click(object sender, EventArgs e)
        {
            if (btnEvolve.Text == "Stop!")
            {
                stopEvolution();
                return;
            }
            running = true;
            _experiment = new SocialExperiment();
            
            // Load config XML.
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(_configFile);
            _experiment.Initialize("SimpleEvolution", xmlConfig.DocumentElement);
            _experiment.PlantLayout = _plantLayout;

            _experiment.World.Changed += new World.ChangedEventHandler(world_Changed);
            _experiment.World.AgentEaten += new World.AgentEatenHandler(World_AgentEaten);

            btnEvolve.Text = "Stop!";

            // Start the evolution
            if (_configFile == QLEARNING_CONFIG_FILE)
            {
                qLearningThread = new Thread(new ThreadStart(startQLearning));
                qLearningThread.Start();
            }
            else
            {
                qLearningThread = new Thread(new ThreadStart(startEvolution));
                qLearningThread.Start();
            }
        }