no.uib.cipr.matrix.DenseVector Java Examples
The following examples show how to use
no.uib.cipr.matrix.DenseVector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EDCoWModularityDetection.java From SONDY with GNU General Public License v3.0 | 6 votes |
public void explore(Community c){ if(c.getChild1() == null){ DenseVector nodesC = c.getVertexIndexes(); EDCoWEvent event = new EDCoWEvent(); for(VectorEntry ve : nodesC){ int id = (int)ve.get(); event.keywords.add(nodeList.get(id).getName()); event.setEpsylon(computeE(c)); event.setStartSlice(startSlice); event.setEndSlice(endSlice); } events.add(event); }else{ explore(c.getChild1()); explore(c.getChild2()); } }
Example #2
Source File: CompDiagMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector mult(Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.mult(x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); y.zero(); for (int i = 0; i < ind.length; ++i) { int row = ind[i] < 0 ? -ind[i] : 0; int column = ind[i] > 0 ? ind[i] : 0; double[] locDiag = diag[i]; for (int j = 0; j < locDiag.length; ++j, ++row, ++column) yd[row] += locDiag[j] * xd[column]; } return y; }
Example #3
Source File: GMRFMultilocusSkyrideLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
double getLogFieldLikelihood() { checkIntervals(); // TODO Is this really necessary? Computation below does not appear to depend on intervals. DenseVector diagonal1 = new DenseVector(fieldLength); DenseVector currentGamma = getMeanAdjustedGamma(); double currentLike = handleMissingValues(); SymmTridiagMatrix currentQ = getScaledWeightMatrix(precisionParameter.getParameterValue(0), lambdaParameter.getParameterValue(0)); currentQ.mult(currentGamma, diagonal1); currentLike += 0.5 * (fieldLength - 1) * Math.log(precisionParameter.getParameterValue(0)) - 0.5 * currentGamma.dot(diagonal1); if (lambdaParameter.getParameterValue(0) == 1) { currentLike -= (fieldLength - 1) / 2.0 * LOG_TWO_TIMES_PI; } else { currentLike -= fieldLength / 2.0 * LOG_TWO_TIMES_PI; } return currentLike; }
Example #4
Source File: UpperCompRowMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transSolve(Vector b, Vector x) { if (!(x instanceof DenseVector)) return super.transSolve(b, x); x.set(b); double[] xd = ((DenseVector) x).getData(); for (int i = 0; i < numRows; ++i) { // Solve for the current entry xd[i] /= data[diagind[i]]; // Move this known solution over to the right hand side for the // remaining equations for (int j = diagind[i] + 1; j < rowptr[i + 1]; ++j) xd[colind[j]] -= data[j] * xd[i]; } return x; }
Example #5
Source File: UpperCompRowMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector solve(Vector b, Vector x) { if (!(b instanceof DenseVector) || !(x instanceof DenseVector)) return super.solve(b, x); double[] bd = ((DenseVector) b).getData(); double[] xd = ((DenseVector) x).getData(); for (int i = numRows - 1; i >= 0; --i) { // xi = (bi - sum[j>i] Uij * xj) / Uii double sum = 0; for (int j = diagind[i] + 1; j < rowptr[i + 1]; ++j) sum += data[j] * xd[colind[j]]; xd[i] = (bd[i] - sum) / data[diagind[i]]; } return x; }
Example #6
Source File: CompColMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transMultAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.transMultAdd(alpha, x, y); checkTransMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < numColumns; ++i) { double dot = 0; for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j) dot += data[j] * xd[rowIndex[j]]; yd[i] += alpha * dot; } return y; }
Example #7
Source File: CompColMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transMult(Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.transMult(x, y); checkTransMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < numColumns; ++i) { double dot = 0; for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j) dot += data[j] * xd[rowIndex[j]]; yd[i] = dot; } return y; }
Example #8
Source File: CompColMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); // y = 1/alpha * y y.scale(1 / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j) yd[rowIndex[j]] += data[j] * xd[i]; // y = alpha*y = alpha*A*x + y return y.scale(alpha); }
Example #9
Source File: EDCoWModularityDetection.java From SONDY with GNU General Public License v3.0 | 6 votes |
public double computeEdgesWeight(Community c, List<Node> nodeList){ double totalWeight =0; if(c.getChild1() == null){ DenseVector nodesC = c.getVertexIndexes(); for(VectorEntry ve : nodesC){ int id = (int)ve.get(); Set<Edge<Node>> edges = structure.getEdges(nodeList.get(id)); for(Edge e:edges){ if(e.getSource().equals(nodeList.get(id))) totalWeight += e.getWeight(); } } }else{ computeEdgesWeight(c.getChild1(),nodeList); computeEdgesWeight(c.getChild2(),nodeList); } return totalWeight; }
Example #10
Source File: SparseVectorTest.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testBug27() { double[] tfVector = {0.0, 0.5, 0.0, 0.4, 0.0}; DenseVector dense = new DenseVector(tfVector, false); SparseVector vectorTF = new SparseVector(dense); vectorTF.compact(); assertTrue(vectorTF.getUsed() == 2); // vectorTF.getUsed() returns 5 for (Iterator<VectorEntry> it = vectorTF.iterator(); it.hasNext();) { VectorEntry ve = it.next(); int index = ve.index(); double value = ve.get(); assertTrue(tfVector[index] == value); } }
Example #11
Source File: ILUT.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
/** * Sets up the preconditioner for the given matrix * * @param LU * Matrix to use internally. For best performance, its non-zero * pattern should conform to that of the system matrix * @param tau * Drop tolerance * @param p * Number of entries to keep on each row in of the factored * matrix. This is in addition to the entries of the original * matrix */ public ILUT(FlexCompRowMatrix LU, double tau, int p) { if (!LU.isSquare()) throw new IllegalArgumentException( "ILU only applies to square matrices"); this.LU = LU; this.tau = tau; this.p = p; int n = LU.numRows(); lower = new ArrayList<IntDoubleEntry>(n); upper = new ArrayList<IntDoubleEntry>(n); y = new DenseVector(n); diagind = new int[n]; }
Example #12
Source File: ILUT.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector solve(Vector b, Vector x) { if (!(b instanceof DenseVector) || !(x instanceof DenseVector)) return super.solve(b, x); double[] bd = ((DenseVector) b).getData(); double[] xd = ((DenseVector) x).getData(); for (int i = 0; i < numRows; ++i) { // Get row i SparseVector row = LU.getRow(i); int[] index = row.getIndex(); double[] data = row.getData(); // xi = bi - sum[j<i] Lij * xj double sum = 0; for (int j = 0; j < diagind[i]; ++j) sum += data[j] * xd[index[j]]; xd[i] = bd[i] - sum; } return x; }
Example #13
Source File: ILUT.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transSolve(Vector b, Vector x) { if (!(x instanceof DenseVector)) return super.transSolve(b, x); x.set(b); double[] xd = ((DenseVector) x).getData(); for (int i = numRows - 1; i >= 0; --i) { // Get row i SparseVector row = LU.getRow(i); int[] index = row.getIndex(); double[] data = row.getData(); // At this stage, x[i] is known, so move it over to the right // hand side for the remaining equations for (int j = 0; j < diagind[i]; ++j) xd[index[j]] -= data[j] * xd[i]; } return x; }
Example #14
Source File: ILUT.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector solve(Vector b, Vector x) { if (!(b instanceof DenseVector) || !(x instanceof DenseVector)) return super.solve(b, x); double[] bd = ((DenseVector) b).getData(); double[] xd = ((DenseVector) x).getData(); for (int i = numRows - 1; i >= 0; --i) { // Get row i SparseVector row = LU.getRow(i); int[] index = row.getIndex(); int used = row.getUsed(); double[] data = row.getData(); // xi = (bi - sum[j>i] Uij * xj) / Uii double sum = 0; for (int j = diagind[i] + 1; j < used; ++j) sum += data[j] * xd[index[j]]; xd[i] = (bd[i] - sum) / data[diagind[i]]; } return x; }
Example #15
Source File: UnitLowerCompRowMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector solve(Vector b, Vector x) { if (!(b instanceof DenseVector) || !(x instanceof DenseVector)) return super.solve(b, x); double[] bd = ((DenseVector) b).getData(); double[] xd = ((DenseVector) x).getData(); for (int i = 0; i < numRows; ++i) { // xi = bi - sum[j<i] Lij * xj double sum = 0; for (int j = rowptr[i]; j < diagind[i]; ++j) sum += data[j] * xd[colind[j]]; xd[i] = bd[i] - sum; } return x; }
Example #16
Source File: UnitLowerCompRowMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transSolve(Vector b, Vector x) { if (!(x instanceof DenseVector)) return super.transSolve(b, x); x.set(b); double[] xd = ((DenseVector) x).getData(); for (int i = numRows - 1; i >= 0; --i) // At this stage, x[i] is known, so move it over to the right hand // side for the remaining equations for (int j = rowptr[i]; j < diagind[i]; ++j) xd[colind[j]] -= data[j] * xd[i]; return x; }
Example #17
Source File: FlexCompRowMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transMultAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.transMultAdd(alpha, x, y); checkTransMultAdd(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); // y = 1/alpha * y y.scale(1. / alpha); // y = A'x + y for (int i = 0; i < numRows; ++i) { SparseVector v = rowD[i]; int[] index = v.getIndex(); double[] data = v.getData(); int length = v.getUsed(); for (int j = 0; j < length; ++j) yd[index[j]] += data[j] * xd[i]; } // y = alpha*y = alpha * A'x + y return y.scale(alpha); }
Example #18
Source File: CompDiagMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < ind.length; ++i) { int row = ind[i] < 0 ? -ind[i] : 0; int column = ind[i] > 0 ? ind[i] : 0; double[] locDiag = diag[i]; for (int j = 0; j < locDiag.length; ++j, ++row, ++column) yd[row] += alpha * locDiag[j] * xd[column]; } return y; }
Example #19
Source File: OldGMRFSkyrideLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
protected double calculateLogFieldLikelihood() { makeIntervalsKnown(); double currentLike = 0; DenseVector diagonal1 = new DenseVector(fieldLength); DenseVector currentGamma = new DenseVector(popSizeParameter.getParameterValues()); SymmTridiagMatrix currentQ = getScaledWeightMatrix(precisionParameter.getParameterValue(0), lambdaParameter.getParameterValue(0)); currentQ.mult(currentGamma, diagonal1); // currentLike += 0.5 * logGeneralizedDeterminant(currentQ) - 0.5 * currentGamma.dot(diagonal1); currentLike += 0.5 * (fieldLength - 1) * Math.log(precisionParameter.getParameterValue(0)) - 0.5 * currentGamma.dot(diagonal1); if (lambdaParameter.getParameterValue(0) == 1) { currentLike -= (fieldLength - 1) / 2.0 * LOG_TWO_TIMES_PI; } else { currentLike -= fieldLength / 2.0 * LOG_TWO_TIMES_PI; } return currentLike; }
Example #20
Source File: GMRFSkyrideLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
protected double calculateLogFieldLikelihood() { makeIntervalsKnown(); double currentLike = 0; DenseVector diagonal1 = new DenseVector(fieldLength); DenseVector currentGamma = new DenseVector(popSizeParameter.getParameterValues()); SymmTridiagMatrix currentQ = getScaledWeightMatrix(precisionParameter.getParameterValue(0), lambdaParameter.getParameterValue(0)); currentQ.mult(currentGamma, diagonal1); // currentLike += 0.5 * logGeneralizedDeterminant(currentQ) - 0.5 * currentGamma.dot(diagonal1); currentLike += 0.5 * (fieldLength - 1) * Math.log(precisionParameter.getParameterValue(0)) - 0.5 * currentGamma.dot(diagonal1); if (lambdaParameter.getParameterValue(0) == 1) { currentLike -= (fieldLength - 1) / 2.0 * LOG_TWO_TIMES_PI; } else { currentLike -= fieldLength / 2.0 * LOG_TWO_TIMES_PI; } return currentLike; }
Example #21
Source File: FlexCompColMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); // y = 1/alpha * y y.scale(1. / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) { SparseVector v = colD[i]; int[] index = v.getIndex(); double[] data = v.getData(); int length = v.getUsed(); for (int j = 0; j < length; ++j) yd[index[j]] += data[j] * xd[i]; } // y = alpha*y = alpha * A'x + y return y.scale(alpha); }
Example #22
Source File: MtjMatrixTest.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
@Test public void testMultiply() { double[][] tmpMatrix = { { 1, 2, 3 }, { 4, 5, 6 } }; double[] tmpVector = { 1, 2, 3 }; double[] resultExpected = { 14, 32 }; DenseMatrix denseMatrix = new DenseMatrix(tmpMatrix); DenseVector denseVector = new DenseVector(tmpVector); AbstractMatrix abstractMatrix = new MtjMatrix(denseMatrix); AbstractVector abstractVector = new MtjVector(denseVector); AbstractVector resultActual = abstractMatrix.multiply(abstractVector); assertEquals(resultExpected.length, resultActual.getDimension()); for (int i = 0; i < resultActual.getDimension(); i++) { assertEquals(resultExpected[i], resultActual.getEntry(i), Helper.TOLERANCE); } }
Example #23
Source File: MtjSolver.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
/** * @see AbstractSolver#solve(AbstractMatrix, AbstractVector) */ @Override public AbstractVector solve(AbstractMatrix m, AbstractVector b) { if (m instanceof MtjMatrix && b instanceof MtjVector) { DenseVector result = new DenseVector(m.getRowDimension()); no.uib.cipr.matrix.AbstractMatrix systemMatrix = ((MtjMatrix) m).getMatrix(); DenseVector bMtj = ((MtjVector) b).getVector(); CG cg = new CG(result); try { cg.solve(systemMatrix, bMtj, result); } catch (IterativeSolverNotConvergedException e) { throw new RuntimeException(e.getMessage()); } return new MtjVector(result); } throw new UnsupportedOperationException(); }
Example #24
Source File: CompDiagMatrix.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Vector transMultAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.transMultAdd(alpha, x, y); checkTransMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < ind.length; ++i) { int row = ind[i] < 0 ? -ind[i] : 0; int column = ind[i] > 0 ? ind[i] : 0; double[] locDiag = diag[i]; for (int j = 0; j < locDiag.length; ++j, ++row, ++column) yd[column] += alpha * locDiag[j] * xd[row]; } return y; }
Example #25
Source File: GMRFSkygridLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
double getLogFieldLikelihood() { if (!intervalsKnown) { //intervalsKnown -> false when handleModelChanged event occurs in super. wrapSetupIntervals(); for(IntervalList intervalList : intervalsList){ intervalList.calculateIntervals(); } setupSufficientStatistics(); intervalsKnown = true; } DenseVector diagonal1 = new DenseVector(fieldLength); DenseVector currentGamma = new DenseVector(popSizeParameter.getParameterValues()); updateGammaWithCovariates(currentGamma); double currentLike = handleMissingValues(); SymmTridiagMatrix currentQ = getScaledWeightMatrix(precisionParameter.getParameterValue(0), lambdaParameter.getParameterValue(0)); currentQ.mult(currentGamma, diagonal1); currentLike += 0.5 * (fieldLength - 1) * Math.log(precisionParameter.getParameterValue(0)) - 0.5 * currentGamma.dot(diagonal1); if (lambdaParameter.getParameterValue(0) == 1) { currentLike -= (fieldLength - 1) / 2.0 * LOG_TWO_TIMES_PI; } else { currentLike -= fieldLength / 2.0 * LOG_TWO_TIMES_PI; } return currentLike; }
Example #26
Source File: AMG.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates the entries of the Galerkin operator * <code>Ac = I<sup>T</sup> A I</code>. This is a very time-consuming * operation */ private static CompRowMatrix createGalerkinSlow(CompColMatrix I, CompRowMatrix A) { int n = I.numRows(), c = I.numColumns(); FlexCompRowMatrix acMatrix = new FlexCompRowMatrix(c, c); double[] aiCol = new double[n]; double[] iCol = new double[n]; DenseVector aiV = new DenseVector(aiCol, false); DenseVector iV = new DenseVector(iCol, false); double[] itaiCol = new double[c]; DenseVector itaiV = new DenseVector(itaiCol, false); int[] colptr = I.getColumnPointers(); int[] rowind = I.getRowIndices(); double[] Idata = I.getData(); for (int k = 0; k < c; ++k) { // Expand column 'k' of I to dense storage iV.zero(); for (int i = colptr[k]; i < colptr[k + 1]; ++i) iCol[rowind[i]] = Idata[i]; // Form column 'k' of A*I A.mult(iV, aiV); // Form column 'k' of I'*A*I I.transMult(aiV, itaiV); // Store non-zeros into Ac for (int i = 0; i < c; ++i) if (itaiCol[i] != 0) acMatrix.set(i, k, itaiCol[i]); } return new CompRowMatrix(acMatrix); }
Example #27
Source File: ILUT.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Vector transSolve(Vector b, Vector x) { if (!(x instanceof DenseVector)) return super.transSolve(b, x); x.set(b); double[] xd = ((DenseVector) x).getData(); for (int i = 0; i < numRows; ++i) { // Get row i SparseVector row = LU.getRow(i); int[] index = row.getIndex(); int used = row.getUsed(); double[] data = row.getData(); // Solve for the current entry xd[i] /= data[diagind[i]]; // Move this known solution over to the right hand side for the // remaining equations for (int j = diagind[i] + 1; j < used; ++j) xd[index[j]] -= data[j] * xd[i]; } return x; }
Example #28
Source File: MtjMatrix.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
/** * @see AbstractMatrix#multiply(AbstractVector) */ @Override public AbstractVector multiply(AbstractVector vector) { if (vector.getDimension() != this.matrix.numColumns()) { throw new IllegalArgumentException("Dimension mismatch"); } if (vector instanceof MtjVector) { DenseVector v = ((MtjVector) vector).getVector(); DenseVector result = new DenseVector(this.matrix.numRows()); this.matrix.mult(v, result); return new MtjVector(result); } throw new UnsupportedOperationException(); }
Example #29
Source File: DiagonalPreconditioner.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 5 votes |
public Vector apply(Vector b, Vector x) { if (!(x instanceof DenseVector) || !(b instanceof DenseVector)) throw new IllegalArgumentException("Vector must be DenseVectors"); double[] xd = ((DenseVector) x).getData(); double[] bd = ((DenseVector) b).getData(); for (int i = 0; i < invdiag.length; ++i) xd[i] = bd[i] * invdiag[i]; return x; }
Example #30
Source File: MtjVector.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
/** * @see ApacheVector#subtract(AbstractVector) */ @Override public AbstractVector subtract(AbstractVector v) { if (v instanceof MtjVector) { DenseVector tmp = ((MtjVector) v).getVector(); tmp.scale(-1); tmp.add(this.vector); return new MtjVector(tmp); } else { throw new UnsupportedOperationException(); } }