Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.Modeling/3.3/SimpleMSEEvaluator.cs @ 2553

Last change on this file since 2553 was 1888, checked in by gkronber, 15 years ago

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 size: 1.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.DataAnalysis;
8
9namespace HeuristicLab.Modeling {
10  public class SimpleMSEEvaluator : SimpleEvaluatorBase {
11
12    public override string OutputVariableName {
13      get {
14        return "MSE";
15      }
16    }
17    public override double Evaluate(double[,] values) {
18      return Calculate(values);
19    }
20
21    public static double Calculate(double[,] values) {
22      double sse = 0;
23      double cnt = 0;
24      for (int i = 0; i < values.GetLength(0); i++) {
25        double estimated = values[i, 0];
26        double target = values[i, 1];
27        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
28            !double.IsNaN(target) && !double.IsInfinity(target)) {
29          double error = estimated - target;
30          sse += error * error;
31          cnt++;
32        }
33      }
34
35      double mse = sse / cnt;
36      return mse;
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.