本文整理汇总了Java中org.jblas.DoubleMatrix.rand方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.rand方法的具体用法?Java DoubleMatrix.rand怎么用?Java DoubleMatrix.rand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jblas.DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.rand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testProjection
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testProjection() {
int cols = 20;
int rows = 2000;
int numProjections = 8;
Random.seed(42);
DoubleMatrix matrix = DoubleMatrix.rand(rows, cols);
DoubleMatrix projectionMatrix = DoubleMatrix.rand(numProjections, cols);
ITable table = BlasConversions.toTable(matrix);
LinearProjectionMap lpm = new LinearProjectionMap(
table.getSchema().getColumnNames(), projectionMatrix,
"LP");
ITable result = lpm.apply(table);
String[] newColNames = new String[numProjections];
for (int i = 0; i < numProjections; i++) {
newColNames[i] = String.format("LP%d", i);
}
DoubleMatrix projectedData = BlasConversions.toDoubleMatrix(result, newColNames);
DoubleMatrix projectedDataCheck = matrix.mmul(projectionMatrix.transpose());
Assert.assertEquals(rows * numProjections, projectedData.eq(projectedDataCheck).sum(), Math.ulp(rows * cols));
}
示例2: 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);
}
}
}
示例3: testConversions
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testConversions() {
int cols = 20;
int rows = 2000;
Random.seed(42);
DoubleMatrix matrix = DoubleMatrix.rand(rows, cols);
ITable table = BlasConversions.toTable(matrix);
DoubleMatrix matrix2 = BlasConversions.toDoubleMatrix(table, table.getSchema().getColumnNames());
Assert.assertEquals(rows * cols, matrix.eq(matrix2).sum(), Math.ulp(rows * rows));
}
示例4: testDatasetProjection
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testDatasetProjection() {
int rows = 10000;
int cols = 20;
int numProjections = 2;
DoubleMatrix dataMatrix = DoubleMatrix.rand(rows, cols);
DoubleMatrix projectionMatrix = DoubleMatrix.rand(numProjections, cols);
DoubleMatrix projectionCheck = dataMatrix.mmul(projectionMatrix.transpose());
ITable bigTable = BlasConversions.toTable(dataMatrix);
String[] colNames = bigTable.getSchema().getColumnNames();
// Convert it to an IDataset
IDataSet<ITable> all = TestTables.makeParallel(bigTable, rows / 10);
LinearProjectionMap lpm = new LinearProjectionMap(colNames, projectionMatrix, "LP");
IDataSet<ITable> result = all.blockingMap(lpm);
for (int i = 0; i < numProjections; i++) {
BasicColStatSketch b = new BasicColStatSketch(
new ColumnAndConverterDescription(String.format("LP%d", i)), 1, 1, 0);
BasicColStats bcs = result.blockingSketch(b);
double expectedMean = projectionCheck.get(new AllRange(), i).mean();
double actualMean = bcs.getMoment(1);
double eps = actualMean * 1e-6;
Assert.assertTrue("Mean is too far from actual mean", Math.abs(actualMean - expectedMean) < eps);
double expectedMin = projectionCheck.get(new AllRange(), i).min();
double actualMin = bcs.getMin();
eps = actualMin * 1e-6;
Assert.assertTrue("Min is too far from actual min", Math.abs(actualMin - expectedMin) < eps);
double expectedMax = projectionCheck.get(new AllRange(), i).max();
double actualMax = bcs.getMax();
eps = actualMax* 1e-6;
Assert.assertTrue("Max is too far from actual min", Math.abs(actualMax - expectedMax) < eps);
}
}