/** * Computes the estimate of the covariance matrix. * * @param matrix A multi-dimensional array containing the matrix values (assumed to contain at least one row). * @param weights The observation weights, normalized to sum to 1. * @param mean The values' mean vector. * @return The covariance matrix, including the ridge. */ private UpperSPDDenseMatrix weightedCovariance(double[][] matrix, DenseVector weights, Vector mean) { int rows = matrix.length; int cols = matrix[0].length; if (mean.size() != cols) { throw new IllegalArgumentException("Length of the mean vector must match matrix."); } // Create matrix with centered transposed data, weighted appropriately DenseMatrix transposed = new DenseMatrix(cols, rows); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { transposed.set(j, i, Math.sqrt(weights.get(i)) * (matrix[i][j] - mean.get(j))); } } UpperSPDDenseMatrix covT = (UpperSPDDenseMatrix) new UpperSPDDenseMatrix(cols).rank1(transposed); for (int i = 0; i < cols; i++) { covT.add(i, i, m_Ridge); } return covT; }
/** * Computes the estimate of the covariance matrix. * * @param matrix A multi-dimensional array containing the matrix values (assumed to contain at least one row). * @param weights The observation weights, normalized to sum to 1. * @param mean The values' mean vector. * @return The covariance matrix, including the ridge. */ private UpperSPDDenseMatrix weightedCovariance(double[][] matrix, DenseVector weights, Vector mean) { int rows = matrix.length; int cols = matrix[0].length; if (mean.size() != cols) { throw new IllegalArgumentException("Length of the mean vector must match matrix."); } // Create matrix with centered transposed data, weighted appropriately DenseMatrix transposed = new DenseMatrix(cols, rows); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { transposed.set(j, i, Math.sqrt(weights.get(i)) * (matrix[i][j] - mean.get(j))); } } UpperSPDDenseMatrix covT = (UpperSPDDenseMatrix) new UpperSPDDenseMatrix(cols).rank1(transposed); for (int i = 0; i < cols; i++) { covT.add(i, i, m_Ridge); } return covT; }
Matrix aTa = new UpperSPDDenseMatrix(numAttributes).rank1(independentTransposed); independentTransposed = null; dependent = null;
Matrix aTa = new UpperSPDDenseMatrix(numAttributes).rank1(independentTransposed); independentTransposed = null; dependent = null;