Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Modeling/3.2/SimplePearsonCorrelationCoefficientEvaluator.cs @ 4023

Last change on this file since 4023 was 2428, checked in by gkronber, 15 years ago

Implemented #782 (Additional model quality metrics: Pearson product-moment correlation coefficient and Spearman's rank correlation coefficient)

File size: 997 bytes
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 SimplePearsonCorrelationCoefficientEvaluator : SimpleEvaluatorBase {
11
12    public override string OutputVariableName {
13      get {
14        return "R2";
15      }
16    }
17
18    public override double Evaluate(double[,] values) {
19      try {
20        return Calculate(values);
21      }
22      catch (ArgumentException) {
23        return double.NegativeInfinity;
24      }
25    }
26
27    public static double Calculate(double[,] values) {
28      double[] estimated = Matrix<double>.GetColumn(values, ESTIMATION_INDEX);
29      double[] original = Matrix<double>.GetColumn(values, ORIGINAL_INDEX);
30      double r = alglib.correlation.pearsoncorrelation(
31        ref estimated,
32        ref original,
33        values.GetLength(0));
34      return r * r;
35    }
36  }
37}
Note: See TracBrowser for help on using the repository browser.