diff --git a/IVMCTrim/Program.cs b/IVMCTrim/Program.cs index 5ac8b3ee911efd6af3df71ec53ab98fbd1ebd8ec..301d3d06ddf9c6ee7f0c060aaa2cad8e1e413583 100644 --- a/IVMCTrim/Program.cs +++ b/IVMCTrim/Program.cs @@ -14,12 +14,12 @@ namespace IVMCTrim class Program { // This is the entry point. - // Consult readme.md for information about how to run this program. + // Consult readme.md for additional 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. + // This code is not exemplar C#; rather, the idea is that it should be fairly easy for anyone to reimplement the model, but it should also reproduce the experiments from the paper. static void Main() { - // none of our matrices are big enough to warrent multi-threading + // none of our matrices are big enough to warrant multi-threading MathNet.Numerics.Control.UseSingleThread(); // runs a bunch of experiments with the 'standard' configuration, only varying Z @@ -279,6 +279,36 @@ namespace IVMCTrim return (double)wins.Last() / runonEpisodeCount; } + + /// <summary> + /// Runs a few episodes, recording the fitness per evolutionary step with the given sample period. + /// </summary> + /// <returns> + /// A list of <see cref="DataPoint"/> comprising the evolutionary step and fitness. + /// </returns> + public static List<DataPoint> RunTracee(Parameters parameters, Individual individual, int traceeEpisodeCount = 4, int samplePeriod = 100) + { + individual = individual.Clone(); + + // run tracee + var ctx = new ExecutionContext(new MersenneTwister(3)); // common seed (chosen so that it has a mix of cL and c0) + var env = new IvmcEnvironment(parameters.ModuleSize, parameters.ModuleCount); + + var fitnessSamples = new List<DataPoint>(); + + void sample(IvmcEnvironment _env, IndividualEvaluation stepIndividualEvaluation, int _episode, int evolutionaryStep) + { + if (evolutionaryStep % samplePeriod == 0) + fitnessSamples.Add(new DataPoint(_episode * parameters.EvolutionaryStepsPerEpisode + evolutionaryStep, stepIndividualEvaluation.Evaluation.Fitness)); + } + + for (int traceeEpisodes = 0; traceeEpisodes < traceeEpisodeCount; traceeEpisodes++) + { + Model.RunEpisode(traceeEpisodes, ctx, parameters, env, ref individual, sample); + } + + return fitnessSamples; + } } public static class Configurations @@ -930,7 +960,10 @@ namespace IVMCTrim { // report progress Console.WriteLine($"{outputDirectory}: {episode}/{parameters.TotalEpisodes} ({(double)episode / parameters.TotalEpisodes:P})\tf={evaluation.Fitness}"); + } + if (episode % (reportingPeriodMultiplier * 10000) == 0) + { // produce grn plot var grnPlot = PlotHelpers.IntegralCartesianAxes($"Episode {episode}", "row", "col"); grnPlot.Axes.Add(PlotHelpers.Gray()); @@ -938,23 +971,7 @@ namespace IVMCTrim grnPlot.ExportPdf(path($"episode{episode}.pdf"), 0.5, true); // run tracee - var ctx = new ExecutionContext(new MersenneTwister(3)); // common seed (chosen so that it has a mix of cL and C0) - var env = new IvmcEnvironment(parameters.ModuleSize, parameters.ModuleCount); - var clone = individual.Clone(); // don't want to modify the real guy - - var fitnessSamples = new List<DataPoint>(); - - void sample(IvmcEnvironment _env, IndividualEvaluation stepIndividualEvaluation, int _episode, int evolutionaryStep) - { - if (evolutionaryStep % 100 == 0) - fitnessSamples.Add(new DataPoint(_episode * parameters.EvolutionaryStepsPerEpisode + evolutionaryStep, stepIndividualEvaluation.Evaluation.Fitness)); - } - - int traceeEpisodeCount = 4; - for (int traceeEpisodes = 0; traceeEpisodes < traceeEpisodeCount; traceeEpisodes++) - { - Model.RunEpisode(traceeEpisodes, ctx, parameters, env, ref clone, sample); - } + var fitnessSamples = Model.RunTracee(parameters, individual); // plot tracee var traceePlot = PlotHelpers.LinearAxes($"Episode {episode}", "Evolutionary Step", "Fitness"); diff --git a/M4MStuff/gens.ps1 b/M4MStuff/gens.ps1 index 692728af133d9e9a1d24a4ee5da5745917743b85..b35b4e856ca7fb5133868ece8d53d200d780a4fc 100644 --- a/M4MStuff/gens.ps1 +++ b/M4MStuff/gens.ps1 @@ -9,7 +9,7 @@ It will produce some directories, each containing a spread of experiments and fi # ranges -function repeats($n) { 0..($n-1) | ForEach-Object { ,@("$_", "$_")} } +function repeats($n) { 0..($n-1) | ForEach-Object { ,@($_.ToString("00"), $_.ToString("00"))} } # funky ordering is to match the funky ordering of the runs that are used in the paper (for seed generation) (sorry) $twentyHalf = (("0.00", "000"), ("0.10", "010"), ("0.20", "020"), ("0.30", "030"), ("0.40", "040"), ("0.50", "050"), ("0.60", "060"), ("0.70", "070"), ("0.80", "080"), ("0.90", "090"), ("1.00", "100"), ("0.05", "005"), ("0.15", "015"), ("0.25", "025"), ("0.35", "035"), ("0.45", "045"), ("0.55", "055"), ("0.65", "065"), ("0.75", "075"), ("0.85", "085"), ("0.95", "095")) $one = (,("0", "0")) @@ -28,7 +28,7 @@ $repeats = repeats(4) # full batches were all 40 (CPUs per node on IRIDIS) # fixed high . .\genSpread.ps1 "FixHigh" "FixHigh" 400000 Z r Z r $one $repeats {param($x, $y) "Z=$x targetpackage=ivmc:custom targetstring=++++++++++++++++ modulesstring=4*4 ivmcvmpos=hhhh ivmcvmmos=0000 mg=0 g0string=++++++++++++++++"} $runName 100 $commonParamFile $noGen -# L2 (common super-additive; Ridge) +# L2 (common super-additive; Quadratic) . .\genSpread.ps1 "LTwo" "LTwo" 400000 Z r Z r $twentyHalf $repeats {param($x, $y) "Z=$x"} $runName 100 $commonParamFile $noGen "regfunc=l2" # MMSO (somewhat arbitrary strictly sub-additive) diff --git a/M4MStuff/paperSequences.ps1 b/M4MStuff/paperSequences.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..12aa9ddfaa3f8c2a4c523209ebea6a9edca3a1ef --- /dev/null +++ b/M4MStuff/paperSequences.ps1 @@ -0,0 +1,14 @@ +# IvmcL010Bex +. seqIvmc.ps1 Standard\Standard\StandardZ000\runsOne\r00 40000 "040k" "IvmcL010BExZ000" +. seqIvmc.ps1 Standard\Standard\StandardZ050\runsOne\r00 40000 "040k" "IvmcL010BExZ050" +. seqIvmc.ps1 Standard\Standard\StandardZ095\runsOne\r00 120000 "120k" "IvmcL010BExZ095" +. seqIvmc.ps1 Standard\Standard\StandardZ100\runsOne\r00 400000 "400k" "IvmcL010BExZ100" "400000" "1*16" + +# IvmcL010Bex Fixed G +. seqIvmc.ps1 FixHigh\FixHigh\FixHighZ0\runsOne\r00 10000 "010K" "IvmcL010BExZ000FixedG" "400000" "1*16" + +# IvmcL010Bex Perfect G +. seqIvmc.ps1 PerfectG\PerfectG\PerfectGZ000\runsOne\r00 10000 "010K" "IvmcL010BExZ000PerfectG" "400000" "1*16" + +# 204 - NoWs, non-IRIDIS run (unknown seed) +. seqIvmc \E204\E204\E204Z050\runsOne\r00 500000 "500K" "Ivmc204L800BExZ050" "500000" "20*4" \ No newline at end of file diff --git a/M4MStuff/seqIvmc.ps1 b/M4MStuff/seqIvmc.ps1 index 1de8e997c32f0c39cdfb28862aaf762be625ae43..aad0e689c6915ea058ebe2c21828b7e378c87d5a 100644 --- a/M4MStuff/seqIvmc.ps1 +++ b/M4MStuff/seqIvmc.ps1 @@ -1,10 +1,5 @@ param($dir, $end = 120000, $postfix = '120K', $prefix = "IvmcL010Z095", $simend = 120000, $huskyModules="4*4", $ivmcDownsample=500, $rebase=$true, $z2traceeStart = 18000, $z2traceeEnd = 22000, $traceeSeed = 3, $denseEpoch=15000) -<# Usage notes - - Generates lots of tasty figures for a particular experiment - -#> $baseSize = 0.3 $baseIntervalSize = 0.5 * 0.4 / $baseSize @@ -27,14 +22,13 @@ m4m -plot $wsFile fitness= regcoefs=l end=$end size=$baseSize intervalsizeh=$bas m4m -plot $wsFile fitness= huskyness=l end=$end size=$baseSize intervalsizeh=$baseIntervalSize intervalsizev=$ybaseIntervalSize format:generations=0.0E+0 title:huskyness="Module Hierarchy" legend= title= out="$dir/husky$postfix" targetlines=none downsample=50 fig=B padding="NaN;4;NaN;NaN" minpad=$commonPad maxpad=$commonPad modulesstring=$huskyModules m4m -plot $wsFile fitness=ls end=$end size=$baseSize intervalsizeh=$baseIntervalSize intervalsizev=$ybaseIntervalSize format:generations=0.0E+0 legend= title= out="$dir/fitness$postfix" targetlines=none downsample=50 start=0 fig=C padding="NaN;4;NaN;NaN" minpad=$commonPad maxpad=$commonPad m4m -plot "$dir\ivmcswitches_t.dat" end=$end size=$baseSize intervalsizeh=$baseIntervalSize intervalsizev=$ybaseIntervalSize format:x=0.0E+0 legend= title= out="$dir/ivmcswitchness$postfix" meandownsample=$ivmcDownsample title:y="Module Switches" keep=4 plottype=scatter fig=D padding="NaN;4;NaN;NaN" minpad=$commonPad maxpad=$commonPad +m4m -plot "$dir\ivmcsolves_t.dat" end=$end size=$baseSize intervalsizeh=$baseIntervalSize intervalsizev=$ybaseIntervalSize format:x=0.0E+0 legend= title= out="$dir/ivmcswitchness$postfix" meandownsample=$ivmcDownsample title:y="Freq. Max-Fit. Ph." keep=4 plottype=scatter fig=C padding="NaN;4;NaN;NaN" minpad=$commonPad maxpad=$commonPad # orange line of loathing (win-freq) special case m4m -plot "$dir\fitnessSat120000(best).dat" end=$end size=$baseSize intervalsizeh=$baseIntervalSize intervalsizev=$ybaseIntervalSize format:x=0.0E+0 legend= title= out="$dir/winfreq$postfix" meandownsample=$ivmcDownsample samplescale=100 title:y="Success Frequency" keep=1 samplethreshold=0.99 plottype=scatter fig=C padding="NaN;4;NaN;NaN" minpad=$commonPad maxpad=$commonPad m4m -plot $wsFile epoch=$end size=$baseSize intervalsize=$baseIntervalSize legend= title= out="$dir/g$postfix" forceaspect - - # tracees (new) $traceeCentre = 24000 $traceeStart = $traceeCentre - 100