Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/12 11:18:40 (12 years ago)
Author:
mkommend
Message:

#1951:

  • Added linear scaling parameter to data analysis problems.
  • Adapted interfaces, evaluators and analyzers accordingly.
  • Added OnlineBoundedMeanSquaredErrorCalculator.
  • Adapted symbolic regression sample unit test.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs

    r7259 r8664  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualityParameter.ActualValue = new DoubleValue(quality);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     54    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     57      OnlineCalculatorError errorState;
    5858
    59       double minClassValue = problemData.ClassValues.OrderBy(x => x).First();
    60       double maxClassValue = problemData.ClassValues.OrderBy(x => x).Last();
     59      double lowestClassValue = problemData.ClassValues.OrderBy(x => x).First();
     60      double upmostClassValue = problemData.ClassValues.OrderByDescending(x => x).First();
    6161
    62       IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    63       IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    64       double errorSum = 0.0;
    65       int n = 0;
    66 
    67       // always move forward both enumerators (do not use short-circuit evaluation!)
    68       while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    69         double estimated = estimatedEnumerator.Current;
    70         double original = originalEnumerator.Current;
    71         double error = estimated - original;
    72 
    73         if (estimated < minClassValue || estimated > maxClassValue)
    74           errorSum += Math.Abs(error);
    75         else
    76           errorSum += Math.Pow(error, 2);
    77         n++;
     62      double boundedMse;
     63      if (applyLinearScaling) {
     64        var boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowestClassValue, upmostClassValue);
     65        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, boundedMseCalculator, problemData.Dataset.Rows);
     66        errorState = boundedMseCalculator.ErrorState;
     67        boundedMse = boundedMseCalculator.BoundedMeanSquaredError;
     68      } else {
     69        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     70        boundedMse = OnlineBoundedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, lowestClassValue, upmostClassValue, out errorState);
    7871      }
    79 
    80       // check if both enumerators are at the end to make sure both enumerations have the same length
    81       if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) {
    82         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    83       } else {
    84         return errorSum / n;
    85       }
     72      if (errorState != OnlineCalculatorError.None) return Double.NaN;
     73      return boundedMse;
    8674    }
    8775
     
    8977      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    9078      EstimationLimitsParameter.ExecutionContext = context;
     79      ApplyLinearScalingParameter.ExecutionContext = context;
    9180
    92       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     81      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    9382
    9483      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    9584      EstimationLimitsParameter.ExecutionContext = null;
     85      ApplyLinearScalingParameter.ExecutionContext = null;
    9686
    9787      return mse;
Note: See TracChangeset for help on using the changeset viewer.