Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7672


Ignore:
Timestamp:
03/30/12 10:21:21 (13 years ago)
Author:
mkommend
Message:

#1788: Prepared symbolic regression evaluators to apply linear scaling and moved to separate folder.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
1 added
1 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r7294 r7672  
    114114    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
    115115    <Compile Include="Plugin.cs" />
    116     <Compile Include="SingleObjective\SymbolicRegressionConstantOptimizationEvaluator.cs" />
     116    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionConstantOptimizationEvaluator.cs" />
    117117    <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs" />
    118118    <Compile Include="SymbolicRegressionModel.cs" />
     
    130130    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs" />
    131131    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs" />
    132     <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveEvaluator.cs" />
    133     <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" />
    134     <Compile Include="SingleObjective\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" />
     132    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveEvaluator.cs" />
     133    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" />
     134    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" />
    135135    <Compile Include="SymbolicRegressionSolution.cs" />
    136136    <None Include="HeuristicLab.snk" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r7670 r7672  
    2222
    2323using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
    2427using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2528namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     29  [StorableClass]
    2630  public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {
     31    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     32    public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
     33      get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     34    }
     35    public bool ApplyLinearScaling {
     36      get { return ApplyLinearScalingParameter.Value.Value; }
     37      set { ApplyLinearScalingParameter.Value.Value = value; }
     38    }
     39
    2740    [StorableConstructor]
    2841    protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
    29     protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner)
    30       : base(original, cloner) {
     42    protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
     43    protected SymbolicRegressionSingleObjectiveEvaluator()
     44      : base() {
     45      Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(true)));
     46      ApplyLinearScalingParameter.Hidden = true;
    3147    }
    3248
    33     protected SymbolicRegressionSingleObjectiveEvaluator() : base() { }
     49    [StorableHook(HookType.AfterDeserialization)]
     50    private void AfterDeserialization() {
     51      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     52        Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(false)));
     53        ApplyLinearScalingParameter.Hidden = true;
     54      }
     55    }
    3456  }
    3557}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7670 r7672  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    3133  [StorableClass]
    3234  public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
     35    public override bool Maximization { get { return false; } }
     36    [ThreadStatic]
     37    private static double[] estimatedValuesCache;
     38
    3339    [StorableConstructor]
    3440    protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }
     
    3945      return new SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(this, cloner);
    4046    }
    41 
    4247    public SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator() : base() { }
    43 
    44     public override bool Maximization { get { return false; } }
    4548
    4649    public override IOperation Apply() {
     
    4851      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4952
    50       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     53      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScaling);
    5154      QualityParameter.ActualValue = new DoubleValue(quality);
    5255
     
    5457    }
    5558
    56     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
     59    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5760      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5861      IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    59       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     62      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6063      OnlineCalculatorError errorState;
    61       double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState);
    62       if (errorState != OnlineCalculatorError.None) return double.NaN;
     64
     65      double mse;
     66      if (applyLinearScaling) {
     67        //int i = 0;
     68        //int rowCount = rows.Count();
     69        //if (estimatedValuesCache == null) estimatedValuesCache = new double[problemData.Dataset.Rows];
     70        //foreach (var value in boundedEstimatedValues) {
     71        //  estimatedValuesCache[i] = value;
     72        //  i++;
     73        //}
     74
     75        double alpha, beta;
     76        OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, originalValues, out alpha, out beta, out errorState);
     77        mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues.Select(value => value * beta + alpha), out errorState);
     78      } else
     79        mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues, out errorState);
     80
     81      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    6382      else return mse;
    6483    }
     
    6887      EstimationLimitsParameter.ExecutionContext = context;
    6988
    70       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
    71 
     89      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScaling);
    7290
    7391      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset for help on using the changeset viewer.