Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionVariableFrequencyAnalyzer.cs @ 4127

Last change on this file since 4127 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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