Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/12 09:51:13 (12 years ago)
Author:
jkarder
Message:

#1331: merged r8086:8330 from trunk

Location:
branches/ScatterSearch (trunk integration)
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r8086 r8331  
    5353    [StorableConstructor]
    5454    protected SymbolicRegressionMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
    55     protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
     55    protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner)
     56      : base(original, cloner) {
     57      RegisterEventHandlers();
     58    }
    5659    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionMultiObjectiveProblem(this, cloner); }
    5760
     
    6669      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
    6770
    68       SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
    69 
     71      RegisterEventHandlers();
    7072      ConfigureGrammarSymbols();
    7173      InitializeOperators();
    7274      UpdateEstimationLimits();
     75    }
     76
     77    [StorableHook(HookType.AfterDeserialization)]
     78    private void AfterDeserialization() {
     79      RegisterEventHandlers();
     80    }
     81
     82    private void RegisterEventHandlers() {
     83      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
    7384    }
    7485
     
    8596
    8697    private void UpdateEstimationLimits() {
    87       if (ProblemData.TrainingIndizes.Any()) {
    88         var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToList();
     98      if (ProblemData.TrainingIndices.Any()) {
     99        var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList();
    89100        var mean = targetValues.Average();
    90101        var range = targetValues.Max() - targetValues.Min();
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame

    r7675 r8331  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.2.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.3.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.5")]
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties/AssemblyInfo.cs.frame

    r7259 r8331  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.2.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.3.$WCREV$")]
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r7677 r8331  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    5960    private static double[] cache;
    6061
    61     protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) {
     62    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
     63      double lowerEstimationLimit, double upperEstimationLimit,
     64      IOnlineCalculator calculator, int maxRows) {
    6265      if (cache == null || cache.GetLength(0) < maxRows) {
    6366        cache = new double[maxRows];
     
    8386      //calculate the quality by using the passed online calculator
    8487      targetValuesEnumerator = targetValues.GetEnumerator();
    85       i = 0;
    86       while (targetValuesEnumerator.MoveNext()) {
    87         double target = targetValuesEnumerator.Current;
    88         double estimated = cache[i] * beta + alpha;
    89         calculator.Add(target, estimated);
    90         i++;
     88      var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
     89        .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
     90
     91      while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
     92        calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
    9193      }
    9294    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r7677 r8331  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var maeCalculator = new OnlineMaxAbsoluteErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows);
    6564        errorState = maeCalculator.ErrorState;
    6665        mse = maeCalculator.MaxAbsoluteError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6868        mse = OnlineMaxAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     69      }
    7070      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7171      else return mse;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r7677 r8331  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var maeCalculator = new OnlineMeanAbsoluteErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows);
    6564        errorState = maeCalculator.ErrorState;
    6665        mse = maeCalculator.MeanAbsoluteError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit,
     68                                                                                  upperEstimationLimit);
    6869        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     70      }
    7071      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7172      else return mse;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7677 r8331  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
    6564        errorState = mseCalculator.ErrorState;
    6665        mse = mseCalculator.MeanSquaredError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6868        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     69      }
    7070      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7171      else return mse;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r8086 r8331  
    4949    [StorableConstructor]
    5050    protected SymbolicRegressionSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
    51     protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
     51    protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner)
     52      : base(original, cloner) {
     53      RegisterEventHandlers();
     54    }
    5255    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionSingleObjectiveProblem(this, cloner); }
    5356
     
    6265      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
    6366
    64       SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
    65 
     67      RegisterEventHandlers();
    6668      ConfigureGrammarSymbols();
    6769      InitializeOperators();
    6870      UpdateEstimationLimits();
     71    }
     72
     73    [StorableHook(HookType.AfterDeserialization)]
     74    private void AfterDeserialization() {
     75      RegisterEventHandlers();
     76      // compatibility
     77      bool changed = false;
     78      if (!Operators.OfType<SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer>().Any()) {
     79        Operators.Add(new SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer());
     80        changed = true;
     81      }
     82      if (!Operators.OfType<SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer>().Any()) {
     83        Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer());
     84        changed = true;
     85      }
     86      if (changed) {
     87        ParameterizeOperators();
     88      }
     89    }
     90
     91    private void RegisterEventHandlers() {
     92      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
    6993    }
    7094
     
    85109
    86110    private void UpdateEstimationLimits() {
    87       if (ProblemData.TrainingIndizes.Any()) {
    88         var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToList();
     111      if (ProblemData.TrainingIndices.Any()) {
     112        var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList();
    89113        var mean = targetValues.Average();
    90114        var range = targetValues.Max() - targetValues.Min();
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r7726 r8331  
    3333  [Item("SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic regression solutions for single objective symbolic regression problems.")]
    3434  [StorableClass]
    35   public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<ISymbolicRegressionSolution>,
    36   ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
    37     private const string ProblemDataParameterName = "ProblemData";
    38     private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    39     private const string EstimationLimitsParameterName = "EstimationLimits";
     35  public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IRegressionProblemData, ISymbolicRegressionSolution> {
    4036    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4137    #region parameter properties
    42     public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
    43       get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    44     }
    45     public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
    46       get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
    47     }
    48     public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    49       get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    50     }
    5138    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    5239      get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     
    6552    public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer()
    6653      : base() {
    67       Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
    68       Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    69       Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    7054      Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    7155    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r7734 r8331  
    3333  [Item("SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic regression solutions for single objective symbolic regression problems.")]
    3434  [StorableClass]
    35   public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData>,
    36   ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
    37     private const string EstimationLimitsParameterName = "EstimationLimits";
     35  public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> {
    3836    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3937    #region parameter properties
    40     public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    41       get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    42     }
    4338    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    4439      get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     
    5752    public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()
    5853      : base() {
    59       Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    6054      Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    6155    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r8086 r8331  
    7373      var dataset = problemData.Dataset;
    7474      var targetVariable = problemData.TargetVariable;
    75       var rows = problemData.TrainingIndizes;
     75      var rows = problemData.TrainingIndices;
    7676      var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);
    7777      var targetValues = dataset.GetDoubleValues(targetVariable, rows);
Note: See TracChangeset for help on using the changeset viewer.