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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Analysis;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
|
---|
34 | [Item("SymbolicRegressionVariableFrequencyAnalyzer", "An operator for analyzing the variable frequencies of symbolic regression solutions given in symbolic expression tree encoding.")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class SymbolicRegressionVariableFrequencyAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer {
|
---|
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
|
---|
43 | public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
44 | get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
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
|
---|
57 | public DataTable VariableFrequencies {
|
---|
58 | get { return VariableFrequenciesParameter.ActualValue; }
|
---|
59 | set { VariableFrequenciesParameter.ActualValue = value; }
|
---|
60 | }
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 | [StorableConstructor]
|
---|
64 | private SymbolicRegressionVariableFrequencyAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
65 | private SymbolicRegressionVariableFrequencyAnalyzer(SymbolicRegressionVariableFrequencyAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
66 | public SymbolicRegressionVariableFrequencyAnalyzer()
|
---|
67 | : base() {
|
---|
68 | Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
|
---|
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 |
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new SymbolicRegressionVariableFrequencyAnalyzer(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public override IOperation Apply() {
|
---|
79 | ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
|
---|
80 | DataAnalysisProblemData problemData = ProblemDataParameter.ActualValue;
|
---|
81 | var inputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value.Value);
|
---|
82 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
83 |
|
---|
84 | if (VariableFrequencies == null) {
|
---|
85 | VariableFrequencies = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.");
|
---|
86 | VariableFrequencies.VisualProperties.XAxisTitle = "Generation";
|
---|
87 | VariableFrequencies.VisualProperties.YAxisTitle = "Relative Variable Frequency";
|
---|
88 | // add a data row for each input variable
|
---|
89 | foreach (var inputVariable in inputVariables) {
|
---|
90 | DataRow row = new DataRow(inputVariable);
|
---|
91 | row.VisualProperties.StartIndexZero = true;
|
---|
92 | VariableFrequencies.Rows.Add(row);
|
---|
93 | }
|
---|
94 | results.Add(new Result("Variable frequencies", VariableFrequencies));
|
---|
95 | }
|
---|
96 | foreach (var pair in VariableFrequencyAnalyser.CalculateVariableFrequencies(expressions, inputVariables)) {
|
---|
97 | VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value);
|
---|
98 | results["Variable frequencies"].Value = VariableFrequencies;
|
---|
99 | }
|
---|
100 |
|
---|
101 | return base.Apply();
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|