Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/11/10 18:39:49 (14 years ago)
Author:
gkronber
Message:

Changed R² evaluator to return 0 when the estimated values contain NaN values. #1142.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs

    r4195 r4202  
    3232using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3333using HeuristicLab.Problems.DataAnalysis.Symbolic;
     34using System;
    3435
    3536namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
     
    285286        int trainingEnd = ProblemData.TrainingSamplesEnd.Value;
    286287        IEnumerable<int> trainingRows = Enumerable.Range(trainingStart, trainingEnd - trainingStart);
    287         SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
    288           lowerEstimationLimit, upperEstimationLimit,
    289           ProblemData.Dataset, targetVariable,
    290           trainingRows, out beta, out alpha);
     288        IEnumerable<double> originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(targetVariable, trainingRows);
     289        IEnumerable<double> estimatedValues =
     290          GetBoundedValues(SymbolicExpressionTreeInterpreter.GetSymbolicExpressionTreeValues(bestTree, ProblemData.Dataset, trainingRows),
     291            lowerEstimationLimit, upperEstimationLimit);
     292
     293
     294        SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);
    291295
    292296        // scale tree for solution
     
    317321      AddValue(validationValues, bestQuality, CurrentBestValidationQualityParameterName, CurrentBestValidationQualityParameterName);
    318322      return base.Apply();
     323    }
     324
     325    private IEnumerable<double> GetBoundedValues(IEnumerable<double> values, double lowerEstimationLimit, double upperEstimationLimit) {
     326      foreach (double v in values) {
     327        if (double.IsNaN(v)) yield return upperEstimationLimit;
     328        else yield return Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, v));
     329      }
    319330    }
    320331
Note: See TracChangeset for help on using the changeset viewer.