本文整理汇总了Java中org.jblas.DoubleMatrix.columnMeans方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.columnMeans方法的具体用法?Java DoubleMatrix.columnMeans怎么用?Java DoubleMatrix.columnMeans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jblas.DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.columnMeans方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBigCorrelation
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testBigCorrelation() {
Random.seed(43);
DoubleMatrix mat = DoubleMatrix.rand(20000, 5);
mat.muli(4.3);
ITable bigTable = BlasConversions.toTable(mat);
String[] colNames = bigTable.getSchema().getColumnNames();
IDataSet<ITable> dataset = TestTables.makeParallel(bigTable, 10);
PCACorrelationSketch fcs = new PCACorrelationSketch(colNames);
CorrMatrix cm = dataset.blockingSketch(fcs);
// Construct the correlation matrix that we compare against by using pure JBLAS.
DoubleMatrix cmCheck = new DoubleMatrix(colNames.length, colNames.length);
DoubleMatrix means = mat.columnMeans();
DoubleMatrix sigmas = MatrixFunctions.sqrt(
mat.subRowVector(means).mul(mat.subRowVector(means)).columnMeans()
);
for (int i = 0; i < cmCheck.columns; i++) {
DoubleMatrix c1 = mat.get(new AllRange(), i);
for (int j = 0; j < cmCheck.rows; j++) {
DoubleMatrix c2 = mat.get(new AllRange(), j);
double corr = c1.dot(c2) / mat.rows;
corr -= means.get(i) * means.get(j);
corr /= sigmas.get(i) * sigmas.get(j);
cmCheck.put(i, j, corr);
cmCheck.put(j, i, corr);
}
}
for (int i = 0; i < cm.getCorrelationMatrix().length; i++) {
double[] row = cm.getCorrelationMatrix()[i];
for (int j = 0; j < row.length; j++) {
double actual = cm.getCorrelationMatrix()[i][j];
double expected = cmCheck.get(i, j);
Assert.assertEquals(expected, actual, 1e-5);
}
}
}
示例2: centerData
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private DoubleMatrix centerData(DoubleMatrix A) {
DoubleMatrix means = A.columnMeans();
for(int i=0; i<A.rows; i++)
for(int j=0; j<A.columns; j++)
A.put(i, j, A.get(i, j) - means.get(j));
return A;
}