Skip to content
Snippets Groups Projects
Select Git revision
  • f8e1dfc9d3ff33ff9d284832d072471b589abc8b
  • master default protected
2 results

Program.cs

Blame
  • Program.cs 57.53 KiB
    using MathNet.Numerics.LinearAlgebra;
    using MathNet.Numerics.Random;
    using OxyPlot;
    using OxyPlot.Axes;
    using OxyPlot.Series;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace IVMCTrim
    {
        class Program
        {
            // This is the entry point.
            // Consult readme.md for information about how to run this program.
            // Consult fjn1g13@soton.ac.uk if you don't understand something.
            // This code is not exemplar C#; rather, the idea is that it should be fairly easy for anyone to reimplement the model from looking at it without taking too long to run.
            static void Main()
            {
                // none of our matrices are big enough to warrent multi-threading
                MathNet.Numerics.Control.UseSingleThread();
    
                // repeats with Z=0.95
                RunRepeats("Z095", Configurations.Standard(Z: 0.95), baseSeed: 2042, repeats: 4);
    
                // runs a bunch of experiments with the 'standard' configuration, only varying Z
                // seeds should match those used in the paper
                Run("Z000", Configurations.Standard(Z: 0.0), seed: 42); // (no dual-peaked environments)
                Run("Z050", Configurations.Standard(Z: 0.5), seed: 542);
                Run("Z075", Configurations.Standard(Z: 0.75), seed: 1842);
                Run("Z095", Configurations.Standard(Z: 0.95), seed: 2042); // Corresponds to Figures 3&4
                Run("Z000PerfectG", Configurations.PerfectG(Z: 0.0), seed: 42); // (we align G with the environment automatically and disable mutations in G, eliminating any oportunity to experiance an evolvability benefit)
    
                // prepare some experiments with unusual configurations
                Run("FixedHigh", Configurations.FixedHigh, seed: 42); // Corresponds to Figure 6
                Run("Z095L2", Configurations.StandardL2(Z: 0.95), seed: 2042); // (example with super-additive cost function (quadratic/Ridge))
                Run("Z095MMSO", Configurations.StandardMMSO(Z: 0.95), seed: 2042); // (example with sub-additive cost function)
                Run("Z050E204", Configurations.Standard204(Z: 0.95), seed: 42, reportingPeriodMultiplier: 10); // (example with more modules; this one takes a while to run)
            }
    
            /// <summary>
            /// Runs a single experiment with the given parameters and seed producing output into the given output directory
            /// </summary>
            public static void Run(string outputDirectory, Parameters parameters, int seed, int reportingPeriodMultiplier = 1)
            {
                Console.WriteLine($"Running into {outputDirectory}");
                System.IO.Directory.CreateDirectory(outputDirectory);
    
                // initialise reporter
                var reporter = Recording.CreateEndOfEpisodeReporter(outputDirectory, parameters, reportingPeriodMultiplier, out var recorders);
    
                // initialise random source
                var ctx = new ExecutionContext(new MersenneTwister(seed, false));
    
                // run the actual experiment
                Model.RunExperiment(ctx, parameters, reporter);
    
                // produce output from recorders
                Recording.ProduceOutput(outputDirectory, parameters, recorders);
    
                // TODO: should probably do run-on solve count
            }
    
            /// <summary>
            /// Runs many experiments in parallel with the same parameters and sequential seeds.
            /// </summary>
            public static void RunRepeats(string outputDirectory, Parameters parameters, int baseSeed, int repeats, int reportingPeriodMultiplier = 1)
            {