[11145] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
[12009] | 4 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11145] | 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System.Linq;
|
---|
[10469] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
|
---|
| 31 | [StorableClass]
|
---|
| 32 | [Item("SymbolicClassificationPruningOperator", "An operator which prunes symbolic classificaton trees.")]
|
---|
| 33 | public class SymbolicClassificationPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
|
---|
| 34 | private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
|
---|
| 35 | private const string ModelCreatorParameterName = "ModelCreator";
|
---|
| 36 |
|
---|
| 37 | #region parameter properties
|
---|
| 38 | public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
|
---|
| 39 | get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
|
---|
| 40 | }
|
---|
| 41 | #endregion
|
---|
| 42 |
|
---|
| 43 | protected SymbolicClassificationPruningOperator(SymbolicClassificationPruningOperator original, Cloner cloner)
|
---|
| 44 | : base(original, cloner) {
|
---|
| 45 | }
|
---|
[11145] | 46 |
|
---|
[10469] | 47 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 48 | return new SymbolicClassificationPruningOperator(this, cloner);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | [StorableConstructor]
|
---|
| 52 | protected SymbolicClassificationPruningOperator(bool deserializing) : base(deserializing) { }
|
---|
| 53 |
|
---|
| 54 | public SymbolicClassificationPruningOperator() {
|
---|
| 55 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, new SymbolicClassificationSolutionImpactValuesCalculator()));
|
---|
| 56 | Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName));
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override ISymbolicDataAnalysisModel CreateModel() {
|
---|
[11145] | 60 | var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper);
|
---|
[10469] | 61 | var problemData = (IClassificationProblemData)ProblemData;
|
---|
[11145] | 62 | var rows = problemData.TrainingIndices;
|
---|
[10469] | 63 | model.RecalculateModelParameters(problemData, rows);
|
---|
| 64 | return model;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | protected override double Evaluate(IDataAnalysisModel model) {
|
---|
| 68 | var classificationModel = (IClassificationModel)model;
|
---|
| 69 | var classificationProblemData = (IClassificationProblemData)ProblemData;
|
---|
[11145] | 70 | var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
|
---|
[10469] | 71 | var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices);
|
---|
| 72 | var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices);
|
---|
| 73 | OnlineCalculatorError errorState;
|
---|
[11145] | 74 | var quality = OnlineAccuracyCalculator.Calculate(targetValues, estimatedValues, out errorState);
|
---|
[10469] | 75 | if (errorState != OnlineCalculatorError.None) return double.NaN;
|
---|
| 76 | return quality;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|