List of usage examples for org.apache.commons.math.linear RealMatrix getRowVector
RealVector getRowVector(int row) throws MatrixIndexException;
row as a vector. From source file:fi.smaa.libror.MaximalVectorComputation.java
private static LinkedList<RealVector> matrixToListOfRows(RealMatrix mat) { LinkedList<RealVector> list = new LinkedList<RealVector>(); for (int i = 0; i < mat.getRowDimension(); i++) { list.add(mat.getRowVector(i)); }/* w ww . j a v a 2 s . co m*/ return list; }
From source file:fi.smaa.libror.MaximalVectorComputation.java
/** * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007. * //from w w w. j a v a 2s.com * Returns indices of the rows from the original matrix. * * @param mat The matrix of values (each row = 1 vector of input) * * @return Matrix containing rows from the input s.t. none are dominated */ public static int[] computeBESTindices(RealMatrix mat) { LinkedList<Integer> list = matrixToListOfIndices(mat); LinkedList<Integer> results = new LinkedList<Integer>(); while (list.size() > 0) { Iterator<Integer> iter = list.iterator(); Integer b = iter.next(); // Get the first iter.remove(); while (iter.hasNext()) { // Find a max Integer t = iter.next(); if (dominates(mat.getRowVector(b), mat.getRowVector(t))) { iter.remove(); } else if (dominates(mat.getRowVector(t), mat.getRowVector(b))) { iter.remove(); b = t; } } results.add(b); iter = list.iterator(); while (iter.hasNext()) { // Clean up Integer t = iter.next(); if (dominates(mat.getRowVector(b), mat.getRowVector(t))) { iter.remove(); } } } return listOfIntegersToIntArray(results); }
From source file:fi.smaa.libror.eff.FastROR.java
private boolean isNecessarilyPreferred(int i, int j) { RealMatrix mat = ror.getPerfMatrix().getMatrix(); if (MaximalVectorComputation.dominates(mat.getRowVector(i), mat.getRowVector(j))) { return true; }/* ww w . j av a 2 s .c om*/ return false; }
From source file:eu.amidst.core.exponentialfamily.EF_Normal_NormalParents2.java
/** * {@inheritDoc}/*www . j a va 2 s . co m*/ */ @Override public double getExpectedLogNormalizer(Map<Variable, MomentParameters> momentParents) { CompoundVector globalNaturalParameters = (CompoundVector) this.naturalParameters; double logNorm = -0.5 * Math.log(-2 * globalNaturalParameters.getTheta_Minus1()); double[] Yarray = new double[nOfParents]; double[] YYarray = new double[nOfParents]; for (int i = 0; i < nOfParents; i++) { Yarray[i] = momentParents.get(this.getConditioningVariables().get(i)).get(0); YYarray[i] = momentParents.get(this.getConditioningVariables().get(i)).get(1); } RealVector Y = new ArrayRealVector(Yarray); logNorm -= globalNaturalParameters.getTheta_beta0BetaRV().dotProduct(new ArrayRealVector(Y)); RealMatrix YY = Y.outerProduct(Y); for (int i = 0; i < nOfParents; i++) { YY.setEntry(i, i, YYarray[i]); } logNorm -= IntStream.range(0, nOfParents).mapToDouble(p -> { return globalNaturalParameters.getTheta_BetaBetaRM().getRowVector(p).dotProduct(YY.getRowVector(p)); }).sum(); logNorm -= Math.pow(globalNaturalParameters.getTheta_beta0(), 2) / (4 * globalNaturalParameters.getTheta_Minus1()); return logNorm; }
From source file:org.caleydo.view.bicluster.elem.layout.MDSLayout.java
@Override public boolean doLayout(List<? extends IGLLayoutElement> children, float w_p, float h_p, IGLLayoutElement parent, int deltaTimeMs) { final int n = children.size(); RealMatrix a = MatrixUtils.createRealMatrix(n, n); // Sind als Startwerte anstatt Distanzen hnlichkeitsmae c_{ij} zwischen Objekten gegeben, so lassen sich diese // durch die Transformation ///*from ww w .j av a 2 s.c om*/ // d_{ij} = \sqrt{c_{ii}+c_{jj}-2c_{ij}} // // in Distanzen berfhren. for (int i = 0; i < n; ++i) { ClusterElement ci = (ClusterElement) children.get(i).asElement(); int c_ii = ci.getDimSize() + ci.getRecSize(); for (int j = i + 1; j < n; ++j) { ClusterElement cj = (ClusterElement) children.get(j).asElement(); int recOverlap = ci.getRecOverlap(cj); int dimOverlap = ci.getDimOverlap(cj); int c_jj = cj.getDimSize() + cj.getRecSize(); int c_ij = recOverlap + dimOverlap; double d_ij = Math.sqrt(c_ii + c_jj - 2 * c_ij); a.setEntry(i, j, d_ij); a.setEntry(j, i, d_ij); } } //#1. negative squared dissimilarity matrix Q //q = as.matrix( -0.5 * d ** 2 ) RealMatrix q = a.copy(); for (int i = 0; i < n; ++i) { q.getRowVector(i).mapPowToSelf(2); } q = q.scalarMultiply(-0.5); //#2. centering matrix H //h = diag(n) - 1/n * 1 RealMatrix h = MatrixUtils.createRealMatrix(n, n); for (int i = 0; i < n; ++i) h.setEntry(i, i, n - 1. / n * 1); //#3. double-center matrix B //b = h %*% q %*% h RealMatrix b = h.copy().multiply(q).multiply(h); // #4. eigen decomposition of B // eig = eigen(b) EigenDecompositionImpl eig = new EigenDecompositionImpl(b, 0); // #5. use top k values/vectors to compute projected points // points = eig$vectors[,1:k] %*% diag(sqrt(eig$values[1:k])) for (int i = 0; i < n; ++i) { RealVector v = eig.getEigenvector(i).getSubVector(0, 2); double x = v.getEntry(0) * eig.getRealEigenvalue(0); double y = v.getEntry(1) * eig.getRealEigenvalue(1); IGLLayoutElement child = children.get(i); child.setLocation((float) x, (float) y); } return false; }