Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6627 was 5275, checked in by gkronber, 14 years ago

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

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