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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
31 | using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
|
---|
32 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
|
---|
35 | using HeuristicLab.Problems.DataAnalysis;
|
---|
36 | using HeuristicLab.Analysis;
|
---|
37 |
|
---|
38 |
|
---|
39 | namespace 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 | }
|
---|