2013-10-02 41 views

回答

1

目前还没有计算相关矩阵的例程,但我已打开票#161在GitHub上进行跟踪。

在此期间,你可以使用下面的程序(我使用v3.0.0-alpha5这里):

Matrix<double> Spearman(double[][] data) 
{ 
    var m = Matrix<double>.Build.DenseIdentity(data.Length); 
    for(int i=0; i<data.Length; i++) 
    for(int j=i+1; j<data.Length; j++) 
    { 
     var c = Correlation.Spearman(data[i], data[j]); 
     m.At(i,j,c); 
     m.At(j,i,c); 
    } 
    return m; 
} 

var vectors = new[] { 
    new[] { 1.0, 2.0, 3.0, 4.0 }, 
    new[] { 2.0, 4.0, 6.0, 8.0 }, 
    new[] { 4.0, 3.0, 2.0, 1.0 }, 
    new[] { 0.0, 10.0, 10.0, 20.0 }, 
    new[] { 2.0, 4.0, -4.0, 2.0 } 
}; 

Spearman(vectors); 

将返回:

DenseMatrix 5x5-Double 
      1   1   -1  0.948683 -0.316228 
      1   1   -1  0.948683 -0.316228 
      -1   -1   1 -0.948683  0.316228 
    0.948683  0.948683 -0.948683   1   0 
    -0.316228 -0.316228  0.316228   0   1 

更新二〇一三年十月二十〇日:

添加到主人,可在V3.0.0-alpha6和更新版本中使用:

  • Correlation.PearsonMatrix(params double[][] vectors)
  • Correlation.PearsonMatrix(IEnumerable<double[]> vectors)
  • Correlation.SpearmanMatrix(params double[][] vectors)
  • Correlation.SpearmanMatrix(IEnumerable<double[]> vectors)
+0

谢谢,我结束了的情况下,具体的解决方案去,因为我并不需要整个矩阵。虽然看到github问题线程,因为这将在未来有用。 –

相关问题