public double[] CanCor(int[] iA, int[] iB, double[][] cov) { this.iA = iA; this.iB = iB; this.cov = cov; RealMatrix covA = new BlockRealMatrix(cov).getSubMatrix(iA, iA); RealMatrix covB = new BlockRealMatrix(cov).getSubMatrix(iB, iB); RealMatrix covAB = new BlockRealMatrix(cov).getSubMatrix(iA, iB); RealMatrix covBA = new BlockRealMatrix(cov).getSubMatrix(iB, iA); RealMatrix S = getInverse(covA).multiply(covAB).multiply(getInverse(covB)).multiply(covBA); double[] rtCors = new EigenDecomposition(S).getRealEigenvalues(); Arrays.sort(rtCors); double[] Cors = new double[rtCors.length]; for (int i = rtCors.length; i > 0; i--) { Cors[rtCors.length - i] = Math.pow(rtCors[i - 1], .5); } return Cors; }