Changeset 13920


Ignore:
Timestamp:
06/17/16 23:11:59 (3 years ago)
Author:
abeham
Message:

#2457: added repetitions to LocalAnalysis and computing average

Location:
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Algorithms/LocalAnalysis.cs

    r13583 r13920  
    6161      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    6262    }
     63    public IFixedValueParameter<IntValue> RepetitionsParameter {
     64      get { return (IFixedValueParameter<IntValue>)Parameters["Repetitions"]; }
     65    }
    6366    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
    6467      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     
    7073
    7174    #region Properties
    72     protected RandomCreator RandomCreator {
     75    protected RandomCreator GlobalRandomCreator {
    7376      get { return (RandomCreator)OperatorGraph.InitialOperator; }
    7477    }
     78    protected UniformSubScopesProcessor FirstUniformSubScopesProcessor {
     79      get { return (UniformSubScopesProcessor)((SubScopesCreator)GlobalRandomCreator.Successor).Successor; }
     80    }
     81    protected LocalRandomCreator IteratedRandomCreator {
     82      get { return (LocalRandomCreator)FirstUniformSubScopesProcessor.Operator; }
     83    }
    7584    protected VariableCreator VariableCreator {
    76       get { return (VariableCreator)RandomCreator.Successor; }
     85      get { return (VariableCreator)IteratedRandomCreator.Successor; }
     86    }
     87    protected UniformSubScopesProcessor SecondUniformSubScopesProcessor {
     88      get { return (UniformSubScopesProcessor)FirstUniformSubScopesProcessor.Successor; }
    7789    }
    7890    protected SolutionsCreator SolutionsCreator {
    79       get { return (SolutionsCreator)VariableCreator.Successor; }
     91      get { return (SolutionsCreator)SecondUniformSubScopesProcessor.Operator; }
    8092    }
    8193    protected LocalAnalysisMainLoop MainLoop {
     
    99111      Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    100112      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "Mutation operator."));
    101       Parameters.Add(new FixedValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(10000)));
     113      Parameters.Add(new FixedValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
     114      Parameters.Add(new FixedValueParameter<IntValue>("Repetitions", "The number of repetitions that should be performed.", new IntValue(10)));
    102115      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
    103116      Parameters.Add(new FixedValueParameter<T>("Selector", "Selection operator.", selector));
    104117
    105118      RandomCreator randomCreator = new RandomCreator();
     119      SubScopesCreator ssc = new SubScopesCreator();
     120      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
     121      UniformSubScopesProcessor ussp2 = new UniformSubScopesProcessor();
     122      LocalRandomCreator lrc = new LocalRandomCreator();
    106123      VariableCreator variableCreator = new VariableCreator();
    107124      SolutionsCreator solutionsCreator = new SolutionsCreator();
    108125      LocalAnalysisMainLoop laMainLoop = new LocalAnalysisMainLoop();
     126      ResultsCollector collector = new ResultsCollector();
     127
    109128      OperatorGraph.InitialOperator = randomCreator;
    110129
     
    114133      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
    115134      randomCreator.SetSeedRandomlyParameter.Value = null;
    116       randomCreator.Successor = variableCreator;
    117 
    118       variableCreator.Successor = solutionsCreator;
     135      randomCreator.Successor = ssc;
     136
     137      ssc.NumberOfSubScopesParameter.Value = null;
     138      ssc.NumberOfSubScopesParameter.ActualName = RepetitionsParameter.Name;
     139      ssc.Successor = ussp1;
     140
     141      ussp1.Depth = new IntValue(1);
     142      ussp1.Parallel = new BoolValue(false);
     143      ussp1.Operator = lrc;
     144      ussp1.Successor = ussp2;
     145
     146      lrc.GlobalRandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
     147      lrc.LocalRandomParameter.ActualName = "IteratedRandom";
     148      lrc.Successor = variableCreator;
     149
     150      var iterResults = new ValueParameter<ResultCollection>("IteratedResults", new ResultCollection());
     151      variableCreator.CollectedValues.Add(iterResults);
     152      variableCreator.Successor = null;
     153
     154      ussp2.Depth = new IntValue(1);
     155      ussp2.Parallel = new BoolValue(true);
     156      ussp2.Operator = solutionsCreator;
     157      ussp2.Successor = collector;
    119158
    120159      solutionsCreator.NumberOfSolutions = new IntValue(1);
     
    124163      laMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    125164      laMainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
    126       laMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    127       laMainLoop.ResultsParameter.ActualName = "Results";
     165      laMainLoop.RandomParameter.ActualName = lrc.LocalRandomParameter.ActualName;
     166      laMainLoop.ResultsParameter.ActualName = iterResults.Name;
    128167      laMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    129168
    130169      qualityTrailAnalyzer = new QualityTrailMultiAnalyzer();
    131170      qualityTrailAnalyzer.UpdateIntervalParameter.Value = null;
    132       qualityTrailAnalyzer.UpdateIntervalParameter.ActualName = "MaximumIterations";
     171      qualityTrailAnalyzer.UpdateIntervalParameter.ActualName = MaximumIterationsParameter.Name;
    133172      AnalyzerParameter.Value.Operators.Add(qualityTrailAnalyzer, true);
     173
     174      collector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IteratedResults", 1));
     175      collector.ResultsParameter.ActualName = "Results";
     176      collector.CopyValue = new BoolValue(false);
     177      collector.Successor = null;
    134178
    135179      RegisterEventHandlers();
     
    138182    public override void Prepare() {
    139183      if (Problem != null) base.Prepare();
     184    }
     185
     186    protected override void OnStopped() {
     187      var iteratedResults = Results.SingleOrDefault(x => x.Name == "IteratedResults");
     188      if (iteratedResults != null) {
     189        var rc = iteratedResults.Value as ItemArray<ResultCollection>;
     190        if (rc != null) {
     191          var results = rc.FirstOrDefault();
     192          if (results != null) {
     193            var toAvg = results.Select(x => x.Name).ToDictionary(x => x, x => 0.0);
     194            foreach (var r in rc) {
     195              foreach (var v in r) {
     196                if (!toAvg.ContainsKey(v.Name)) continue;
     197                var value = v.Value as IntValue;
     198                if (value != null) toAvg[v.Name] += value.Value;
     199                else {
     200                  var doubleValue = v.Value as DoubleValue;
     201                  if (doubleValue != null) toAvg[v.Name] += doubleValue.Value;
     202                }
     203              }
     204            }
     205
     206            foreach (var r in toAvg.Keys.OrderBy(x => x)) {
     207              Results.Add(new Result(r, new DoubleValue(toAvg[r] / RepetitionsParameter.Value.Value)));
     208            }
     209          }
     210        }
     211      }
     212      base.OnStopped();
    140213    }
    141214
     
    189262      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    190263      foreach (var sOp in Problem.Operators.OfType<IStochasticOperator>()) {
    191         sOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     264        sOp.RandomParameter.ActualName = IteratedRandomCreator.LocalRandomParameter.ActualName;
    192265      }
    193266      foreach (var iOp in Problem.Operators.OfType<IIterationBasedOperator>()) {
     
    196269      }
    197270      var sEval = Problem.Evaluator as IStochasticOperator;
    198       if (sEval != null) sEval.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     271      if (sEval != null) sEval.RandomParameter.ActualName = IteratedRandomCreator.LocalRandomParameter.ActualName;
    199272      var sCrea = Problem.SolutionCreator as IStochasticOperator;
    200       if (sCrea != null) sCrea.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     273      if (sCrea != null) sCrea.RandomParameter.ActualName = IteratedRandomCreator.LocalRandomParameter.ActualName;
    201274      var sSel = SelectorParameter.Value as IStochasticOperator;
    202       if (sSel != null) sSel.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     275      if (sSel != null) sSel.RandomParameter.ActualName = IteratedRandomCreator.LocalRandomParameter.ActualName;
    203276      var sel = SelectorParameter.Value as ISelector;
    204277      if (sel != null) {
     
    211284        }
    212285      }
     286
     287      foreach (var op in Problem.Operators.OfType<IParameterizedItem>()) {
     288        var resultsParam = op.Parameters.SingleOrDefault(x => x.Name == "Results");
     289        var lookupParam = resultsParam as ILookupParameter<ResultCollection>;
     290        if (lookupParam == null) continue;
     291        lookupParam.ActualName = "IteratedResults";
     292      }
    213293    }
    214294    #endregion
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/AdaptiveWalkCalculator.cs

    r13667 r13920  
    6767        "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent",
    6868        "PeakDensityBasinInformation" }.Select(x => new StringValue(x)));
    69       characteristics.SetItemCheckedState(1, false);
    70       characteristics.SetItemCheckedState(5, false);
    7169    }
    7270
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/RandomWalkCalculator.cs

    r13667 r13920  
    6767        "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent",
    6868        "PeakDensityBasinInformation" }.Select(x => new StringValue(x)));
    69       characteristics.SetItemCheckedState(1, false);
    70       characteristics.SetItemCheckedState(5, false);
    7169    }
    7270
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/UpDownWalkCalculator.cs

    r13667 r13920  
    6868        "PeakDensityBasinInformation", "DownWalkLength", "UpWalkLength", "UpWalkLenVar",
    6969        "DownWalkLenVar", "LowerVariance", "UpperVariance" }.Select(x => new StringValue(x)));
    70       characteristics.SetItemCheckedState(1, false);
    71       characteristics.SetItemCheckedState(5, false);
    72       characteristics.SetItemCheckedState(15, false);
    73       characteristics.SetItemCheckedState(16, false);
    7470    }
    7571
Note: See TracChangeset for help on using the changeset viewer.