Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.DataAnalysis;
|
---|
8 |
|
---|
9 | namespace 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.