本文整理汇总了Java中no.uib.cipr.matrix.sparse.CompRowMatrix类的典型用法代码示例。如果您正苦于以下问题:Java CompRowMatrix类的具体用法?Java CompRowMatrix怎么用?Java CompRowMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompRowMatrix类属于no.uib.cipr.matrix.sparse包,在下文中一共展示了CompRowMatrix类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSparseWriteRead
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
@Test
public void testSparseWriteRead() throws Exception {
CompRowMatrix mat = new CompRowMatrix(3, 3, new int[][]{{1, 2}, {0, 2},
{1}});
mat.set(0, 1, 1);
mat.set(0, 2, 2);
mat.set(1, 0, 3);
mat.set(1, 2, 4);
mat.set(2, 1, 5);
File testFile = new File("TestMatrixFile");
testFile.deleteOnExit();
BufferedWriter out = new BufferedWriter(new FileWriter(testFile));
MatrixVectorWriter writer = new MatrixVectorWriter(out);
MatrixInfo mi = new MatrixInfo(true, MatrixInfo.MatrixField.Real,
MatrixInfo.MatrixSymmetry.General);
writer.printMatrixInfo(mi);
writer.printMatrixSize(
new MatrixSize(mat.numColumns(), mat.numColumns(), mat
.getData().length), mi);
int[] rows = buildRowArray(mat);
writer.printCoordinate(rows, mat.getColumnIndices(), mat.getData(), 1);
out.close();
CompRowMatrix newMat = new CompRowMatrix(new MatrixVectorReader(
new FileReader(testFile)));
MatrixTestAbstract.assertMatrixEquals(mat, newMat);
}
示例2: buildRowArray
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
private int[] buildRowArray(CompRowMatrix mat) {
int[] rows = new int[mat.getData().length];
int curRow = -1;
int nextValidRow = 0;
int curIndex = 0;
int[] rowPs = mat.getRowPointers();
// find first valid row
while (nextValidRow < mat.numRows() && rowPs[nextValidRow] < 0)
nextValidRow++;
while (true) {
curRow = nextValidRow;
nextValidRow++;
while (nextValidRow < mat.numRows() && rowPs[nextValidRow] < 0)
nextValidRow++;
// enter the remainder of data as currentRow
if (nextValidRow >= mat.numRows()) {
while (curIndex < mat.getData().length)
rows[curIndex++] = curRow;
break;
}
int nextRowIndex = rowPs[nextValidRow];
while (curIndex < nextRowIndex)
rows[curIndex++] = curRow;
}
return rows;
}
示例3: testMultiply
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
@Test
public void testMultiply() {
Matrix p = PermutationMatrix.fromPartialPivots(piv);
Matrix c = p
.mult(m,
new CompRowMatrix(new DenseMatrix(m.numRows(), m
.numColumns())));
MatrixTestAbstract.assertMatrixEquals(e, c);
}
示例4: testMultiplyTrans
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
@Test
public void testMultiplyTrans() {
Matrix p = PermutationMatrix.fromPartialPivots(piv);
Matrix c = p
.transAmult(
m,
new CompRowMatrix(new DenseMatrix(m.numRows(), m
.numColumns())));
MatrixTestAbstract.assertMatrixEquals(eI, c);
}
示例5: testMultiplyCompRow
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
@Test
public void testMultiplyCompRow() {
Matrix p = PermutationMatrix.fromPartialPivots(piv);
Matrix c = p.mult(new CompRowMatrix(m), new CompRowMatrix(
new DenseMatrix(m.numRows(), m.numColumns())));
MatrixTestAbstract.assertMatrixEquals(e, c);
}
示例6: testMultiplyTransCompRow
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
@Test
public void testMultiplyTransCompRow() {
Matrix p = PermutationMatrix.fromPartialPivots(piv);
Matrix c = p.transAmult(new CompRowMatrix(m), new CompRowMatrix(
new DenseMatrix(m.numRows(), m.numColumns())));
MatrixTestAbstract.assertMatrixEquals(eI, c);
}
示例7: MtjSparseMatrix
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
public MtjSparseMatrix(
final int numRows,
final int numCols,
final CompRowMatrix matrix) {
super(numRows, numCols);
this.matrix = matrix;
}
示例8: createMtjMatrix
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
private static CompRowMatrix createMtjMatrix(final int numRows, final int numEntriesPerRow, final byte[] bytes) {
final int[][] rows = createMtjMatrixRows(numRows, numEntriesPerRow, bytes);
final CompRowMatrix matrix = new CompRowMatrix(numRows, numRows, rows);
for (int i = 0; i < numRows; ++i) {
for (int j = 0; j < numEntriesPerRow; ++j) {
matrix.set(i, rows[i][j], NONZERO_ELEMENT_VALUE);
}
}
return matrix;
}
示例9: TunedMtjSparseMatrix
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
public TunedMtjSparseMatrix(
final int numRows,
final int numCols,
final CompRowMatrix matrix) {
super(numRows, numCols);
this.matrix = matrix;
}
示例10: testHessian
import no.uib.cipr.matrix.sparse.CompRowMatrix; //导入依赖的package包/类
/**
* http://www.otago.ac.nz/sas/ormp/chap5/sect28.htm
* @throws Exception
*/
@Test
public void testHessian() throws Exception {
if (f == null) {
Assert.fail("Functional has not been set");
}
if (!f.hasHessian()) {
return;
}
if (hds == null) {
Assert.fail("No HalfEdgedatastructure has been set");
}
if (xHess == null) {
System.out.println("No hessian test point set in " + getClass().getSimpleName());
return;
}
int n = f.getDimension(hds);
int[][] nz = f.getNonZeroPattern(hds);
Matrix H = new CompRowMatrix(n, n, nz);
MyHessian hessian = new MyHessian(H);
MyEnergy y = new MyEnergy();
f.evaluate(hds, xHess, y, null, hessian);
double normDif = 0.0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
double fdHessian = 0.0;
double xi = xHess.get(i);
double xj = xHess.get(j);
if (i == j) {
MyEnergy iPlus = new MyEnergy();
MyEnergy iMinus = new MyEnergy();
MyEnergy i2Plus = new MyEnergy();
MyEnergy i2Minus = new MyEnergy();
xHess.set(i, xi + eps);
f.evaluate(hds, xHess, iPlus, null, null);
xHess.set(i, xi + 2*eps);
f.evaluate(hds, xHess, i2Plus, null, null);
xHess.set(i, xi - eps);
f.evaluate(hds, xHess, iMinus, null, null);
xHess.set(i, xi - 2*eps);
f.evaluate(hds, xHess, i2Minus, null, null);
fdHessian = (-i2Plus.E/eps + 16*iPlus.E/eps - 30*y.E/eps + 16*iMinus.E/eps - i2Minus.E/eps) / (12 * eps);
} else {
MyEnergy iPlusjPlus = new MyEnergy();
MyEnergy iPlusjMinus = new MyEnergy();
MyEnergy iMinusjPlus = new MyEnergy();
MyEnergy iMinusjMinus = new MyEnergy();
xHess.set(i, xi + eps);
xHess.set(j, xj + eps);
f.evaluate(hds, xHess, iPlusjPlus, null, null);
xHess.set(i, xi + eps);
xHess.set(j, xj - eps);
f.evaluate(hds, xHess, iPlusjMinus, null, null);
xHess.set(i, xi - eps);
xHess.set(j, xj + eps);
f.evaluate(hds, xHess, iMinusjPlus, null, null);
xHess.set(i, xi - eps);
xHess.set(j, xj - eps);
f.evaluate(hds, xHess, iMinusjMinus, null, null);
fdHessian = (iPlusjPlus.E/eps - iPlusjMinus.E/eps - iMinusjPlus.E/eps + iMinusjMinus.E/eps) / (4 * eps);
}
log.info("fdHess["+i+","+j+"] = " +fdHessian+ "; G["+i+","+j+"] = " + H.get(i,j));
normDif += (fdHessian - H.get(i,j)) * (fdHessian - H.get(i,j));
xHess.set(i, xi);
xHess.set(j, xj);
}
}
normDif = sqrt(normDif);
double normHC = H.norm(Frobenius);
double ratio = normDif / normHC;
Assert.assertEquals(0.0, ratio, error);
}