Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Exporter-715/sources/HeuristicLab.Modeling/3.2/SimpleEvaluatorBase.cs @ 2498

Last change on this file since 2498 was 2136, checked in by gkronber, 15 years ago

Improved handling of exceptional cases in data-based modeling evaluators. #688 (SimpleEvaluators should handle exceptional cases more gracefully)

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 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    protected static bool IsAlmost(double x, double y) {
35      return Math.Abs(x - y) < 1.0E-12;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.