[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 |
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[5716] | 26 | using HeuristicLab.Parameters;
|
---|
[5618] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[7805] | 28 | using HeuristicLab.Problems.Instances;
|
---|
[5618] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
|
---|
| 31 | [Item("Symbolic Regression Problem (multi objective)", "Represents a multi objective symbolic regression problem.")]
|
---|
| 32 | [StorableClass]
|
---|
| 33 | [Creatable("Problems")]
|
---|
[7805] | 34 | public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem,
|
---|
| 35 | IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
|
---|
[5618] | 36 | private const double PunishmentFactor = 10;
|
---|
[5685] | 37 | private const int InitialMaximumTreeDepth = 8;
|
---|
| 38 | private const int InitialMaximumTreeLength = 25;
|
---|
[5770] | 39 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
| 40 | private const string EstimationLimitsParameterDescription = "The lower and upper limit for the estimated value that can be returned by the symbolic regression model.";
|
---|
[5618] | 41 |
|
---|
[5685] | 42 | #region parameter properties
|
---|
[5770] | 43 | public IFixedValueParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 44 | get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
[5685] | 45 | }
|
---|
| 46 | #endregion
|
---|
[5770] | 47 |
|
---|
[5685] | 48 | #region properties
|
---|
[5770] | 49 | public DoubleLimit EstimationLimits {
|
---|
| 50 | get { return EstimationLimitsParameter.Value; }
|
---|
[5685] | 51 | }
|
---|
[5770] | 52 |
|
---|
[5685] | 53 | #endregion
|
---|
[5770] | 54 |
|
---|
[5618] | 55 | [StorableConstructor]
|
---|
| 56 | protected SymbolicRegressionMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
| 57 | protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
|
---|
| 58 | public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionMultiObjectiveProblem(this, cloner); }
|
---|
| 59 |
|
---|
| 60 | public SymbolicRegressionMultiObjectiveProblem()
|
---|
| 61 | : base(new RegressionProblemData(), new SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
|
---|
[5847] | 62 | Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
|
---|
[5685] | 63 |
|
---|
[5854] | 64 | EstimationLimitsParameter.Hidden = true;
|
---|
| 65 |
|
---|
[5742] | 66 | Maximization = new BoolArray(new bool[] { true, false });
|
---|
[5685] | 67 | MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
|
---|
| 68 | MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
|
---|
| 69 |
|
---|
[6803] | 70 | SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
|
---|
| 71 |
|
---|
| 72 | ConfigureGrammarSymbols();
|
---|
[5685] | 73 | InitializeOperators();
|
---|
[5716] | 74 | UpdateEstimationLimits();
|
---|
[5618] | 75 | }
|
---|
| 76 |
|
---|
[6803] | 77 | private void ConfigureGrammarSymbols() {
|
---|
| 78 | var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar;
|
---|
| 79 | if (grammar != null) grammar.ConfigureAsDefaultRegressionGrammar();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[5685] | 82 | private void InitializeOperators() {
|
---|
| 83 | Operators.Add(new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer());
|
---|
| 84 | Operators.Add(new SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer());
|
---|
| 85 | ParameterizeOperators();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | private void UpdateEstimationLimits() {
|
---|
[6754] | 89 | if (ProblemData.TrainingIndizes.Any()) {
|
---|
[6740] | 90 | var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToList();
|
---|
[5618] | 91 | var mean = targetValues.Average();
|
---|
| 92 | var range = targetValues.Max() - targetValues.Min();
|
---|
[5770] | 93 | EstimationLimits.Upper = mean + PunishmentFactor * range;
|
---|
| 94 | EstimationLimits.Lower = mean - PunishmentFactor * range;
|
---|
[6754] | 95 | } else {
|
---|
| 96 | EstimationLimits.Upper = double.MaxValue;
|
---|
| 97 | EstimationLimits.Lower = double.MinValue;
|
---|
[5618] | 98 | }
|
---|
| 99 | }
|
---|
[5623] | 100 |
|
---|
[5685] | 101 | protected override void OnProblemDataChanged() {
|
---|
| 102 | base.OnProblemDataChanged();
|
---|
| 103 | UpdateEstimationLimits();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | protected override void ParameterizeOperators() {
|
---|
| 107 | base.ParameterizeOperators();
|
---|
[5770] | 108 | if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
|
---|
| 109 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
| 110 | foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
|
---|
| 111 | op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
|
---|
| 112 | }
|
---|
[5685] | 113 | }
|
---|
| 114 | }
|
---|
[5618] | 115 | }
|
---|
| 116 | }
|
---|