Last change
on this file since 2879 was
2844,
checked in by gkronber, 15 years ago
|
Added a check to SimpleStableCorrelationCoefficientEvaluator so that a r2 of 0.0 is returned instead of NaN (in case of division by zero). Also removed unnecessary try {} catch block in SimplePearsonCorrelationCoefficientEvaluator. #881
|
File size:
888 bytes
|
Line | |
---|
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 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 | return Calculate(values);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public static double Calculate(double[,] values) {
|
---|
23 | double[] estimated = Matrix<double>.GetColumn(values, ESTIMATION_INDEX);
|
---|
24 | double[] original = Matrix<double>.GetColumn(values, ORIGINAL_INDEX);
|
---|
25 | double r = alglib.correlation.pearsoncorrelation(
|
---|
26 | ref estimated,
|
---|
27 | ref original,
|
---|
28 | values.GetLength(0));
|
---|
29 | return r * r;
|
---|
30 | }
|
---|
31 | }
|
---|
32 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.