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