Last change
on this file since 5754 was
1814,
checked in by mkommend, 16 years ago
|
added SimpleR2Evaluator for SVMs + test engine (ticket #619)
|
File size:
1.3 KB
|
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.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.