本文整理了Java中org.apache.mahout.math.Matrix.transpose()
方法的一些代码示例,展示了Matrix.transpose()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.transpose()
方法的具体详情如下:
包路径:org.apache.mahout.math.Matrix
类名称:Matrix
方法名:transpose
[英]Return a new matrix that is the transpose of the receiver
[中]返回一个新矩阵,它是接收器的转置
代码示例来源:origin: apache/mahout
public Matrix getV() {
// V = (B' inv(L')) V_0
return cd2.solveRight(b.transpose()).times(svd.getV());
}
}
代码示例来源:origin: apache/mahout
public SequentialBigSvd(Matrix A, int p) {
// Y = A * \Omega
y = A.times(new RandomTrinaryMatrix(A.columnSize(), p));
// R'R = Y' Y
cd1 = new CholeskyDecomposition(y.transpose().times(y));
// B = Q" A = (Y R^{-1} )' A
b = cd1.solveRight(y).transpose().times(A);
// L L' = B B'
cd2 = new CholeskyDecomposition(b.times(b.transpose()));
// U_0 D V_0' = L
svd = new SingularValueDecomposition(cd2.getL());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testPlusMatrixCardinality() {
test.plus(test.transpose());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignMatrixBinaryFunctionCardinality() {
test.assign(test.transpose(), Functions.PLUS);
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testMinusCardinality() {
test.minus(test.transpose());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testMinusCardinality() {
test.minus(test.transpose());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testPlusMatrixCardinality() {
test.plus(test.transpose());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignMatrixCardinality() {
test.assign(test.transpose());
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignMatrixBinaryFunctionCardinality() {
test.assign(test.transpose(), Functions.PLUS);
}
代码示例来源:origin: apache/mahout
@Test
public void testTransposeView() {
Matrix m = Matrices.gaussianView(5, 6, 1234L);
Matrix controlM = new DenseMatrix(5, 6).assign(m);
System.out.printf("M=\n%s\n", m);
System.out.printf("controlM=\n%s\n", controlM);
Matrix mtm = Matrices.transposedView(m).times(m);
Matrix controlMtm = controlM.transpose().times(controlM);
System.out.printf("M'M=\n%s\n", mtm);
Matrix diff = mtm.minus(controlMtm);
assertEquals(0, diff.aggregate(Functions.PLUS, Functions.ABS), 1e-10);
}
代码示例来源:origin: apache/mahout
private static Matrix lowRankMatrix() {
Matrix u = new RandomTrinaryMatrix(1, 20, 4, false);
Matrix d = new DiagonalMatrix(new double[]{5, 3, 1, 0.5});
Matrix v = new RandomTrinaryMatrix(2, 23, 4, false);
return u.times(d).times(v.transpose());
}
}
代码示例来源:origin: apache/mahout
@Test
public void testSvdHang() throws IOException, InterruptedException, ExecutionException, TimeoutException {
System.out.printf("starting hanging-svd\n");
final Matrix m = readTsv("hanging-svd.tsv");
SingularValueDecomposition svd = new SingularValueDecomposition(m);
assertEquals(0, m.minus(svd.getU().times(svd.getS()).times(svd.getV().transpose())).aggregate(Functions.PLUS, Functions.ABS), 1e-10);
System.out.printf("No hang\n");
}
代码示例来源:origin: apache/mahout
@Test
public void testTimesMatrix() {
Matrix transpose = test.transpose();
Matrix value = test.times(transpose);
assertEquals("rows", test.rowSize(), value.rowSize());
assertEquals("cols", test.rowSize(), value.columnSize());
// TODO: check the math too, lazy
}
代码示例来源:origin: apache/mahout
@Test
public void testTimesSquaredTimesVector() {
Vector vectorA = new DenseVector(vectorAValues);
Vector ttA = test.timesSquared(vectorA);
Vector ttASlow = test.transpose().times(test.times(vectorA));
assertTrue("M'Mv != M.timesSquared(v): " + ttA + " != " + ttASlow,
ttASlow.minus(ttA).norm(2) < 1.0e-12);
}
代码示例来源:origin: apache/mahout
public static void checkOrthogonal(Matrix m) {
Matrix mTm = m.transpose().times(m);
Matrix id = new DenseMatrix(mTm.numRows(),mTm.numRows());
for (int i = 0; i < mTm.numRows(); i++) {
id.set(i, i, 1);
}
assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE);
}
代码示例来源:origin: apache/mahout
private void validateYtY(Matrix matrixToTest, int numThreads) {
OpenIntObjectHashMap<Vector> matrixToTestAsRowVectors = asRowVectors(matrixToTest);
ImplicitFeedbackAlternatingLeastSquaresSolver solver = new ImplicitFeedbackAlternatingLeastSquaresSolver(
matrixToTest.columnSize(), 1, 1, matrixToTestAsRowVectors, numThreads);
Matrix yTy = matrixToTest.transpose().times(matrixToTest);
Matrix shouldMatchyTy = solver.getYtransposeY(matrixToTestAsRowVectors);
for (int row = 0; row < yTy.rowSize(); row++) {
for (int column = 0; column < yTy.columnSize(); column++) {
assertEquals(yTy.getQuick(row, column), shouldMatchyTy.getQuick(row, column), 0);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testTranspose() {
Matrix transpose = test.transpose();
assertEquals("rows", test.columnSize(), transpose.rowSize());
assertEquals("cols", test.rowSize(), transpose.columnSize());
for (int row = 0; row < test.rowSize(); row++) {
for (int col = 0; col < test.columnSize(); col++) {
assertEquals("value[" + row + "][" + col + ']',
test.getQuick(row, col), transpose.getQuick(col, row), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testTranspose() {
Matrix transpose = test.transpose();
assertEquals("rows", test.columnSize(), transpose.rowSize());
assertEquals("cols", test.rowSize(), transpose.columnSize());
for (int row = 0; row < test.rowSize(); row++) {
for (int col = 0; col < test.columnSize(); col++) {
assertEquals("value[" + row + "][" + col + ']',
test.getQuick(row, col), transpose.getQuick(col, row), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testSingularValues() {
Matrix A = lowRankMatrix();
SequentialBigSvd s = new SequentialBigSvd(A, 8);
SingularValueDecomposition svd = new SingularValueDecomposition(A);
Vector reference = new DenseVector(svd.getSingularValues()).viewPart(0, 8);
assertEquals(reference, s.getSingularValues());
assertEquals(A, s.getU().times(new DiagonalMatrix(s.getSingularValues())).times(s.getV().transpose()));
}
代码示例来源:origin: apache/mahout
@Test
public void randomMatrix() {
Matrix a = new DenseMatrix(60, 60).assign(Functions.random());
QRDecomposition qr = new QRDecomposition(a);
// how close is Q to actually being orthornormal?
double maxIdent = qr.getQ().transpose().times(qr.getQ()).viewDiagonal().assign(Functions.plus(-1)).norm(1);
assertEquals(0, maxIdent, 1.0e-13);
// how close is Q R to the original value of A?
Matrix z = qr.getQ().times(qr.getR()).minus(a);
double maxError = z.aggregate(Functions.MIN, Functions.ABS);
assertEquals(0, maxError, 1.0e-13);
}
内容来源于网络,如有侵权,请联系作者删除!