[12892] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 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;
|
---|
[17434] | 23 | using HEAL.Attic;
|
---|
[12892] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
[10293] | 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 28 | using HeuristicLab.EvolutionTracking;
|
---|
[12892] | 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
[10293] | 31 |
|
---|
[11227] | 32 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[12892] | 33 | [Item("SymbolicDataAnalysisGenealogyAnalyzer", "Genealogy analyzer for symbolic data analysis problems")]
|
---|
[17434] | 34 | [StorableType("A3D2A9C6-D304-47F1-9F02-6ABA9A0F4428")]
|
---|
[10300] | 35 | public class SymbolicDataAnalysisGenealogyAnalyzer : GenealogyAnalyzer<ISymbolicExpressionTree> {
|
---|
[12892] | 36 | private const string EvaluatorParameterName = "Evaluator";
|
---|
| 37 | private const string ProblemDataParameterName = "ProblemData";
|
---|
| 38 | private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
| 39 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
| 40 | private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
|
---|
[11227] | 41 |
|
---|
[12892] | 42 | #region parameters
|
---|
| 43 | public ILookupParameter<ISingleObjectiveEvaluator> EvaluatorParameter {
|
---|
| 44 | get {
|
---|
| 45 | return (ILookupParameter<ISingleObjectiveEvaluator>)Parameters[EvaluatorParameterName];
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
|
---|
| 50 | get {
|
---|
| 51 | return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName];
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter {
|
---|
| 56 | get {
|
---|
| 57 | return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName];
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public ILookupParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 62 | get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
|
---|
| 66 | get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
|
---|
| 67 | }
|
---|
| 68 | #endregion
|
---|
| 69 |
|
---|
| 70 | public SymbolicDataAnalysisGenealogyAnalyzer() {
|
---|
| 71 | Parameters.Add(new LookupParameter<ISingleObjectiveEvaluator>(EvaluatorParameterName));
|
---|
| 72 | Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName));
|
---|
| 73 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName));
|
---|
| 74 | Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName));
|
---|
| 75 | Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public SymbolicDataAnalysisGenealogyAnalyzer(SymbolicDataAnalysisGenealogyAnalyzer original, Cloner cloner)
|
---|
| 79 | : base(original, cloner) {
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 83 | return new SymbolicDataAnalysisGenealogyAnalyzer(this, cloner);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[11227] | 86 | [StorableConstructor]
|
---|
[17434] | 87 | protected SymbolicDataAnalysisGenealogyAnalyzer(StorableConstructorFlag _) : base(_) {
|
---|
[12892] | 88 | }
|
---|
| 89 |
|
---|
| 90 | protected override void EvaluateIntermediateChildren() {
|
---|
| 91 | var results = ResultsParameter.ActualValue;
|
---|
| 92 | var graph = (IGenealogyGraph<ISymbolicExpressionTree>)results["PopulationGraph"].Value;
|
---|
| 93 | var population = PopulationParameter.ActualValue;
|
---|
| 94 | var generation = GenerationsParameter.ActualValue.Value;
|
---|
| 95 | var problemData = ProblemDataParameter.ActualValue;
|
---|
| 96 |
|
---|
| 97 | var vertices = population.Select(graph.GetByContent).Where(x => x.InDegree == 1).Select(x => x.Parents.First());
|
---|
| 98 | var intermediateVertices = vertices.Where(x => x.Rank.IsAlmost(generation - 0.5));
|
---|
| 99 |
|
---|
| 100 | var classificationProblemData = problemData as IClassificationProblemData;
|
---|
| 101 | var regressionProblemData = problemData as IRegressionProblemData;
|
---|
| 102 | if (classificationProblemData != null) {
|
---|
| 103 | var evaluator = (ISymbolicDataAnalysisSingleObjectiveEvaluator<IClassificationProblemData>)EvaluatorParameter.ActualValue;
|
---|
| 104 | foreach (var v in intermediateVertices) {
|
---|
| 105 | var child = v.Data;
|
---|
| 106 | v.Quality = evaluator.Evaluate(this.ExecutionContext, child, classificationProblemData, classificationProblemData.TrainingIndices);
|
---|
| 107 | }
|
---|
| 108 | } else if (regressionProblemData != null) {
|
---|
| 109 | var evaluator = (ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>)EvaluatorParameter.ActualValue;
|
---|
| 110 | foreach (var v in intermediateVertices) {
|
---|
| 111 | var child = v.Data;
|
---|
| 112 | v.Quality = evaluator.Evaluate(this.ExecutionContext, child, regressionProblemData, problemData.TrainingIndices);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[10293] | 116 | }
|
---|
| 117 | }
|
---|