Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1873 was 1869, checked in by gkronber, 15 years ago

Moved simple evaluators from plugin SVM to plugin Modeling. #635

File size: 1.3 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 : OperatorBase {
11
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));
16    }
17
18    public override IOperation Apply(IScope scope) {
19      DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true);
20      double sse = 0;
21      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];
25        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
26            !double.IsNaN(target) && !double.IsInfinity(target)) {
27          double error = estimated - target;
28          sse += error * error;
29          cnt++;
30        }
31      }
32
33      double mse = sse / cnt;
34      scope.AddVariable(new Variable(scope.TranslateName("MSE"), new DoubleData(mse)));
35      return null;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.