Last change
on this file since 2188 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
|
Rev | Line | |
---|
[1888] | 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.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);
|
---|
[2136] | 33 |
|
---|
| 34 | protected static bool IsAlmost(double x, double y) {
|
---|
| 35 | return Math.Abs(x - y) < 1.0E-12;
|
---|
| 36 | }
|
---|
[1888] | 37 | }
|
---|
| 38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.