[5618] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11576] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5618] | 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 | using System.Linq;
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[5623] | 24 | using HeuristicLab.Data;
|
---|
[5716] | 25 | using HeuristicLab.Parameters;
|
---|
[5618] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
|
---|
| 29 | [Item("Symbolic Classification Problem (multi objective)", "Represents a multi objective symbolic classfication problem.")]
|
---|
| 30 | [StorableClass]
|
---|
| 31 | [Creatable("Problems")]
|
---|
[5733] | 32 | public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
|
---|
[5618] | 33 | private const double PunishmentFactor = 10;
|
---|
[5685] | 34 | private const int InitialMaximumTreeDepth = 8;
|
---|
| 35 | private const int InitialMaximumTreeLength = 25;
|
---|
[5770] | 36 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
| 37 | private const string EstimationLimitsParameterDescription = "The lower and upper limit for the estimated value that can be returned by the symbolic classification model.";
|
---|
[8594] | 38 | private const string ModelCreatorParameterName = "ModelCreator";
|
---|
[5618] | 39 |
|
---|
[8594] | 40 |
|
---|
[5685] | 41 | #region parameter properties
|
---|
[5770] | 42 | public IFixedValueParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 43 | get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
[5685] | 44 | }
|
---|
[8594] | 45 | public IValueParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
|
---|
| 46 | get { return (IValueParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
|
---|
| 47 | }
|
---|
[5685] | 48 | #endregion
|
---|
| 49 | #region properties
|
---|
[5770] | 50 | public DoubleLimit EstimationLimits {
|
---|
| 51 | get { return EstimationLimitsParameter.Value; }
|
---|
[5685] | 52 | }
|
---|
[8594] | 53 | public ISymbolicClassificationModelCreator ModelCreator {
|
---|
| 54 | get { return ModelCreatorParameter.Value; }
|
---|
| 55 | }
|
---|
[5685] | 56 | #endregion
|
---|
[5618] | 57 | [StorableConstructor]
|
---|
| 58 | protected SymbolicClassificationMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
[8175] | 59 | protected SymbolicClassificationMultiObjectiveProblem(SymbolicClassificationMultiObjectiveProblem original, Cloner cloner)
|
---|
| 60 | : base(original, cloner) {
|
---|
| 61 | RegisterEventHandlers();
|
---|
| 62 | }
|
---|
[5618] | 63 | public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationMultiObjectiveProblem(this, cloner); }
|
---|
| 64 |
|
---|
| 65 | public SymbolicClassificationMultiObjectiveProblem()
|
---|
| 66 | : base(new ClassificationProblemData(), new SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
|
---|
[5847] | 67 | Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
|
---|
[8594] | 68 | Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
|
---|
[5685] | 69 |
|
---|
[8664] | 70 | ApplyLinearScalingParameter.Value.Value = false;
|
---|
[5854] | 71 | EstimationLimitsParameter.Hidden = true;
|
---|
| 72 |
|
---|
[5623] | 73 | Maximization = new BoolArray(new bool[] { false, false });
|
---|
[5685] | 74 | MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
|
---|
| 75 | MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
|
---|
| 76 |
|
---|
[6803] | 77 |
|
---|
[8175] | 78 | RegisterEventHandlers();
|
---|
[6803] | 79 | ConfigureGrammarSymbols();
|
---|
[5685] | 80 | InitializeOperators();
|
---|
[5716] | 81 | UpdateEstimationLimits();
|
---|
[5618] | 82 | }
|
---|
| 83 |
|
---|
[8175] | 84 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 85 | private void AfterDeserialization() {
|
---|
[8883] | 86 | // BackwardsCompatibility3.4
|
---|
| 87 | #region Backwards compatible code, remove with 3.5
|
---|
[8594] | 88 | if (!Parameters.ContainsKey(ModelCreatorParameterName))
|
---|
| 89 | Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
|
---|
[8883] | 90 | #endregion
|
---|
[8175] | 91 | RegisterEventHandlers();
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | private void RegisterEventHandlers() {
|
---|
| 95 | SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
|
---|
[8594] | 96 | ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators();
|
---|
[8175] | 97 | }
|
---|
| 98 |
|
---|
[6803] | 99 | private void ConfigureGrammarSymbols() {
|
---|
| 100 | var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar;
|
---|
| 101 | if (grammar != null) grammar.ConfigureAsDefaultClassificationGrammar();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[5685] | 104 | private void InitializeOperators() {
|
---|
| 105 | Operators.Add(new SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer());
|
---|
| 106 | Operators.Add(new SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer());
|
---|
| 107 | ParameterizeOperators();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | private void UpdateEstimationLimits() {
|
---|
[8139] | 111 | if (ProblemData.TrainingIndices.Any()) {
|
---|
| 112 | var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList();
|
---|
[5618] | 113 | var mean = targetValues.Average();
|
---|
| 114 | var range = targetValues.Max() - targetValues.Min();
|
---|
[5770] | 115 | EstimationLimits.Upper = mean + PunishmentFactor * range;
|
---|
| 116 | EstimationLimits.Lower = mean - PunishmentFactor * range;
|
---|
[6754] | 117 | } else {
|
---|
| 118 | EstimationLimits.Upper = double.MaxValue;
|
---|
| 119 | EstimationLimits.Lower = double.MinValue;
|
---|
[5618] | 120 | }
|
---|
| 121 | }
|
---|
[5623] | 122 |
|
---|
[5685] | 123 | protected override void OnProblemDataChanged() {
|
---|
| 124 | base.OnProblemDataChanged();
|
---|
| 125 | UpdateEstimationLimits();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[8594] | 128 | protected override void ParameterizeOperators() {
|
---|
[5685] | 129 | base.ParameterizeOperators();
|
---|
[5770] | 130 | if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
|
---|
| 131 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
[8594] | 132 | foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>())
|
---|
| 133 | op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
|
---|
| 134 | foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>())
|
---|
| 135 | op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name;
|
---|
[5685] | 136 | }
|
---|
| 137 | }
|
---|
[5618] | 138 | }
|
---|
| 139 | }
|
---|