#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { [Item("Symbolic Regression Problem (multi objective)", "Represents a multi objective symbolic regression problem.")] [StorableClass] [Creatable("Problems")] public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem, IRegressionProblem { private const double PunishmentFactor = 10; private const int InitialMaximumTreeDepth = 8; private const int InitialMaximumTreeLength = 25; private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; private const string LowerEstimationLimitParameterDescription = "The lower limit for the estimated value that can be returned by the symbolic regression model."; private const string UpperEstimationLimitParameterDescription = "The upper limit for the estimated value that can be returned by the symbolic regression model."; #region parameter properties public IFixedValueParameter LowerEstimationLimitParameter { get { return (IFixedValueParameter)Parameters[LowerEstimationLimitParameterName]; } } public IFixedValueParameter UpperEstimationLimitParameter { get { return (IFixedValueParameter)Parameters[UpperEstimationLimitParameterName]; } } #endregion #region properties public DoubleValue LowerEstimationLimit { get { return LowerEstimationLimitParameter.Value; } } public DoubleValue UpperEstimationLimit { get { return UpperEstimationLimitParameter.Value; } } #endregion [StorableConstructor] protected SymbolicRegressionMultiObjectiveProblem(bool deserializing) : base(deserializing) { } protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionMultiObjectiveProblem(this, cloner); } public SymbolicRegressionMultiObjectiveProblem() : base(new RegressionProblemData(), new SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) { Parameters.Add(new FixedValueParameter(LowerEstimationLimitParameterName, LowerEstimationLimitParameterDescription, new DoubleValue())); Parameters.Add(new FixedValueParameter(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue())); Maximization = new BoolArray(new bool[] { true, false }); MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth; MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; InitializeOperators(); UpdateEstimationLimits(); } private void InitializeOperators() { Operators.Add(new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer()); Operators.Add(new SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer()); ParameterizeOperators(); } private void UpdateEstimationLimits() { if (ProblemData.TrainingPartition.Start < ProblemData.TrainingPartition.End) { var targetValues = ProblemData.Dataset.GetVariableValues(ProblemData.TargetVariable, ProblemData.TrainingPartition.Start, ProblemData.TrainingPartition.End); var mean = targetValues.Average(); var range = targetValues.Max() - targetValues.Min(); UpperEstimationLimit.Value = mean + PunishmentFactor * range; LowerEstimationLimit.Value = mean - PunishmentFactor * range; } } protected override void OnProblemDataChanged() { base.OnProblemDataChanged(); UpdateEstimationLimits(); } protected override void ParameterizeOperators() { base.ParameterizeOperators(); var operators = Parameters.OfType().Select(p => p.Value).OfType().Union(Operators); foreach (var op in operators.OfType()) { op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameterName; op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameterName; } } public override void ImportProblemDataFromFile(string fileName) { RegressionProblemData problemData = RegressionProblemData.ImportFromFile(fileName); ProblemData = problemData; } } }