[5618] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 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.";
|
---|
[8660] | 38 | private const string ModelCreatorParameterName = "ModelCreator";
|
---|
[5618] | 39 |
|
---|
[8660] | 40 |
|
---|
[5685] | 41 | #region parameter properties
|
---|
[5770] | 42 | public IFixedValueParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 43 | get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
[5685] | 44 | }
|
---|
[8660] | 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 | }
|
---|
[8660] | 53 | public ISymbolicClassificationModelCreator ModelCreator {
|
---|
| 54 | get { return ModelCreatorParameter.Value; }
|
---|
| 55 | }
|
---|
[5685] | 56 | #endregion
|
---|
[5618] | 57 | [StorableConstructor]
|
---|
| 58 | protected SymbolicClassificationMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
[8206] | 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));
|
---|
[8660] | 68 | Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
|
---|
[5685] | 69 |
|
---|
[5854] | 70 | EstimationLimitsParameter.Hidden = true;
|
---|
| 71 |
|
---|
[5623] | 72 | Maximization = new BoolArray(new bool[] { false, false });
|
---|
[5685] | 73 | MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
|
---|
| 74 | MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
|
---|
| 75 |
|
---|
[6803] | 76 |
|
---|
[8206] | 77 | RegisterEventHandlers();
|
---|
[6803] | 78 | ConfigureGrammarSymbols();
|
---|
[5685] | 79 | InitializeOperators();
|
---|
[5716] | 80 | UpdateEstimationLimits();
|
---|
[5618] | 81 | }
|
---|
| 82 |
|
---|
[8206] | 83 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 84 | private void AfterDeserialization() {
|
---|
[8660] | 85 | if (!Parameters.ContainsKey(ModelCreatorParameterName))
|
---|
| 86 | Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
|
---|
[8206] | 87 | RegisterEventHandlers();
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | private void RegisterEventHandlers() {
|
---|
| 91 | SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
|
---|
[8660] | 92 | ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators();
|
---|
[8206] | 93 | }
|
---|
| 94 |
|
---|
[6803] | 95 | private void ConfigureGrammarSymbols() {
|
---|
| 96 | var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar;
|
---|
| 97 | if (grammar != null) grammar.ConfigureAsDefaultClassificationGrammar();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[5685] | 100 | private void InitializeOperators() {
|
---|
| 101 | Operators.Add(new SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer());
|
---|
| 102 | Operators.Add(new SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer());
|
---|
| 103 | ParameterizeOperators();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void UpdateEstimationLimits() {
|
---|
[8206] | 107 | if (ProblemData.TrainingIndices.Any()) {
|
---|
| 108 | var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList();
|
---|
[5618] | 109 | var mean = targetValues.Average();
|
---|
| 110 | var range = targetValues.Max() - targetValues.Min();
|
---|
[5770] | 111 | EstimationLimits.Upper = mean + PunishmentFactor * range;
|
---|
| 112 | EstimationLimits.Lower = mean - PunishmentFactor * range;
|
---|
[6754] | 113 | } else {
|
---|
| 114 | EstimationLimits.Upper = double.MaxValue;
|
---|
| 115 | EstimationLimits.Lower = double.MinValue;
|
---|
[5618] | 116 | }
|
---|
| 117 | }
|
---|
[5623] | 118 |
|
---|
[5685] | 119 | protected override void OnProblemDataChanged() {
|
---|
| 120 | base.OnProblemDataChanged();
|
---|
| 121 | UpdateEstimationLimits();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[8660] | 124 | protected override void ParameterizeOperators() {
|
---|
[5685] | 125 | base.ParameterizeOperators();
|
---|
[5770] | 126 | if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
|
---|
| 127 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
[8660] | 128 | foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>())
|
---|
| 129 | op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
|
---|
| 130 | foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>())
|
---|
| 131 | op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name;
|
---|
[5685] | 132 | }
|
---|
| 133 | }
|
---|
[5618] | 134 | }
|
---|
| 135 | }
|
---|