Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2635_HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/AdjustedEvaluatedSolutionsAnalyzer.cs @ 16403

Last change on this file since 16403 was 14428, checked in by bburlacu, 8 years ago

#2635: Add analyzer for counting the AdjustedEvaluatedSolutions (according to the actual number of evaluated rows). Add option to preserve compatibility with the standard evaluator. Optimize performance.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
29using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
30
31namespace HeuristicLab.OSGAEvaluator {
32  [Item("AdjustedEvaluatedSolutionsAnalyzer", "Analyzer which aggregates the adjusted evaluated solutions count from the predictive evaluator.")]
33  [StorableClass]
34  public class AdjustedEvaluatedSolutionsAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer {
35    private const string EvaluatorParameterName = "Evaluator";
36    private const string AdjustedEvaluatedSolutionsResultName = "AdjustedEvaluatedSolutions";
37
38    public ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
39      get { return (ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
40    }
41
42    public SymbolicRegressionSingleObjectiveEvaluator Evaluator {
43      get { return EvaluatorParameter.ActualValue; }
44    }
45
46    public AdjustedEvaluatedSolutionsAnalyzer() {
47      Parameters.Add(new LookupParameter<SymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
48    }
49
50    [StorableConstructor]
51    protected AdjustedEvaluatedSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
52
53    protected AdjustedEvaluatedSolutionsAnalyzer(AdjustedEvaluatedSolutionsAnalyzer original, Cloner cloner) : base(original, cloner) { }
54
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new AdjustedEvaluatedSolutionsAnalyzer(this, cloner);
57    }
58
59    public override IOperation Apply() {
60      var evaluator = Evaluator as SymbolicRegressionSingleObjectiveOsgaEvaluator;
61
62      if (evaluator == null)
63        return base.Apply();
64
65      var results = ResultCollectionParameter.ActualValue;
66      if (!results.ContainsKey(AdjustedEvaluatedSolutionsResultName)) {
67        results.Add(new Result(AdjustedEvaluatedSolutionsResultName, new DoubleValue(0)));
68      }
69      var adjustedEvaluatedSolutions = (DoubleValue)results[AdjustedEvaluatedSolutionsResultName].Value;
70      adjustedEvaluatedSolutions.Value += evaluator.AdjustedEvaluatedSolutions;
71      evaluator.AdjustedEvaluatedSolutions = 0;
72
73      return base.Apply();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.