Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.SupportVectorMachines/3.2/SimpleMSEEvaluator.cs @ 6452

Last change on this file since 6452 was 1814, checked in by mkommend, 16 years ago

added SimpleR2Evaluator for SVMs + test engine (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 sse = 0;
21      double cnt = 0;     
22      foreach (ItemList row in values) {
23        double estimated = ((DoubleData)row[0]).Data;
24        double target = ((DoubleData)row[1]).Data;
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.