Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisPhenotypicDiversityAnalyzer.cs @ 11997

Last change on this file since 11997 was 11997, checked in by bburlacu, 9 years ago

#2269: Removed obsolete diversity analyzer and added the new bottom-up and phenotype diversity analyzers (and similarity calculators)

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.Data;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers {
31  [Item("SymbolicDataAnalysisPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic similarity between trees")]
32  [StorableClass]
33  public class SymbolicDataAnalysisPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
34    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
35    private const string EvaluatedValuesParameterName = "EstimatedValues";
36    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
37    private const string ProblemDataParameterName = "ProblemData";
38    private const string EstimationLimitsParameterName = "EstimationLimits";
39
40    public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
41      get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
42    }
43
44    private IScopeTreeLookupParameter<DoubleArray> EvaluatedValuesParameter {
45      get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters[EvaluatedValuesParameterName]; }
46    }
47
48    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
49      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
50    }
51    public IValueLookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
52      get { return (IValueLookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
53    }
54
55    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
56      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
57    }
58
59    public SymbolicDataAnalysisPhenotypicDiversityAnalyzer() {
60      SimilarityCalculator = new PhenotypicSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" };
61
62      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees."));
63      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(EvaluatedValuesParameterName, "Intermediate estimated values to be saved in the scopes."));
64      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
65      Parameters.Add(new ValueLookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
66      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
67    }
68
69    public override IOperation Apply() {
70      var trees = SymbolicExpressionTreeParameter.ActualValue;
71      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
72      var ds = ProblemDataParameter.ActualValue.Dataset;
73      var rows = ProblemDataParameter.ActualValue.TrainingIndices;
74
75      var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray())));
76
77      EvaluatedValuesParameter.ActualValue = evaluatedValues;
78
79      return base.Apply();
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.