Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/SimpleMSEEvaluator.cs @ 3188

Last change on this file since 3188 was 2357, checked in by gkronber, 15 years ago

Fixed #740 (SimpleEvaluators in HL.GP.StructId and HL.SVM are not compatible with evaluators in HL.Modeling).

File size: 1.3 KB
RevLine 
[1810]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.DataAnalysis;
8
[1869]9namespace HeuristicLab.Modeling {
[1888]10  public class SimpleMSEEvaluator : SimpleEvaluatorBase {
[1810]11
[1888]12    public override string OutputVariableName {
13      get {
14        return "MSE";
15      }
[1810]16    }
[1888]17    public override double Evaluate(double[,] values) {
[2136]18      try {
19        return Calculate(values);
20      }
21      catch (ArgumentException) {
22        return double.PositiveInfinity;
23      }
[1888]24    }
[1810]25
[1888]26    public static double Calculate(double[,] values) {
[1810]27      double sse = 0;
[1869]28      double cnt = 0;
[1888]29      for (int i = 0; i < values.GetLength(0); i++) {
[2357]30        double estimated = values[i, ESTIMATION_INDEX];
31        double target = values[i, ORIGINAL_INDEX];
[1810]32        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
33            !double.IsNaN(target) && !double.IsInfinity(target)) {
[1814]34          double error = estimated - target;
[1810]35          sse += error * error;
36          cnt++;
37        }
38      }
[2136]39      if (cnt > 0) {
40        double mse = sse / cnt;
41        return mse;
42      } else {
43        throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");
44      }
[1810]45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.