本文整理汇总了Java中no.uib.cipr.matrix.Matrix类的典型用法代码示例。如果您正苦于以下问题:Java Matrix类的具体用法?Java Matrix怎么用?Java Matrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Matrix类属于no.uib.cipr.matrix包,在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: multAdd
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Override
public Matrix multAdd(double alpha, Matrix B, Matrix C) {
checkMultAdd(B, C);
if (alpha == 0)
return C;
for (int i = 0; i < numRows; i++) {
Node row = links.startOfRow(i);
if (row != null)
for (int j = 0; j < B.numColumns(); j++) {
Node node = row;
double v = 0;
while (node != null && node.row == i) {
v += (B.get(node.col, j) * node.val);
node = node.rowTail;
}
if (v != 0)
C.add(i, j, alpha * v);
}
}
return C;
}
示例2: transBmultAdd
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Override
public Matrix transBmultAdd(double alpha, Matrix B, Matrix C) {
checkTransBmultAdd(B, C);
if (alpha == 0)
return C;
for (int i = 0; i < numRows; i++) {
Node row = links.startOfRow(i);
if (row != null)
for (int j = 0; j < B.numRows(); j++) {
Node node = row;
double v = 0;
while (node != null && node.row == i) {
v += (B.get(j, node.col) * node.val);
node = node.rowTail;
}
if (v != 0)
C.add(i, j, alpha * v);
}
}
return C;
}
示例3: transAmultAdd
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Override
public Matrix transAmultAdd(double alpha, Matrix B, Matrix C) {
checkTransAmultAdd(B, C);
if (alpha == 0)
return C;
for (int i = 0; i < numColumns; i++) {
Node row = links.startOfCol(i);
if (row != null)
for (int j = 0; j < B.numColumns(); j++) {
Node node = row;
double v = 0;
while (node != null && node.col == i) {
v += (B.get(node.row, j) * node.val);
node = node.colTail;
}
if (v != 0)
C.add(i, j, alpha * v);
}
}
return C;
}
示例4: transABmultAdd
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Override
public Matrix transABmultAdd(double alpha, Matrix B, Matrix C) {
checkTransABmultAdd(B, C);
if (alpha == 0)
return C;
for (int i = 0; i < numColumns; i++) {
Node row = links.startOfCol(i);
if (row != null)
for (int j = 0; j < B.numRows(); j++) {
Node node = row;
double v = 0;
while (node != null && node.col == i) {
v += (B.get(j, node.row) * node.val);
node = node.colTail;
}
if (v != 0)
C.add(i, j, alpha * v);
}
}
return C;
}
示例5: setMatrix
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public void setMatrix(Matrix A) {
F.set(A);
int n = F.numRows();
int[] rowptr = F.getRowPointers();
int[] colind = F.getColumnIndices();
// Find the indices to the diagonal entries
for (int k = 0; k < n; ++k) {
diagind[k] = Arrays.binarySearch(colind, k, rowptr[k],
rowptr[k + 1]);
if (diagind[k] < 0)
throw new RuntimeException("Missing diagonal on row " + (k + 1));
}
}
示例6: ignoredTimedTransMult
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public void ignoredTimedTransMult() {
Stopwatch watch = Stopwatch.createUnstarted();
DenseMatrix dense = new DenseMatrix(1000, 1000);
int[][] nz = Utilities.getRowPattern(dense.numRows(),
dense.numColumns(), 100);
Utilities.rowPopulate(dense, nz);
log.info("created matrices");
Matrix sparse = new LinkedSparseMatrix(dense.numRows(),
dense.numColumns());
sparse.set(dense);
for (Matrix m : Lists.newArrayList(dense, sparse)) {
log.info("starting " + m.getClass());
Matrix t = new DenseMatrix(m);
Matrix o = new DenseMatrix(dense.numRows(), dense.numColumns());
log.info("warming up " + m.getClass() + " " + o.getClass());
for (int i = 0; i < 10; i++)
m.transAmult(t, o);
log.info("starting " + m.getClass() + " " + o.getClass());
watch.start();
for (int i = 0; i < 100; i++)
m.transAmult(t, o);
watch.stop();
log.info(m.getClass() + " " + o.getClass() + " " + watch);
}
}
示例7: testWriteRead
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Test
public void testWriteRead() throws Exception {
DenseMatrix mat = new DenseMatrix(
new double[][]{{1.1, 1.2}, {1.3, 1.4}});
File matrixFile = new File("TestMatrixFile");
BufferedWriter out = new BufferedWriter(new FileWriter(matrixFile));
MatrixVectorWriter writer = new MatrixVectorWriter(out);
MatrixInfo mi = new MatrixInfo(false, MatrixInfo.MatrixField.Real,
MatrixInfo.MatrixSymmetry.General);
writer.printMatrixInfo(mi);
writer.printMatrixSize(new MatrixSize(mat.numRows(), mat.numColumns(),
mat.numColumns() * mat.numRows()), mi);
writer.printArray(mat.getData());
writer.close();
Matrix newMat = new DenseMatrix(new MatrixVectorReader(new FileReader(
matrixFile)));
MatrixTestAbstract.assertMatrixEquals(mat, newMat);
}
示例8: testSample
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public void testSample ()
{
Variable v1 = new Variable (Variable.CONTINUOUS);
Variable v2 = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
// Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});
VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
Factor f = new NormalFactor (vars, mu, var);
TDoubleArrayList v1lst = new TDoubleArrayList ();
TDoubleArrayList v2lst = new TDoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
v1lst.add (assn.getDouble (v1));
v2lst.add (assn.getDouble (v2));
}
checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
}
示例9: testGetPermutationMatrix
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
/**
* Checks to see if a matrix can be permuted correctly given a permutation vector. The
* permutation is done both on rows and columns
*/
@Test
public void testGetPermutationMatrix() {
Matrix M = new DenseMatrix(new double[][] {
new double[] { 1, 5, 9, 13 },
new double[] { 2, 6, 10, 14 },
new double[] { 3, 7, 11, 15 },
new double[] { 4, 8, 12, 16 },
});
int[] permutations = new int[] { 3, 2, 1, 0 };
Matrix R = GraphPartition.getPermutedMatrix(M, permutations);
Matrix R_e = new DenseMatrix(new double[][] {
new double[] { 16, 12, 8, 4 },
new double[] { 15, 11, 7, 3 },
new double[] { 14, 10, 6, 2 },
new double[] { 13, 9, 5, 1 },
});
assertArrayEquals(Matrices.getArray(R_e), Matrices.getArray(R));
}
示例10: calculateCodifferential
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
private static <
V extends Vertex<V,E,F>,
E extends Edge<V,E,F>,
F extends Face<V,E,F>,
HDS extends HalfEdgeDataStructure<V, E, F>
> Matrix calculateCodifferential(HDS heds, AdapterSet adapters, int dim) {
Matrix hs0inv = invertDiagonalMatrix(getHodgeStar(heds, adapters, dim));
Matrix hs1 = getHodgeStar(heds, adapters, dim+1);
Matrix bd = getBoundaryOperator(heds, adapters, dim);
int[][] nz = getColumnNonZeros(bd);
Matrix M = new CompColMatrix(bd.numRows(),bd.numColumns(),nz);
M.set(bd);
for(MatrixEntry me : M) {
double val = me.get();
me.set(-1.0*hs0inv.get(me.row(), me.row())*hs1.get(me.column(), me.column())*val);
}
return M;
}
示例11: getLaplaceOperator
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public static <
V extends Vertex<V,E,F>,
E extends Edge<V,E,F>,
F extends Face<V,E,F>,
HDS extends HalfEdgeDataStructure<V, E, F>
> Matrix getLaplaceOperator(HDS heds, AdapterSet adapters, int dim) {
if(dim < 0 || dim > 2) {
throw new IllegalArgumentException("No laplacian for dimension "+dim);
}
Matrix M = null;
switch (dim) {
case 0:
return calculateLaplaceOperator(heds, adapters, dim);
case 1:
return calculateLaplaceOperator(heds, adapters, dim);
case 2:
return calculateLaplaceOperator(heds, adapters, dim);
}
return M;
}
示例12: testSample
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public void testSample ()
{
Variable v1 = new Variable (Variable.CONTINUOUS);
Variable v2 = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
// Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});
VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
Factor f = new NormalFactor (vars, mu, var);
TDoubleArrayList v1lst = new TDoubleArrayList();
TDoubleArrayList v2lst = new TDoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
v1lst.add (assn.getDouble (v1));
v2lst.add (assn.getDouble (v2));
}
checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
}
示例13: ignoretestSample
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
public void ignoretestSample ()
{
Variable v1 = new Variable (Variable.CONTINUOUS);
Variable v2 = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
// Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});
VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
Factor f = new NormalFactor (vars, mu, var);
DoubleArrayList v1lst = new DoubleArrayList ();
DoubleArrayList v2lst = new DoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
v1lst.add (assn.getDouble (v1));
v2lst.add (assn.getDouble (v2));
}
checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
}
示例14: transform
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
/**
* Optimized method for matrix and diagonal matrix multiplication
*
* @param documents
* A List of documents
* @return sparse input matrix
*/
public Matrix transform(List<String> documents) {
Matrix X = this.countVocab(documents);
if (this.useIdf) {
// theoretically, use X * idf_diagonal should be faster.
// unfortunately, the writer of mtj doesn't optimize it.
// I use a manully optimization to make it faster.
for(MatrixEntry e: X){
e.set(e.get() * this.idfDiag[e.column()]);
}
}
// normalization
this.rowNormalize(X);
return X;
}
示例15: getQRDecomposition
import no.uib.cipr.matrix.Matrix; //导入依赖的package包/类
@Override
public Pair<IMatrix, IMatrix> getQRDecomposition() {
Matrix input = internalMatrix.copy();
// If the Matrix has the wrong dimensions
if (input.numRows() < input.numColumns()) {
input = input.transpose(new LinkedSparseMatrix(input.numColumns(), input.numRows()));
}
QR rs = QR.factorize(input);
return Pair.of(new SparseDoubleMatrix(rs.getQ()), new SparseDoubleMatrix(rs.getR()));
}