[5618] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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 | using System.Linq;
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[5716] | 24 | using HeuristicLab.Data;
|
---|
| 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 (single objective)", "Represents a single objective symbolic classfication problem.")]
|
---|
| 30 | [StorableClass]
|
---|
| 31 | [Creatable("Problems")]
|
---|
[5733] | 32 | public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
|
---|
[5618] | 33 | private const double PunishmentFactor = 10;
|
---|
[5685] | 34 | private const int InitialMaximumTreeDepth = 8;
|
---|
| 35 | private const int InitialMaximumTreeLength = 25;
|
---|
| 36 | private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
|
---|
| 37 | private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
|
---|
| 38 | private const string LowerEstimationLimitParameterDescription = "The lower limit for the estimated value that can be returned by the symbolic classification model.";
|
---|
| 39 | private const string UpperEstimationLimitParameterDescription = "The upper limit for the estimated value that can be returned by the symbolic classification model.";
|
---|
[5618] | 40 |
|
---|
[5685] | 41 | #region parameter properties
|
---|
| 42 | public IFixedValueParameter<DoubleValue> LowerEstimationLimitParameter {
|
---|
| 43 | get { return (IFixedValueParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
|
---|
| 44 | }
|
---|
| 45 | public IFixedValueParameter<DoubleValue> UpperEstimationLimitParameter {
|
---|
| 46 | get { return (IFixedValueParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
|
---|
| 47 | }
|
---|
| 48 | #endregion
|
---|
| 49 | #region properties
|
---|
| 50 | public DoubleValue LowerEstimationLimit {
|
---|
| 51 | get { return LowerEstimationLimitParameter.Value; }
|
---|
| 52 | }
|
---|
| 53 | public DoubleValue UpperEstimationLimit {
|
---|
| 54 | get { return UpperEstimationLimitParameter.Value; }
|
---|
| 55 | }
|
---|
| 56 | #endregion
|
---|
[5618] | 57 | [StorableConstructor]
|
---|
| 58 | protected SymbolicClassificationSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
| 59 | protected SymbolicClassificationSingleObjectiveProblem(SymbolicClassificationSingleObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
|
---|
| 60 | public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationSingleObjectiveProblem(this, cloner); }
|
---|
| 61 |
|
---|
| 62 | public SymbolicClassificationSingleObjectiveProblem()
|
---|
| 63 | : base(new ClassificationProblemData(), new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
|
---|
[5685] | 64 | Parameters.Add(new FixedValueParameter<DoubleValue>(LowerEstimationLimitParameterName, LowerEstimationLimitParameterDescription, new DoubleValue()));
|
---|
| 65 | Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue()));
|
---|
| 66 |
|
---|
| 67 | MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
|
---|
| 68 | MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
|
---|
| 69 |
|
---|
| 70 | InitializeOperators();
|
---|
[5716] | 71 | UpdateEstimationLimits();
|
---|
[5722] | 72 | UpdateDatasetPartitions();
|
---|
[5618] | 73 | }
|
---|
| 74 |
|
---|
[5685] | 75 | private void InitializeOperators() {
|
---|
| 76 | Operators.Add(new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer());
|
---|
| 77 | Operators.Add(new SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer());
|
---|
| 78 | ParameterizeOperators();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | private void UpdateEstimationLimits() {
|
---|
[5618] | 82 | if (ProblemData.TrainingPartitionStart.Value < ProblemData.TrainingPartitionEnd.Value) {
|
---|
| 83 | var targetValues = ProblemData.Dataset.GetVariableValues(ProblemData.TargetVariable, ProblemData.TrainingPartitionStart.Value, ProblemData.TrainingPartitionEnd.Value);
|
---|
| 84 | var mean = targetValues.Average();
|
---|
| 85 | var range = targetValues.Max() - targetValues.Min();
|
---|
| 86 | UpperEstimationLimit.Value = mean + PunishmentFactor * range;
|
---|
| 87 | LowerEstimationLimit.Value = mean - PunishmentFactor * range;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[5623] | 90 |
|
---|
[5685] | 91 | protected override void OnProblemDataChanged() {
|
---|
| 92 | base.OnProblemDataChanged();
|
---|
| 93 | UpdateEstimationLimits();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | protected override void ParameterizeOperators() {
|
---|
| 97 | base.ParameterizeOperators();
|
---|
| 98 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
[5720] | 99 | foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
|
---|
[5685] | 100 | op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameterName;
|
---|
| 101 | op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameterName;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[5623] | 105 | public override void ImportProblemDataFromFile(string fileName) {
|
---|
| 106 | ClassificationProblemData problemData = ClassificationProblemData.ImportFromFile(fileName);
|
---|
| 107 | ProblemData = problemData;
|
---|
| 108 | }
|
---|
[5618] | 109 | }
|
---|
| 110 | }
|
---|