Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.Modeling/3.3/SimpleEvaluatorBase.cs @ 3155

Last change on this file since 3155 was 1888, checked in by gkronber, 16 years ago

Added simple evaluators for mean absolute percentage error, mean absolute percentage of range error and, variance accounted for. #635 (Plugin HeuristicLab.Modeling as a common basis for all data-based modeling algorithms)

File size: 1.2 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 abstract class SimpleEvaluatorBase : OperatorBase {
11    public virtual string OutputVariableName {
12      get { return "Quality"; }
13    }
14    public SimpleEvaluatorBase()
15      : base() {
16      AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.In));
17      AddVariableInfo(new VariableInfo(OutputVariableName, OutputVariableName, typeof(DoubleData), VariableKind.New | VariableKind.Out));
18    }
19
20    public override IOperation Apply(IScope scope) {
21      DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true);
22      DoubleData quality = GetVariableValue<DoubleData>(OutputVariableName, scope, false, false);
23      if (quality == null) {
24        quality = new DoubleData();
25        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OutputVariableName), quality));
26      }
27
28      quality.Data = Evaluate(values.Data);
29      return null;
30    }
31
32    public abstract double Evaluate(double[,] values);
33  }
34}
Note: See TracBrowser for help on using the repository browser.