Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/SimpleWeightedDirectionalSymmetryEvaluator.cs @ 2893

Last change on this file since 2893 was 2379, checked in by gkronber, 15 years ago

Implemented additional model quality metrics. #761

File size: 1.5 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 class SimpleWeightedDirectionalSymmetryEvaluator : SimpleEvaluatorBase {
11
12    public override string OutputVariableName {
13      get {
14        return "WeightedDirectionalSymmetry";
15      }
16    }
17
18    public override double Evaluate(double[,] values) {
19      return Calculate(values);
20    }
21
22    public static double Calculate(double[,] values) {
23      double correctSum = 0.0;
24      double incorrectSum = 0.0;
25      for (int i = 1; i < values.GetLength(0); i++) {
26        double prevOriginal = values[i - 1, ORIGINAL_INDEX];
27        double original = values[i, ORIGINAL_INDEX];
28        double prevEstimated = values[i - 1, ESTIMATION_INDEX];
29        double estimated = values[i, ESTIMATION_INDEX];
30        if (!(double.IsNaN(original) || double.IsInfinity(original) || double.IsNaN(prevOriginal) || double.IsInfinity(prevOriginal))) {
31          if (!(double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(prevEstimated) || double.IsInfinity(prevEstimated))) {
32            double error = Math.Abs(estimated - original);
33            if ((original - prevOriginal) * (estimated - prevEstimated) >= 0) correctSum += error;
34            else incorrectSum += error;
35          }
36        }
37      }
38      return incorrectSum / correctSum;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.