Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5894


Ignore:
Timestamp:
03/30/11 18:04:03 (14 years ago)
Author:
gkronber
Message:

#1453: Added an ErrorState property to online evaluators to indicate if the result value is valid or if there has been an error in the calculation. Adapted all classes that use one of the online evaluators to check this property.

Location:
trunk/sources
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs

    r5809 r5894  
    8484      var classifier = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter);
    8585      classifier.SetThresholdsAndClassValues(thresholds, classValues);
    86       double originalAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows));
     86      OnlineEvaluatorError errorState;
     87      double originalAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows), out errorState);
     88      if (errorState != OnlineEvaluatorError.None) originalAccuracy = 0.0;
    8789
    8890      foreach (ISymbolicExpressionTreeNode node in nodes) {
     
    9799        classifier = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter);
    98100        classifier.SetThresholdsAndClassValues(thresholds, classValues);
    99         double newAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows));
     101        double newAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows), out errorState);
     102        if (errorState != OnlineEvaluatorError.None) newAccuracy = 0.0;
    100103
    101104        // impact = 0 if no change
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r5851 r5894  
    5858      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    5959      IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    60       double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues);
     60      OnlineEvaluatorError errorState;
     61      double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState);
     62      if (errorState != OnlineEvaluatorError.None) mse = double.NaN;
    6163      return new double[2] { mse, solution.Length };
    6264    }
     
    7274      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7375      EstimationLimitsParameter.ExecutionContext = null;
    74       EvaluatedNodesParameter.ExecutionContext = null; 
     76      EvaluatedNodesParameter.ExecutionContext = null;
    7577
    7678      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r5851 r5894  
    3737      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    3838      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    39       double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
    40       return new double[] { double.IsNaN(r2) ? 0.0 : r2, solution.Length };
     39      OnlineEvaluatorError errorState;
     40      double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState);
     41      if (errorState != OnlineEvaluatorError.None) r2 = 0.0;
     42      return new double[] { r2, solution.Length };
     43
    4144    }
    4245
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs

    r5851 r5894  
    6363      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    6464      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    65       OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
    6665      double errorSum = 0.0;
    6766      int n = 0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs

    r5851 r5894  
    5858      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    5959      IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    60       return OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues);
     60      OnlineEvaluatorError errorState;
     61      double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState);
     62      if (errorState != OnlineEvaluatorError.None) return double.NaN;
     63      else return mse;
    6164    }
    6265
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs

    r5851 r5894  
    5858      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5959      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    60       double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
    61       return double.IsNaN(r2) ? 0.0 : r2;
     60      OnlineEvaluatorError errorState;
     61      double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState);
     62      if (errorState != OnlineEvaluatorError.None) return 0.0;
     63      else return r2;
    6264    }
    6365
     
    7274      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7375      EstimationLimitsParameter.ExecutionContext = null;
    74       EvaluatedNodesParameter.ExecutionContext = null; 
     76      EvaluatedNodesParameter.ExecutionContext = null;
    7577
    7678      return r2;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r5818 r5894  
    124124      double alpha;
    125125      double beta;
    126       OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta);
     126      OnlineEvaluatorError errorState;
     127      OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState);
     128      if (errorState != OnlineEvaluatorError.None) return;
    127129
    128130      ConstantTreeNode alphaTreeNode = null;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r5818 r5894  
    7878        .ToArray();
    7979      var targetValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
    80 
    81       double originalR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, originalOutput);
     80      OnlineEvaluatorError errorState;
     81      double originalR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, originalOutput, out errorState);
     82      if (errorState != OnlineEvaluatorError.None) originalR2 = 0.0;
    8283
    8384      foreach (ISymbolicExpressionTreeNode node in nodes) {
     
    8788        SwitchNode(parent, node, replacementNode);
    8889        var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    89         double newR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, newOutput);
     90        double newR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, newOutput, out errorState);
     91        if (errorState != OnlineEvaluatorError.None) newR2 = 0.0;
    9092
    9193        // impact = 0 if no change
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r5851 r5894  
    5858      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    5959      IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    60       double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues);
     60      OnlineEvaluatorError errorState;
     61      double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState);
     62      if (errorState != OnlineEvaluatorError.None) mse = double.NaN;
    6163      return new double[2] { mse, solution.Length };
    6264    }
     
    7274      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7375      EstimationLimitsParameter.ExecutionContext = null;
    74       EvaluatedNodesParameter.ExecutionContext = null; 
     76      EvaluatedNodesParameter.ExecutionContext = null;
    7577
    7678      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r5851 r5894  
    5858      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5959      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    60       double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
    61       return new double[] { double.IsNaN(r2) ? 0.0 : r2, solution.Length };
     60      OnlineEvaluatorError errorState;
     61      double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState);
     62      if (errorState != OnlineEvaluatorError.None) r2 = 0.0;
     63      return new double[] { r2, solution.Length };
    6264    }
    6365
     
    7274      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7375      EstimationLimitsParameter.ExecutionContext = null;
    74       EvaluatedNodesParameter.ExecutionContext = null; 
     76      EvaluatedNodesParameter.ExecutionContext = null;
    7577
    7678      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r5851 r5894  
    6060      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    6161      IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    62       return OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues);
     62      OnlineEvaluatorError errorState;
     63      double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState);
     64      if (errorState != OnlineEvaluatorError.None) return double.NaN;
     65      else return mse;
    6366    }
    6467
     
    7477      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7578      EstimationLimitsParameter.ExecutionContext = null;
    76       EvaluatedNodesParameter.ExecutionContext = null; 
     79      EvaluatedNodesParameter.ExecutionContext = null;
    7780
    7881      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r5851 r5894  
    6060      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    6161      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
    62       double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
    63       return double.IsNaN(r2) ? 0.0 : r2;
     62      OnlineEvaluatorError errorState;
     63      double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState);
     64      if (errorState != OnlineEvaluatorError.None) return 0.0;
     65      else return r2;
    6466    }
    6567
     
    7476      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7577      EstimationLimitsParameter.ExecutionContext = null;
    76       EvaluatedNodesParameter.ExecutionContext = null; 
     78      EvaluatedNodesParameter.ExecutionContext = null;
    7779
    7880      return r2;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r5818 r5894  
    7575      double alpha;
    7676      double beta;
    77       OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta);
     77      OnlineEvaluatorError errorState;
     78      OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState);
     79      if (errorState != OnlineEvaluatorError.None) return;
    7880
    7981      ConstantTreeNode alphaTreeNode = null;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r5809 r5894  
    208208          var variableTreeNode = instr.dynamicNode as VariableTreeNode;
    209209          instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
    210           code[i] = instr;
     210          instr.dArg0 = variableTreeNode.Weight;
    211211        } else if (instr.opCode == OpCodes.LagVariable) {
    212212          var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode;
    213213          instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
    214           code[i] = instr;
     214          instr.dArg0 = variableTreeNode.Weight;
    215215        } else if (instr.opCode == OpCodes.VariableCondition) {
    216216          var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode;
    217217          instr.iArg0 = (ushort)dataset.GetVariableIndex(variableConditionTreeNode.VariableName);
     218          instr.dArg0 = variableConditionTreeNode.Threshold;
     219        } else if (instr.opCode == OpCodes.Constant) {
     220          var constTreeNode = instr.dynamicNode as ConstantTreeNode;
     221          instr.dArg0 = constTreeNode.Value;
    218222        }
    219223      }
     
    408412          }
    409413        case OpCodes.Variable: {
    410             var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode;
    411             return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight;
     414            return dataset[row, currentInstr.iArg0] * currentInstr.dArg0;
    412415          }
    413416        case OpCodes.LagVariable: {
     
    415418            int actualRow = row + laggedVariableTreeNode.Lag;
    416419            if (actualRow < 0 || actualRow >= dataset.Rows) throw new ArgumentException("Out of range access to dataset row: " + row);
    417             return dataset[actualRow, currentInstr.iArg0] * laggedVariableTreeNode.Weight;
     420            return dataset[actualRow, currentInstr.iArg0] * currentInstr.dArg0;
    418421          }
    419422        case OpCodes.Constant: {
    420             var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode;
    421             return constTreeNode.Value;
     423            return currentInstr.dArg0;
    422424          }
    423425
     
    427429            var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode;
    428430            double variableValue = dataset[row, currentInstr.iArg0];
    429             double x = variableValue - variableConditionTreeNode.Threshold;
     431            double x = variableValue - currentInstr.dArg0;
    430432            double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
    431433
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs

    r5809 r5894  
    8585      IEnumerable<double> originalTestClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
    8686
    87       double trainingAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues);
    88       double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues);
     87      OnlineEvaluatorError errorState;
     88      double trainingAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues, out errorState);
     89      if (errorState != OnlineEvaluatorError.None) trainingAccuracy = double.NaN;
     90      double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues, out errorState);
     91      if (errorState != OnlineEvaluatorError.None) testAccuracy = double.NaN;
    8992
    9093      TrainingAccuracy = trainingAccuracy;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs

    r5889 r5894  
    105105      IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
    106106
    107       double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues);
    108       double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues);
    109       double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues);
    110       double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues);
     107      OnlineEvaluatorError errorState;
     108      double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     109      TrainingMeanSquaredError = errorState == OnlineEvaluatorError.None ? trainingMSE : double.NaN;
     110      double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     111      TestMeanSquaredError = errorState == OnlineEvaluatorError.None ? testMSE : double.NaN;
    111112
    112       TrainingMeanSquaredError = trainingMSE;
    113       TestMeanSquaredError = testMSE;
    114       TrainingRSquared = trainingR2;
    115       TestRSquared = testR2;
     113      double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     114      TrainingRSquared = errorState == OnlineEvaluatorError.None ? trainingR2 : double.NaN;
     115      double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     116      TestRSquared = errorState == OnlineEvaluatorError.None ? testR2 : double.NaN;
    116117    }
    117118
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs

    r5849 r5894  
    6464        double classValue = group.Key;
    6565        double mean, variance;
    66         OnlineMeanAndVarianceCalculator.Calculate(estimatedClassValues, out mean, out variance);
    67         classMean[classValue] = mean;
    68         classStdDev[classValue] = Math.Sqrt(variance);
     66        OnlineEvaluatorError meanErrorState, varianceErrorState;
     67        OnlineMeanAndVarianceCalculator.Calculate(estimatedClassValues, out mean, out variance, out meanErrorState, out varianceErrorState);
     68
     69        if (meanErrorState == OnlineEvaluatorError.None && varianceErrorState == OnlineEvaluatorError.None) {
     70          classMean[classValue] = mean;
     71          classStdDev[classValue] = Math.Sqrt(variance);
     72        }
    6973      }
    7074      double[] originalClasses = classMean.Keys.OrderBy(x => x).ToArray();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r5809 r5894  
    114114      IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
    115115
    116       double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues);
    117       double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues);
    118       double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues);
    119       double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues);
    120       double trainingRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues);
    121       double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues);
     116      OnlineEvaluatorError errorState;
     117      double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     118      TrainingMeanSquaredError = errorState == OnlineEvaluatorError.None ? trainingMSE : double.NaN;
     119      double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     120      TestMeanSquaredError = errorState == OnlineEvaluatorError.None ? testMSE : double.NaN;
    122121
    123       TrainingMeanSquaredError = trainingMSE;
    124       TestMeanSquaredError = testMSE;
    125       TrainingRSquared = trainingR2;
    126       TestRSquared = testR2;
    127       TrainingRelativeError = trainingRelError;
    128       TestRelativeError = testRelError;
     122      double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     123      TrainingRSquared = errorState == OnlineEvaluatorError.None ? trainingR2 : double.NaN;
     124      double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     125      TestRSquared = errorState == OnlineEvaluatorError.None ? testR2 : double.NaN;
     126
     127      double trainingRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     128      TrainingRelativeError = errorState == OnlineEvaluatorError.None ? trainingRelError : double.NaN;
     129      double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     130      TestRelativeError = errorState == OnlineEvaluatorError.None ? testRelError : double.NaN;
    129131    }
    130132
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineEvaluator.cs

    r5809 r5894  
    2121
    2222
     23using System;
    2324namespace HeuristicLab.Problems.DataAnalysis {
     25  [Flags]
     26  public enum OnlineEvaluatorError {
     27    /// <summary>
     28    /// No error occurred
     29    /// </summary>
     30    None = 0,
     31    /// <summary>
     32    /// An invalid value has been added (often +/- Infinity and NaN are invalid values)
     33    /// </summary>
     34    InvalidValueAdded = 1,
     35    /// <summary>
     36    /// The number of elements added to the evaluator is not sufficient to calculate the result value
     37    /// </summary>
     38    InsufficientElementsAdded = 2
     39  }
    2440  public interface IOnlineEvaluator {
     41    OnlineEvaluatorError ErrorState { get; }
    2542    double Value { get; }
    2643    void Reset();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineAccuracyEvaluator.cs

    r5809 r5894  
    3131    public double Accuracy {
    3232      get {
    33         if (n < 1)
    34           throw new InvalidOperationException("No elements");
    35         else
    36           return correctlyClassified / (double)n;
     33        return correctlyClassified / (double)n;
    3734      }
    3835    }
     
    4340
    4441    #region IOnlineEvaluator Members
     42    private OnlineEvaluatorError errorState;
     43    public OnlineEvaluatorError ErrorState {
     44      get { return errorState; }
     45    }
    4546    public double Value {
    4647      get { return Accuracy; }
     
    4950      n = 0;
    5051      correctlyClassified = 0;
     52      errorState = OnlineEvaluatorError.InsufficientElementsAdded;
    5153    }
    5254
    5355    public void Add(double original, double estimated) {
    54       if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    55           double.IsNaN(original) || double.IsInfinity(original)) {
    56         throw new ArgumentException("Accuracy is not defined for NaN or infinity elements");
    57       } else {
    58         if (original.IsAlmost(estimated)) correctlyClassified++;
     56      // ignore cases where original is NaN completly
     57      if (!double.IsNaN(original)) {
     58        // increment number of observed samples
    5959        n++;
     60        if (original.IsAlmost(estimated)) {
     61          // original = estimated = +Inf counts as correctly classified
     62          // original = estimated = -Inf counts as correctly classified
     63          correctlyClassified++;
     64        }
     65        errorState = OnlineEvaluatorError.None; // number of (non-NaN) samples >= 1
    6066      }
    6167    }
    6268    #endregion
    6369
    64     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     70    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    6571      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6672      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    7884        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    7985      } else {
     86        errorState = accuracyEvaluator.ErrorState;
    8087        return accuracyEvaluator.Accuracy;
    8188      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineCovarianceEvaluator.cs

    r5845 r5894  
    3939
    4040    #region IOnlineEvaluator Members
     41    private OnlineEvaluatorError errorState;
     42    public OnlineEvaluatorError ErrorState {
     43      get { return errorState; }
     44    }
    4145    public double Value {
    4246      get { return Covariance; }
     
    4751      originalMean = 0.0;
    4852      estimatedMean = 0.0;
     53      errorState = OnlineEvaluatorError.InsufficientElementsAdded;
    4954    }
    5055
    5156    public void Add(double original, double estimated) {
    52       if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    53           double.IsNaN(original) || double.IsInfinity(original) ||
    54          double.IsNaN(Cn)) {
    55         Cn = double.NaN;
    56       } else {
     57      if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original)) {
     58        errorState = errorState | OnlineEvaluatorError.InvalidValueAdded;
     59      } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) {
    5760        n++;
     61        errorState = OnlineEvaluatorError.None;        // n >= 1
     62
    5863        // online calculation of tMean
    5964        originalMean = originalMean + (original - originalMean) / n;
     
    6772    #endregion
    6873
    69     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     74    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    7075      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    7176      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    8388        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    8489      } else {
     90        errorState = covarianceEvaluator.ErrorState;
    8591        return covarianceEvaluator.Covariance;
    8692      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineLinearScalingParameterCalculator.cs

    r5818 r5894  
    3232    public double Alpha {
    3333      get {
    34         if (cnt < 2)
    35           return 0;
    36         else
    37           return targetMeanCalculator.Mean - Beta * originalMeanAndVarianceCalculator.Mean;
     34        return targetMeanCalculator.Mean - Beta * originalMeanAndVarianceCalculator.Mean;
    3835      }
    3936    }
     
    4441    public double Beta {
    4542      get {
    46         if (cnt < 2)
    47           return 1;
    48         else if (originalMeanAndVarianceCalculator.PopulationVariance.IsAlmost(0.0))
     43        if (originalMeanAndVarianceCalculator.PopulationVariance.IsAlmost(0.0))
    4944          return 1;
    5045        else
    5146          return originalTargetCovarianceEvaluator.Covariance / originalMeanAndVarianceCalculator.PopulationVariance;
     47      }
     48    }
     49
     50    public OnlineEvaluatorError ErrorState {
     51      get {
     52        return targetMeanCalculator.MeanErrorState | originalMeanAndVarianceCalculator.MeanErrorState |
     53          originalMeanAndVarianceCalculator.PopulationVarianceErrorState | originalTargetCovarianceEvaluator.ErrorState;
    5254      }
    5355    }
     
    9496    /// <param name="alpha">Additive constant for the linear scaling</param>
    9597    /// <param name="beta">Multiplicative factor for the linear scaling</param>
    96     public static void Calculate(IEnumerable<double> original, IEnumerable<double> target, out double alpha, out double beta) {
     98    /// <param name="errorState">Flag that indicates if errors occurred in the calculation of the linea scaling parameters.</param>
     99    public static void Calculate(IEnumerable<double> original, IEnumerable<double> target, out double alpha, out double beta, out OnlineEvaluatorError errorState) {
    97100      OnlineLinearScalingParameterCalculator calculator = new OnlineLinearScalingParameterCalculator();
    98101      IEnumerator<double> originalEnumerator = original.GetEnumerator();
     
    110113        throw new ArgumentException("Number of elements in original and target enumeration do not match.");
    111114      } else {
     115        errorState = calculator.ErrorState;
    112116        alpha = calculator.Alpha;
    113117        beta = calculator.Beta;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAbsolutePercentageErrorEvaluator.cs

    r5845 r5894  
    4040
    4141    #region IOnlineEvaluator Members
     42    private OnlineEvaluatorError errorState;
     43    public OnlineEvaluatorError ErrorState {
     44      get { return errorState; }
     45    }
    4246    public double Value {
    4347      get { return MeanAbsolutePercentageError; }
     
    4650      n = 0;
    4751      sre = 0.0;
     52      errorState = OnlineEvaluatorError.InsufficientElementsAdded;
    4853    }
    4954
     
    5156      if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    5257          double.IsNaN(original) || double.IsInfinity(original) ||
    53         double.IsNaN(sre)) {
    54         sre = double.NaN;
    55       } else {
    56         if (!original.IsAlmost(0.0)) {
    57           sre += Math.Abs((estimated - original) / original);
    58           n++;
    59         }
     58        original.IsAlmost(0.0)) {
     59        errorState = errorState | OnlineEvaluatorError.InvalidValueAdded;
     60      } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) {
     61        sre += Math.Abs((estimated - original) / original);
     62        n++;
     63        errorState = OnlineEvaluatorError.None; // n >= 1
    6064      }
    6165    }
     
    6367    #endregion
    6468
    65     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     69    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    6670      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6771      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    7983        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    8084      } else {
     85        errorState = evaluator.ErrorState;
    8186        return evaluator.MeanAbsolutePercentageError;
    8287      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAndVarianceCalculator.cs

    r5845 r5894  
    2929    private int n;
    3030
     31    private OnlineEvaluatorError varianceErrorState;
     32    public OnlineEvaluatorError VarianceErrorState {
     33      get { return varianceErrorState; }
     34    }
     35
    3136    public double Variance {
    3237      get {
     
    3540    }
    3641
     42    private OnlineEvaluatorError errorState;
     43    public OnlineEvaluatorError PopulationVarianceErrorState {
     44      get { return errorState; }
     45    }
    3746    public double PopulationVariance {
    3847      get {
     
    4150    }
    4251
     52    public OnlineEvaluatorError MeanErrorState {
     53      get { return errorState; }
     54    }
    4355    public double Mean {
    4456      get {
     
    5769    public void Reset() {
    5870      n = 0;
     71      errorState = OnlineEvaluatorError.InsufficientElementsAdded;
     72      varianceErrorState = OnlineEvaluatorError.InsufficientElementsAdded;
    5973    }
    6074
    6175    public void Add(double x) {
    62       if (double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(m_newM)) {
    63         m_newM = double.NaN;
    64         m_newS = double.NaN;
    65       } else {
     76      if (double.IsNaN(x) || double.IsInfinity(x)) {
     77        errorState = errorState | OnlineEvaluatorError.InvalidValueAdded;
     78        varianceErrorState = errorState | OnlineEvaluatorError.InvalidValueAdded;
     79      } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) {
    6680        n++;
    6781        // See Knuth TAOCP vol 2, 3rd edition, page 232
     
    6983          m_oldM = m_newM = x;
    7084          m_oldS = 0.0;
     85          errorState = OnlineEvaluatorError.None; // n >= 1
    7186        } else {
     87          varianceErrorState = OnlineEvaluatorError.None; // n >= 1
    7288          m_newM = m_oldM + (x - m_oldM) / n;
    7389          m_newS = m_oldS + (x - m_oldM) * (x - m_newM);
     
    8096    }
    8197
    82     public static void Calculate(IEnumerable<double> x, out double mean, out double variance) {
     98    public static void Calculate(IEnumerable<double> x, out double mean, out double variance, out OnlineEvaluatorError meanErrorState, out OnlineEvaluatorError varianceErrorState) {
    8399      OnlineMeanAndVarianceCalculator meanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator();
    84100      foreach (double xi in x) {
     
    87103      mean = meanAndVarianceCalculator.Mean;
    88104      variance = meanAndVarianceCalculator.Variance;
     105      meanErrorState = meanAndVarianceCalculator.MeanErrorState;
     106      varianceErrorState = meanAndVarianceCalculator.VarianceErrorState;
    89107    }
    90108  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanSquaredErrorEvaluator.cs

    r5845 r5894  
    3939
    4040    #region IOnlineEvaluator Members
     41    private OnlineEvaluatorError errorState;
     42    public OnlineEvaluatorError ErrorState {
     43      get { return errorState; }
     44    }
    4145    public double Value {
    4246      get { return MeanSquaredError; }
     
    4549      n = 0;
    4650      sse = 0.0;
     51      errorState = OnlineEvaluatorError.InsufficientElementsAdded;
    4752    }
    4853
    4954    public void Add(double original, double estimated) {
    5055      if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    51           double.IsNaN(original) || double.IsInfinity(original) ||
    52         double.IsNaN(sse)) {
    53         sse = double.NaN;
    54       } else {
     56          double.IsNaN(original) || double.IsInfinity(original)) {
     57        errorState = errorState | OnlineEvaluatorError.InvalidValueAdded;
     58      } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) {
    5559        double error = estimated - original;
    5660        sse += error * error;
    5761        n++;
     62        errorState = OnlineEvaluatorError.None; // n >= 1
    5863      }
    5964    }
    6065    #endregion
    6166
    62     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     67    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    6368      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6469      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    7681        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    7782      } else {
     83        errorState = mseEvaluator.ErrorState;
    7884        return mseEvaluator.MeanSquaredError;
    7985      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineNormalizedMeanSquaredErrorEvaluator.cs

    r5809 r5894  
    4343
    4444    #region IOnlineEvaluator Members
     45    public OnlineEvaluatorError ErrorState {
     46      get { return meanSquaredErrorCalculator.MeanErrorState | originalVarianceCalculator.VarianceErrorState; }
     47    }
    4548    public double Value {
    4649      get { return NormalizedMeanSquaredError; }
     
    6063    #endregion
    6164
    62     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     65    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    6366      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6467      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    7679        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    7780      } else {
     81        errorState = normalizedMSEEvaluator.ErrorState;
    7882        return normalizedMSEEvaluator.NormalizedMeanSquaredError;
    7983      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs

    r5809 r5894  
    4646
    4747    #region IOnlineEvaluator Members
     48    public OnlineEvaluatorError ErrorState {
     49      get { return covEvaluator.ErrorState | sxEvaluator.PopulationVarianceErrorState | syEvaluator.PopulationVarianceErrorState; }
     50    }
    4851    public double Value {
    4952      get { return RSquared; }
     
    6467    #endregion
    6568
    66     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     69    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) {
    6770      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6871      IEnumerator<double> secondEnumerator = second.GetEnumerator();
     
    8083        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    8184      } else {
     85        errorState = rSquaredEvaluator.ErrorState;
    8286        return rSquaredEvaluator.RSquared;
    8387      }
Note: See TracChangeset for help on using the changeset viewer.