Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SimpleMSEEvaluator.cs @ 1810

Last change on this file since 1810 was 1810, checked in by mkommend, 15 years ago

added SimpleMSEEvaluator in HL SVM project (ticket #619)

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.SupportVectorMachines {
10  public class SimpleMSEEvaluator : OperatorBase{
11
12    public SimpleMSEEvaluator()
13      : base() {
14      AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(ItemList), 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      ItemList values = GetVariableValue<ItemList>("Values", scope, true);
20      double target;
21      double estimated;
22      double error;
23      double sse = 0;
24      double cnt = 0;
25      foreach (ItemList row in values) {
26        estimated = ((DoubleData)row[0]).Data;
27        target = ((DoubleData)row[1]).Data;
28        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
29            !double.IsNaN(target) && !double.IsInfinity(target)) {
30          error = estimated - target;
31          sse += error * error;
32          cnt++;
33        }
34      }
35
36      double mse = sse / cnt;
37      scope.AddVariable(new Variable(scope.TranslateName("MSE"),new DoubleData(mse)));
38      return null;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.