Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 15:09:44 (15 years ago)
Author:
gkronber
Message:

Added simple evaluators for mean absolute percentage error, mean absolute percentage of range error and, variance accounted for. #635 (Plugin HeuristicLab.Modeling as a common basis for all data-based modeling algorithms)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/SimpleMSEEvaluator.cs

    r1869 r1888  
    88
    99namespace HeuristicLab.Modeling {
    10   public class SimpleMSEEvaluator : OperatorBase {
     10  public class SimpleMSEEvaluator : SimpleEvaluatorBase {
    1111
    12     public SimpleMSEEvaluator()
    13       : base() {
    14       AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.In));
    15       AddVariableInfo(new VariableInfo("MSE", "Mean squarred error", typeof(DoubleData), VariableKind.New | VariableKind.Out));
     12    public override string OutputVariableName {
     13      get {
     14        return "MSE";
     15      }
     16    }
     17    public override double Evaluate(double[,] values) {
     18      return Calculate(values);
    1619    }
    1720
    18     public override IOperation Apply(IScope scope) {
    19       DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true);
     21    public static double Calculate(double[,] values) {
    2022      double sse = 0;
    2123      double cnt = 0;
    22       for (int i = 0; i < values.Data.GetLength(0); i++) {
    23         double estimated = values.Data[i, 0];
    24         double target = values.Data[i, 1];
     24      for (int i = 0; i < values.GetLength(0); i++) {
     25        double estimated = values[i, 0];
     26        double target = values[i, 1];
    2527        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
    2628            !double.IsNaN(target) && !double.IsInfinity(target)) {
     
    3234
    3335      double mse = sse / cnt;
    34       scope.AddVariable(new Variable(scope.TranslateName("MSE"), new DoubleData(mse)));
    35       return null;
     36      return mse;
    3637    }
    3738  }
Note: See TracChangeset for help on using the changeset viewer.