Free cookie consent management tool by TermsFeed Policy Generator

source: branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionVariableFrequencyAnalyzer.cs @ 6406

Last change on this file since 6406 was 5863, checked in by mkommend, 14 years ago

#1418: Added NonDiscoverableType attribute to outdated analyzers.

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 System.Linq;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Problems.DataAnalysis.Symbolic;
33
34namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
35  [Item("SymbolicRegressionVariableFrequencyAnalyzer", "An operator for analyzing the variable frequencies of symbolic regression solutions given in symbolic expression tree encoding.")]
36  [StorableClass]
37  [NonDiscoverableType]
38  public sealed class SymbolicRegressionVariableFrequencyAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer {
39    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
40    private const string ProblemDataParameterName = "ProblemData";
41    private const string VariableFrequenciesParameterName = "VariableFrequencies";
42    private const string ResultsParameterName = "Results";
43
44    #region parameter properties
45    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
46      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
47    }
48    public ILookupParameter<DataTable> VariableFrequenciesParameter {
49      get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; }
50    }
51    public ILookupParameter<DataAnalysisProblemData> ProblemDataParameter {
52      get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
53    }
54    public ILookupParameter<ResultCollection> ResultsParameter {
55      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
56    }
57    #endregion
58    #region properties
59    public DataTable VariableFrequencies {
60      get { return VariableFrequenciesParameter.ActualValue; }
61      set { VariableFrequenciesParameter.ActualValue = value; }
62    }
63    #endregion
64
65    [StorableConstructor]
66    private SymbolicRegressionVariableFrequencyAnalyzer(bool deserializing) : base(deserializing) { }
67    private SymbolicRegressionVariableFrequencyAnalyzer(SymbolicRegressionVariableFrequencyAnalyzer original, Cloner cloner) : base(original, cloner) { }
68    public SymbolicRegressionVariableFrequencyAnalyzer()
69      : base() {
70      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
71      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data containing the input varaibles for the symbolic regression problem."));
72      Parameters.Add(new ValueLookupParameter<DataTable>(VariableFrequenciesParameterName, "The data table to store the variable frequencies."));
73      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored."));
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new SymbolicRegressionVariableFrequencyAnalyzer(this, cloner);
78    }
79
80    public override IOperation Apply() {
81      ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
82      DataAnalysisProblemData problemData = ProblemDataParameter.ActualValue;
83      var inputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value.Value);
84      ResultCollection results = ResultsParameter.ActualValue;
85
86      if (VariableFrequencies == null) {
87        VariableFrequencies = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.");
88        VariableFrequencies.VisualProperties.XAxisTitle = "Generation";
89        VariableFrequencies.VisualProperties.YAxisTitle = "Relative Variable Frequency";
90        // add a data row for each input variable
91        foreach (var inputVariable in inputVariables) {
92          DataRow row = new DataRow(inputVariable);
93          row.VisualProperties.StartIndexZero = true;
94          VariableFrequencies.Rows.Add(row);
95        }
96        results.Add(new Result("Variable frequencies", VariableFrequencies));
97      }
98      foreach (var pair in VariableFrequencyAnalyser.CalculateVariableFrequencies(expressions, inputVariables)) {
99        VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value);
100        results["Variable frequencies"].Value = VariableFrequencies;
101      }
102
103      return base.Apply();
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.