本文整理汇总了Java中org.ujmp.core.Matrix.mtimes方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.mtimes方法的具体用法?Java Matrix.mtimes怎么用?Java Matrix.mtimes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ujmp.core.Matrix
的用法示例。
在下文中一共展示了Matrix.mtimes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pca
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public SparseMatrix pca(SparseMatrix A, int dim) {
logger.info("Type 'pca' started (target dimensions = " + dim + ").");
centerData(A);
logger.info("Computing SVD...");
Matrix[] svd = A.svd();
Matrix U = svd[0];
Matrix S = svd[1];
logger.info("Reducing U to Uk...");
Matrix Uk = U.select(Ret.NEW, "*;0-" + dim);
logger.info("Reducing S to Sk...");
Matrix Sk = S.select(Ret.NEW, "0-" + dim + ";0-" + dim);
logger.info("Computing principal components...");
return (SparseMatrix) Uk.mtimes(Sk);
}
示例2: testEigRandSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testEigRandSmall() throws Exception {
Matrix a = createMatrixWithAnnotation(10, 10);
if (!isSupported(a, MatrixLibraries.EIG, MatrixLayout.SQUARE, Size.SMALL, EntryType.RANDN)) {
return;
}
a.randn(Ret.ORIG);
Matrix[] eig = a.eig();
Matrix prod1 = a.mtimes(eig[0]);
Matrix prod2 = eig[0].mtimes(eig[1]);
assertEquals(getLabel(), 0.0, prod1.minus(prod2).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
}
示例3: testSquareInverse
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testSquareInverse() {
Matrix a = Matrix.Factory.zeros(3, 3); // example from ucla.edu
a.setAsDouble(4, 0, 0);
a.setAsDouble(2, 0, 1);
a.setAsDouble(2, 0, 2);
a.setAsDouble(4, 1, 0);
a.setAsDouble(6, 1, 1);
a.setAsDouble(8, 1, 2);
a.setAsDouble(-2, 2, 0);
a.setAsDouble(2, 2, 1);
a.setAsDouble(4, 2, 2);
Matrix a12 = a.ginv();
Matrix a12a = a12.mtimes(a);
for (int row = 0; row < a12a.getRowCount(); ++row) {
for (int col = 0; col < a12a.getColumnCount(); ++col) {
if (row == col) {
assertEquals(1.0, a12a.getAsDouble(row, col), 0.001);
} else {
assertEquals(0.0, a12a.getAsDouble(row, col), 0.001);
}
}
}
}
示例4: testEigSymmSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testEigSymmSmall() throws Exception {
Matrix a = createMatrixWithAnnotation(10, 10);
setRandSymmetric(a);
Matrix[] eig = a.eig();
Matrix prod1 = a.mtimes(eig[0]);
Matrix prod2 = eig[0].mtimes(eig[1]);
assertEquals(getLabel(), 0.0, prod1.minus(prod2).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod1 instanceof Erasable) {
((Erasable) prod1).erase();
}
if (prod2 instanceof Erasable) {
((Erasable) prod2).erase();
}
}
示例5: testSparseMultiplySmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSparseMultiplySmall() throws Exception {
Matrix m1 = createMatrix(2, 2);
Matrix m2 = null;
if (isTestSparse() && m1.isSparse()) {
m1 = createMatrix(8, 9);
m2 = createMatrix(9, 4);
m1.setAsDouble(5.0, 0, 0);
m1.setAsDouble(4.0, 1, 1);
m1.setAsDouble(1.0, 3, 4);
m1.setAsDouble(2.0, 4, 2);
m1.setAsDouble(3.0, 3, 5);
m1.setAsDouble(4.0, 4, 4);
m2.setAsDouble(7.0, 0, 0);
m2.setAsDouble(6.0, 1, 1);
m2.setAsDouble(1.0, 3, 4);
m2.setAsDouble(2.0, 4, 1);
m2.setAsDouble(3.0, 3, 2);
m2.setAsDouble(4.0, 2, 3);
Matrix m3 = m1.mtimes(m2);
Matrix m4 = m1.mtimes(Ret.LINK, true, m2);
assertEquals(m3, m4);
}
}
示例6: testInvRandSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testInvRandSmall() throws Exception {
Matrix m1 = createMatrixWithAnnotation(10, 10);
do {
m1.randn(Ret.ORIG);
} while (m1.isSingular());
Matrix m2 = m1.inv();
Matrix m3 = m1.mtimes(m2);
Matrix eye = DenseDoubleMatrix2D.Factory.eye(m1.getRowCount(), m1.getColumnCount());
assertEquals(getLabel(), 0.0, eye.minus(m3).getEuklideanValue(), TOLERANCE);
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
if (eye instanceof Erasable) {
((Erasable) eye).erase();
}
}
示例7: testCholRandSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testCholRandSmall() throws Exception {
Random random = new Random(System.nanoTime());
DenseDoubleMatrix2D temp = new DefaultDenseDoubleMatrix2D(10, 10);
int rows = (int) temp.getRowCount();
int cols = (int) temp.getColumnCount();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
temp.setDouble(random.nextDouble(), r, c);
}
}
Matrix result = createMatrixWithAnnotation(temp.mtimes(temp.transpose()));
if (!isSupported(result, MatrixLibraries.CHOL, MatrixLayout.SQUARE, Size.SMALL, null)) {
return;
}
Matrix chol = result.chol();
Matrix prod = chol.mtimes(chol.transpose());
assertEquals(getLabel(), 0.0, prod.minus(result).getRMS(), TOLERANCE);
if (result instanceof Erasable) {
((Erasable) result).erase();
}
}
示例8: task
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Override
public BenchmarkResult task(Class<? extends Matrix> matrixClass, long benchmarkSeed, int run,
long[] size) {
final long t0, t1, m0, m1;
final DoubleMatrix2D m;
Matrix r = null;
try {
m = BenchmarkUtil.createMatrix(matrixClass, size);
if (!m.getClass().getName().startsWith("org.ujmp.core")
&& m.getClass().getDeclaredMethod("chol") == null) {
System.out.print("-");
System.out.flush();
return BenchmarkResult.NOTAVAILABLE;
}
BenchmarkUtil.randPositiveDefinite(benchmarkSeed, run, 0, m);
BenchmarkUtil.purgeMemory(getConfig());
m0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
t0 = System.nanoTime();
r = m.chol();
t1 = System.nanoTime();
m1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
if (r == null) {
System.out.print("e");
System.out.flush();
return BenchmarkResult.ERROR;
}
Matrix result = r.mtimes(r.transpose());
double diff = BenchmarkUtil.difference(result, m);
result = null;
long mem = m1 - m0 - SerializationUtil.sizeOf(r);
mem = mem > 0 ? mem : 0;
return new BenchmarkResult((t1 - t0) / 1000000.0, diff, mem);
} catch (Throwable e) {
System.out.print("e");
System.out.flush();
return BenchmarkResult.ERROR;
}
}
示例9: testSolveRandSPDSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSolveRandSPDSmall() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix a = createMatrixWithAnnotation(15, 15);
BenchmarkUtil.randPositiveDefinite(System.currentTimeMillis(), 0, 0, a);
Matrix x = createMatrixWithAnnotation(15, 15);
x.randn(Ret.ORIG);
Matrix b = a.mtimes(x);
Matrix x2 = a.solveSPD(b);
Matrix prod = a.mtimes(x2);
assertEquals(getLabel(), 0.0, prod.minus(b).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod instanceof Erasable) {
((Erasable) prod).erase();
}
if (x instanceof Erasable) {
((Erasable) x).erase();
}
if (x2 instanceof Erasable) {
((Erasable) x2).erase();
}
}
示例10: testEigRandLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testEigRandLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix a = createMatrixWithAnnotation(110, 110);
if (!isSupported(a, MatrixLibraries.EIG, MatrixLayout.SQUARE, Size.LARGE, null)) {
return;
}
a.randn(Ret.ORIG);
Matrix[] eig = a.eig();
Matrix prod1 = a.mtimes(eig[0]);
Matrix prod2 = eig[0].mtimes(eig[1]);
assertEquals(getLabel(), 0.0, prod1.minus(prod2).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod1 instanceof Erasable) {
((Erasable) prod1).erase();
}
if (prod2 instanceof Erasable) {
((Erasable) prod2).erase();
}
}
示例11: testSolveRandTallLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSolveRandTallLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix a = createMatrixWithAnnotation(169, 121);
if (!isSupported(a, MatrixLibraries.SOLVE, MatrixLayout.TALL, Size.LARGE, EntryType.RANDN)) {
return;
}
a.randn(Ret.ORIG);
Matrix x = createMatrixWithAnnotation(121, 143);
x.randn(Ret.ORIG);
Matrix b = a.mtimes(x);
Matrix x2 = a.solve(b);
Matrix prod = a.mtimes(x2);
assertEquals(getLabel(), 0.0, prod.minus(b).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod instanceof Erasable) {
((Erasable) prod).erase();
}
if (x instanceof Erasable) {
((Erasable) x).erase();
}
if (x2 instanceof Erasable) {
((Erasable) x2).erase();
}
}
示例12: testSolveRandSPDLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSolveRandSPDLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix a = createMatrixWithAnnotation(125, 125);
BenchmarkUtil.randPositiveDefinite(System.currentTimeMillis(), 0, 0, a);
Matrix x = createMatrixWithAnnotation(125, 125);
x.randn(Ret.ORIG);
Matrix b = a.mtimes(x);
Matrix x2 = a.solveSPD(b);
Matrix prod = a.mtimes(x2);
assertEquals(getLabel(), 0.0, prod.minus(b).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod instanceof Erasable) {
((Erasable) prod).erase();
}
if (x instanceof Erasable) {
((Erasable) x).erase();
}
if (x2 instanceof Erasable) {
((Erasable) x2).erase();
}
}
示例13: testCholRandLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testCholRandLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Random random = new Random(System.nanoTime());
DenseDoubleMatrix2D temp = new DefaultDenseDoubleMatrix2D(102, 102);
int rows = (int) temp.getRowCount();
int cols = (int) temp.getColumnCount();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
temp.setDouble(random.nextDouble(), r, c);
}
}
Matrix result = createMatrixWithAnnotation(temp.mtimes(temp.transpose()));
if (!isSupported(result, MatrixLibraries.CHOL, MatrixLayout.SQUARE, Size.LARGE, null)) {
return;
}
Matrix chol = result.chol();
Matrix prod = chol.mtimes(chol.transpose());
assertEquals(0.0, prod.minus(result).getRMS(), TOLERANCE);
if (result instanceof Erasable) {
((Erasable) result).erase();
}
}
示例14: test1
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void test1() {
Matrix a = Matrix.Factory.linkToArray(new double[][] { { 1, 2, 3 }, { 4, 5, 6 },
{ 7, 8, 9 } });
Matrix b = Matrix.Factory.linkToArray(new double[][] { { 1, 2, 3 }, { 4, 5, 6 },
{ 7, 8, 9 } });
Matrix c_correct = a.mtimes(Ret.NEW, true, b);
Matrix c1 = a.mtimes(b);
assertEquals(c_correct, c1);
}
示例15: predictOne
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.NEW);
Matrix x = Matrix.Factory.zeros(1, input.getColumnCount() + 1);
for (int c = 0; c < input.getColumnCount(); c++) {
x.setAsDouble(input.getAsDouble(0, c), 0, c + 1);
}
x = x.minus(mean).divide(std);
x.setAsDouble(1, 0, 0);
Matrix result = x.mtimes(getParameterMatrix());
return result;
}