当前位置: 首页>>代码示例>>Java>>正文


Java Matrix.ginv方法代码示例

本文整理汇总了Java中org.ujmp.core.Matrix.ginv方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.ginv方法的具体用法?Java Matrix.ginv怎么用?Java Matrix.ginv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ujmp.core.Matrix的用法示例。


在下文中一共展示了Matrix.ginv方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
			}
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:25,代码来源:TestGinv.java

示例2: testSquareArbitrariness

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testSquareArbitrariness() {
	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 ima12a = Ginv.arbitrariness(a, a12);
	for (int row = 0; row < ima12a.getRowCount(); ++row) {
		for (int col = 0; col < ima12a.getColumnCount(); ++col) {
			assertEquals(0.0, ima12a.getAsDouble(row, col), 0.001);
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:21,代码来源:TestGinv.java

示例3: testNonSquareInverse2

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testNonSquareInverse2() {
	Matrix a = Matrix.Factory.zeros(3, 3);
	a.setAsDouble(4, 0, 0);
	a.setAsDouble(2, 0, 1);
	a.setAsDouble(2, 0, 2);
	a.setAsDouble(-2, 1, 0);
	a.setAsDouble(2, 1, 1);
	a.setAsDouble(4, 1, 2);
	Matrix a12 = a.ginv();
	Matrix a12a = a12.mtimes(a);
	Matrix a12aa12 = a12a.mtimes(a12);
	Matrix aa12a = a.mtimes(a12a);
	for (int row = 0; row < a12aa12.getRowCount(); ++row) {
		for (int col = 0; col < a12aa12.getColumnCount(); ++col) {
			assertEquals(a12.getAsDouble(row, col), a12aa12.getAsDouble(row, col), 0.001);
		}
	}
	for (int row = 0; row < aa12a.getRowCount(); ++row) {
		for (int col = 0; col < aa12a.getColumnCount(); ++col) {
			assertEquals(a.getAsDouble(row, col), aa12a.getAsDouble(row, col), 0.001);
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:25,代码来源:TestGinv.java

示例4: testNonSquareInverse

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testNonSquareInverse() {
	Matrix a = Matrix.Factory.zeros(3, 4);
	a.setAsDouble(4, 0, 0);
	a.setAsDouble(2, 0, 1);
	a.setAsDouble(2, 0, 2);
	a.setAsDouble(2, 0, 3);
	a.setAsDouble(4, 1, 0);
	a.setAsDouble(6, 1, 1);
	a.setAsDouble(8, 1, 2);
	a.setAsDouble(8, 1, 3);
	a.setAsDouble(-2, 2, 0);
	a.setAsDouble(2, 2, 1);
	a.setAsDouble(4, 2, 2);
	a.setAsDouble(4, 2, 3);
	Matrix a12 = a.ginv();
	Matrix ima12a = Ginv.arbitrariness(a, a12);
	for (int row = 0; row < ima12a.getRowCount(); ++row) {
		for (int col = 0; col < ima12a.getColumnCount(); ++col) {
			if (col == 3 && (row == 2 || row == 3)) {
				if (row == 2) {
					assertEquals(-1.0, ima12a.getAsDouble(row, col), 0.001);
				}
				if (row == 3) {
					assertEquals(1.0, ima12a.getAsDouble(row, col), 0.001);
				}
			} else {
				assertEquals(0.0, ima12a.getAsDouble(row, col), 0.001);
			}
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:33,代码来源:TestGinv.java

示例5: testNonSquareArbitrariness

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testNonSquareArbitrariness() {
	Matrix a = Matrix.Factory.zeros(2, 3);
	a.setAsDouble(2, 0, 0);
	a.setAsDouble(1, 0, 1);
	a.setAsDouble(-1, 0, 2);
	a.setAsDouble(1, 1, 0);
	a.setAsDouble(2, 1, 1);
	a.setAsDouble(-1, 1, 2);
	Matrix a12 = a.ginv();
	Matrix a12a = a12.mtimes(a);
	assertTrue(a12.equals(a12a.mtimes(a12)));
	assertTrue(a.equals(a.mtimes(a12a)));
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:15,代码来源:TestGinv.java

示例6: testRandomInverses

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testRandomInverses() {
	Random rand = new Random(System.currentTimeMillis());
	for (int count = 0; count < 10000; ++count) {
		Matrix a = Matrix.Factory.zeros(1 + Math.abs(rand.nextInt()) % 6,
				1 + Math.abs(rand.nextInt()) % 6);
		for (int row = 0; row < a.getRowCount(); ++row) {
			for (int col = 0; col < a.getColumnCount(); ++col) {
				a.setAsDouble(rand.nextDouble(), row, col);
			}
		}
		Matrix a12 = a.ginv();
		Matrix a12a = a12.mtimes(a);
		Matrix a12aa12 = a12a.mtimes(a12);
		Matrix aa12a = a.mtimes(a12a);
		// confirm left and right side inverses:
		for (int row = 0; row < a12aa12.getRowCount(); ++row) {
			for (int col = 0; col < a12aa12.getColumnCount(); ++col) {
				assertEquals(a12.getAsDouble(row, col), a12aa12.getAsDouble(row, col), 0.001);
			}
		}
		for (int row = 0; row < aa12a.getRowCount(); ++row) {
			for (int col = 0; col < aa12a.getColumnCount(); ++col) {
				assertEquals(a.getAsDouble(row, col), aa12a.getAsDouble(row, col), 0.001);
			}
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:29,代码来源:TestGinv.java

示例7: testSquareInverse2

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testSquareInverse2() {
	Matrix a = Matrix.Factory.zeros(3, 3);
	a.setAsDouble(2, 0, 0);
	a.setAsDouble(2, 0, 1);
	a.setAsDouble(4, 0, 2);
	a.setAsDouble(2, 1, 0);
	a.setAsDouble(4, 1, 1);
	a.setAsDouble(6, 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);
	Matrix a12aa12 = a12a.mtimes(a12);
	Matrix aa12a = a.mtimes(a12a);
	for (int row = 0; row < a12aa12.getRowCount(); ++row) {
		for (int col = 0; col < a12aa12.getColumnCount(); ++col) {
			assertEquals(a12.getAsDouble(row, col), a12aa12.getAsDouble(row, col), 0.001);
		}
	}
	for (int row = 0; row < aa12a.getRowCount(); ++row) {
		for (int col = 0; col < aa12a.getColumnCount(); ++col) {
			assertEquals(a.getAsDouble(row, col), aa12a.getAsDouble(row, col), 0.001);
		}
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:28,代码来源:TestGinv.java

示例8: testGinvFixedSmall

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testGinvFixedSmall() throws Exception {
	Matrix m1 = createMatrixWithAnnotation(3, 3);
	m1.setAsDouble(1.0, 0, 0);
	m1.setAsDouble(2.0, 1, 0);
	m1.setAsDouble(3.0, 2, 0);
	m1.setAsDouble(4.0, 0, 1);
	m1.setAsDouble(1.0, 1, 1);
	m1.setAsDouble(2.0, 2, 1);
	m1.setAsDouble(3.0, 0, 2);
	m1.setAsDouble(7.0, 1, 2);
	m1.setAsDouble(1.0, 2, 2);

	Matrix m2 = m1.ginv();

	assertEquals(getLabel(), -0.1970, m2.getAsDouble(0, 0), 0.001);
	assertEquals(getLabel(), 0.2879, m2.getAsDouble(1, 0), 0.001);
	assertEquals(getLabel(), 0.0152, m2.getAsDouble(2, 0), 0.001);
	assertEquals(getLabel(), 0.0303, m2.getAsDouble(0, 1), 0.001);
	assertEquals(getLabel(), -0.1212, m2.getAsDouble(1, 1), 0.001);
	assertEquals(getLabel(), 0.1515, m2.getAsDouble(2, 1), 0.001);
	assertEquals(getLabel(), 0.3788, m2.getAsDouble(0, 2), 0.001);
	assertEquals(getLabel(), -0.0152, m2.getAsDouble(1, 2), 0.001);
	assertEquals(getLabel(), -0.1061, m2.getAsDouble(2, 2), 0.001);

	if (m1 instanceof Erasable) {
		((Erasable) m1).erase();
	}

	if (m2 instanceof Erasable) {
		((Erasable) m2).erase();
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:34,代码来源:AbstractMatrixTest.java

示例9: calculateObjects

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public Map<String, Object> calculateObjects(Map<String, Object> input) {
	Map<String, Object> result = new HashMap<String, Object>();

	Matrix source = MathUtil.getMatrix(input.get(SOURCE));

	Matrix target = source.ginv();
	result.put(TARGET, target);
	return result;
}
 
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:10,代码来源:Ginv.java

示例10: testInverse

import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testInverse() throws Exception {
	Matrix ref1 = Matrix.Factory.zeros(3, 3);
	ref1.setAsDouble(1.0, 0, 0);
	ref1.setAsDouble(2.0, 1, 0);
	ref1.setAsDouble(3.0, 2, 0);
	ref1.setAsDouble(4.0, 0, 1);
	ref1.setAsDouble(1.0, 1, 1);
	ref1.setAsDouble(2.0, 2, 1);
	ref1.setAsDouble(3.0, 0, 2);
	ref1.setAsDouble(7.0, 1, 2);
	ref1.setAsDouble(1.0, 2, 2);
	Matrix ref2 = ref1.inv();

	for (Class<? extends Matrix> mclass : ALLFLOATMATRIXCLASSES) {
		// JBlas not supported for 64 bit on windows
		if (System.getProperty("os.name").toLowerCase().contains("windows")
				&& System.getProperty("java.vm.name").contains("64")
				&& mclass.getName().startsWith("org.ujmp.jblas")) {
			continue;
		}

		Matrix m1 = getMatrix(mclass, ref1);

		if (m1.getClass().getName().startsWith("org.ujmp.owlpack.")) {
			return;
		}

		if (m1.getClass().getName().startsWith("org.ujmp.mtj.")) {
			// mtj has an error with inverse?!
			return;
		}

		Matrix m2 = m1.inv();
		Matrix m3 = m1.pinv();
		Matrix m4 = m1.ginv();
		assertEquals(mclass.toString(), 0.0, ref2.minus(m2).getRMS(), TOLERANCE);
		assertEquals(mclass.toString(), 0.0, ref2.minus(m3).getRMS(), TOLERANCE);
		assertEquals(mclass.toString(), 0.0, ref2.minus(m4).getRMS(), TOLERANCE);
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:42,代码来源:TestCompareMatrices.java


注:本文中的org.ujmp.core.Matrix.ginv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。