Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/SimpleNMSEEvaluator.cs @ 2879

Last change on this file since 2879 was 2379, checked in by gkronber, 15 years ago

Implemented additional model quality metrics. #761

File size: 1.2 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 SimpleNMSEEvaluator : SimpleEvaluatorBase {
11
12    public override string OutputVariableName {
13      get {
14        return "NMSE";
15      }
16    }
17    public override double Evaluate(double[,] values) {
18      try {
19        return Calculate(values);
20      }
21      catch (ArgumentException) {
22        return double.PositiveInfinity;
23      }
24    }
25
26    public static double Calculate(double[,] values) {
27      double mse = SimpleMSEEvaluator.Calculate(values);
28      double mean = Statistics.Mean(Matrix<double>.GetColumn(values, ORIGINAL_INDEX));
29      double ssd = 0;
30      int n = 0;
31      for (int i = 0; i < values.GetLength(0); i++) {
32        double original = values[i, ORIGINAL_INDEX];
33        if (!(double.IsNaN(original) || double.IsInfinity(original))) {
34          double dev = original - mean;
35          ssd += dev * dev;
36          n++;
37        }
38      }
39      double variance = ssd / (n - 1);
40      return mse / variance;
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.