Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorAnalyzer.cs @ 15275

Last change on this file since 15275 was 15275, checked in by pkimmesw, 7 years ago

#2665 Added PlushEncoding, ZeroErrorDistributionAnalzer

File size: 5.0 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer {
2
3  using HeuristicLab.Analysis;
4  using HeuristicLab.Common;
5  using HeuristicLab.Core;
6  using HeuristicLab.Data;
7  using HeuristicLab.Operators;
8  using HeuristicLab.Optimization;
9  using HeuristicLab.Parameters;
10  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem;
12
13  /// <summary>
14  /// An operater that tracks the count of individuals with zero error on the cases
15  /// </summary>
16  [Item("IndividualZeroErrorAnalyzer", "An operater that tracks the count of individuals with zero error on the cases")]
17  [StorableClass]
18  public class IndividualZeroErrorAnalyzer : SingleSuccessorOperator, IIndividualZeroErrorAnalyzer {
19    private const string RESULTS_PARAMETER_NAME = "Results";
20    private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCase";
21
22    private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case";
23    private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population.";
24    private const string Y_AXIS_TITLE = "Count of zero error individuals";
25    private const string X_AXIS_TITLE = "Case Index";
26    private const string ROW_NAME = "Cases";
27
28    public IndividualZeroErrorAnalyzer() {
29      Parameters.Add(new LookupParameter<DataTable>(
30        INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME,
31        "The data table to store the count of individuals with zero error."));
32
33      Parameters.Add(new LookupParameter<ResultCollection>(
34        RESULTS_PARAMETER_NAME,
35        "The result collection where the symbol frequencies should be stored."));
36
37      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(
38       IntegerVectorPushProblem.CaseQualitiesScopeParameterName,
39       "The quality of every single training case for each individual."));
40    }
41
42    [StorableConstructor]
43    public IndividualZeroErrorAnalyzer(bool deserializing) : base(deserializing) { }
44
45    public IndividualZeroErrorAnalyzer(IndividualZeroErrorAnalyzer origin, Cloner cloner) : base(origin, cloner) { }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new IndividualZeroErrorAnalyzer(this, cloner);
49    }
50
51    public bool EnabledByDefault { get { return true; } }
52
53    public ILookupParameter<DataTable> IndividualZeroErrorParameter
54    {
55      get { return (ILookupParameter<DataTable>)Parameters[INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME]; }
56    }
57
58    public ILookupParameter<ResultCollection> ResultsParameter
59    {
60      get { return (ILookupParameter<ResultCollection>)Parameters[RESULTS_PARAMETER_NAME]; }
61    }
62
63    public ILookupParameter<ItemArray<DoubleArray>> CaseQualitiesParameter
64    {
65      get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[IntegerVectorPushProblem.CaseQualitiesScopeParameterName]; }
66    }
67
68    public override IOperation Apply() {
69      var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue;
70      var caseCount = caseQualitiesPerIndividual[0].Length;
71
72      var results = ResultsParameter.ActualValue;
73      var individualZeroErrorCounts = IndividualZeroErrorParameter.ActualValue;
74
75      if (individualZeroErrorCounts == null) {
76        individualZeroErrorCounts = new DataTable(
77         RESULT_PARAMETER_NAME,
78         RESULT_PARAMETER_DESCRIPTION) {
79          VisualProperties = {
80            YAxisTitle = Y_AXIS_TITLE,
81            XAxisTitle = X_AXIS_TITLE,
82            XAxisMinimumFixedValue = 0,
83            XAxisMaximumFixedValue = caseCount,
84            XAxisMaximumAuto = false,
85            XAxisMinimumAuto = false,
86          }
87        };
88
89        IndividualZeroErrorParameter.ActualValue = individualZeroErrorCounts;
90      }
91
92      if (!results.ContainsKey(RESULT_PARAMETER_NAME)) {
93        results.Add(new Result(RESULT_PARAMETER_NAME, individualZeroErrorCounts));
94      }
95
96      DataRow row;
97      if (!individualZeroErrorCounts.Rows.TryGetValue(ROW_NAME, out row)) {
98        row = new DataRow(ROW_NAME) {
99          VisualProperties = {
100              StartIndexZero = true,
101              IsVisibleInLegend = false,
102              ChartType = DataRowVisualProperties.DataRowChartType.Bars,
103            }
104        };
105
106        individualZeroErrorCounts.Rows.Add(row);
107      }
108
109      var caseCountChanged = row.Values.Count != caseCount;
110
111      if (caseCountChanged) {
112        individualZeroErrorCounts.VisualProperties.XAxisMaximumFixedValue = caseCount;
113        row.Values.Clear();
114      }
115
116      for (var i = 0; i < caseCount; i++) {
117        var count = 0;
118
119        for (var j = 0; j < caseQualitiesPerIndividual.Length; j++) {
120          var caseQuality = caseQualitiesPerIndividual[j][i];
121
122          if (caseQuality == 0.0)
123            count++;
124        }
125
126        if (caseCountChanged)
127          row.Values.Add(count);
128        else
129          row.Values[i] = count;
130      }
131
132      return base.Apply();
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.