Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute Covariance Matrix in Java

I want to calculate covariance matrix using Java.

Is there any free library to compute covariance Matrix in Java?

like image 785
Pow Avatar asked Jun 19 '11 23:06

Pow


People also ask

What is covariance of a matrix?

Covariance Matrix is a measure of how much two random variables gets change together. It is actually used for computing the covariance in between every column of data matrix. The Covariance Matrix is also known as dispersion matrix and variance-covariance matrix.


1 Answers

Here is a short example, how you can create it with Apache Commons Math (3.5):

RealMatrix mx = MatrixUtils.createRealMatrix(new double[][]{
  {1, 2, 3},
  {2, 4, 6}
});
RealMatrix cov = new Covariance(mx).getCovarianceMatrix();
like image 99
Darius Avatar answered Sep 20 '22 13:09

Darius