Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Analyzer/SymbolicVectorRegressionVariableFrequencyAnalyzer.cs @ 4087

Last change on this file since 4087 was 4056, checked in by gkronber, 14 years ago

Added new plugins for multi-variate regression. #1089

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