Java Code Examples for org.ejml.simple.SimpleMatrix#mult()
The following examples show how to use
org.ejml.simple.SimpleMatrix#mult() .
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: TextRankSummarization.java From cocolian-nlp with Apache License 2.0 | 6 votes |
/** * 用textRank算法计算权重矩阵。 * * @param matrix * @return */ protected SimpleMatrix buildWeightVector(SimpleMatrix matrix) { SimpleMatrix vector = new SimpleMatrix(matrix.numCols(), 1); vector.set(1); SimpleMatrix vecDamp = new SimpleMatrix(matrix.numCols(), 1); vecDamp.set(1- this.damp); double diff = 1; while(diff > this.threshold){ SimpleMatrix next = matrix.mult(vector); //next = (1-damp)+damp * next; next = vecDamp.plus(this.damp, next); diff = next.minus(vector).normF(); vector = next; // System.out.println("weight=========="); // System.out.println(vector); } return vector; }
Example 2
Source File: TextRankSummarization.java From cocolian-nlp with Apache License 2.0 | 5 votes |
/** * 将matrix归一化处理。 * * @param matrix */ protected void normalize(SimpleMatrix matrix) { SimpleMatrix one = new SimpleMatrix(matrix.numCols(), matrix.numRows()); one.set(1); SimpleMatrix sum = matrix.mult(one); //CommonOps.elementDiv(matrix.getMatrix(), sum.getMatrix()); matrix.set(matrix.elementDiv(sum)); //CommonOps.transpose(matrix.getMatrix()); matrix.set(matrix.transpose()); }
Example 3
Source File: FactorGraphTrueSkillCalculator.java From ACManager with GNU General Public License v3.0 | 5 votes |
@Override public double calculateMatchQuality(GameInfo gameInfo, Collection<ITeam> teams) { // We need to create the A matrix which is the player team assignments. List<ITeam> teamAssignmentsList = new ArrayList<>(teams); SimpleMatrix skillsMatrix = GetPlayerCovarianceMatrix(teamAssignmentsList); SimpleMatrix meanVector = GetPlayerMeansVector(teamAssignmentsList); SimpleMatrix meanVectorTranspose = meanVector.transpose(); SimpleMatrix playerTeamAssignmentsMatrix = CreatePlayerTeamAssignmentMatrix(teamAssignmentsList, meanVector.numRows()); SimpleMatrix playerTeamAssignmentsMatrixTranspose = playerTeamAssignmentsMatrix.transpose(); double betaSquared = square(gameInfo.getBeta()); SimpleMatrix start = meanVectorTranspose.mult(playerTeamAssignmentsMatrix); SimpleMatrix aTa = playerTeamAssignmentsMatrixTranspose.mult(playerTeamAssignmentsMatrix).scale(betaSquared); SimpleMatrix aTSA = playerTeamAssignmentsMatrixTranspose.mult(skillsMatrix).mult(playerTeamAssignmentsMatrix); SimpleMatrix middle = aTa.plus(aTSA); SimpleMatrix middleInverse = middle.invert(); SimpleMatrix end = playerTeamAssignmentsMatrixTranspose.mult(meanVector); SimpleMatrix expPartMatrix = start.mult(middleInverse).mult(end).scale(-0.5); double expPart = expPartMatrix.determinant(); double sqrtPartNumerator = aTa.determinant(); double sqrtPartDenominator = middle.determinant(); double sqrtPart = sqrtPartNumerator / sqrtPartDenominator; return Math.exp(expPart) * Math.sqrt(sqrtPart); }
Example 4
Source File: BigMatrixMultiplicationBenchmarking.java From tutorials with MIT License | 5 votes |
@Benchmark public Object ejmlMatrixMultiplication(BigMatrixProvider matrixProvider) { SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); return firstMatrix.mult(secondMatrix); }
Example 5
Source File: MatrixMultiplicationBenchmarking.java From tutorials with MIT License | 5 votes |
@Benchmark public Object ejmlMatrixMultiplication(MatrixProvider matrixProvider) { SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); return firstMatrix.mult(secondMatrix); }
Example 6
Source File: SimpleMatrixUnitTest.java From tutorials with MIT License | 5 votes |
@Test void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { SimpleMatrix firstMatrix = new SimpleMatrix( new double[][] { new double[] {1d, 5d}, new double[] {2d, 3d}, new double[] {1d ,7d} } ); SimpleMatrix secondMatrix = new SimpleMatrix( new double[][] { new double[] {1d, 2d, 3d, 7d}, new double[] {5d, 2d, 8d, 1d} } ); SimpleMatrix expected = new SimpleMatrix( new double[][] { new double[] {26d, 12d, 43d, 12d}, new double[] {17d, 10d, 30d, 17d}, new double[] {36d, 16d, 59d, 14d} } ); SimpleMatrix actual = firstMatrix.mult(secondMatrix); assertThat(actual).matches(m -> m.isIdentical(expected, 0d)); }
Example 7
Source File: OneComponentDistribution.java From okde-java with MIT License | 5 votes |
/** * Splits a single component distribution into two components as described in the oKDE-paper. * @return a TwoComponentDistribution */ public TwoComponentDistribution split(double parentWeight){ SimpleSVD<?> svd = mGlobalCovariance.svd(true); SimpleMatrix S = svd.getW(); SimpleMatrix V = svd.getV(); SimpleMatrix d = S.extractDiag(); double max = MatrixOps.maxVectorElement(d); int maxIndex = MatrixOps.maxVectorElementIndex(d); int len = mGlobalCovariance.numRows(); SimpleMatrix M = new SimpleMatrix(len,1); M.set(maxIndex, 0, 1.0d); SimpleMatrix dMean = V.mult(M).scale(0.5*Math.sqrt(max)); SimpleMatrix meanSplit1 = mGlobalMean.plus(dMean); SimpleMatrix meanSplit2 = mGlobalMean.minus(dMean); SimpleMatrix dyadMean = mGlobalMean.mult(mGlobalMean.transpose()); SimpleMatrix dyadMeanSplit1 = meanSplit1.mult(meanSplit1.transpose()); SimpleMatrix dyadMeanSplit2 = meanSplit2.mult(meanSplit2.transpose()); SimpleMatrix covSplit = mGlobalCovariance.plus(dyadMean).minus(dyadMeanSplit1.plus(dyadMeanSplit2).scale(0.5)); SimpleMatrix[] means = {meanSplit1, meanSplit2}; SimpleMatrix[] covariances = {covSplit, covSplit}; double[] weights = {0.5, 0.5}; TwoComponentDistribution splitDist = null; try { splitDist = new TwoComponentDistribution(weights, means, covariances, mBandwidthMatrix); splitDist.setGlobalWeight(parentWeight*mGlobalWeight); splitDist.setGlobalCovariance(mGlobalCovariance); splitDist.setGlobalMean(mGlobalMean); } catch (TooManyComponentsException e) { // cant be thrown } return splitDist; }
Example 8
Source File: Coordinates.java From GNSS_Compare with Apache License 2.0 | 4 votes |
public void setSMMultXYZ(SimpleMatrix sm){ this.ecef = sm.mult(this.ecef); }
Example 9
Source File: Coordinates.java From GNSS_Compare with Apache License 2.0 | 3 votes |
/** * @param target * @return Local (ENU) coordinates */ public void computeLocal(Coordinates target) { if(this.geod==null) computeGeodetic(); SimpleMatrix R = rotationMatrix(this); enu = R.mult(target.minusXYZ(this)); }
Example 10
Source File: Coordinates.java From GNSS_Compare with Apache License 2.0 | 3 votes |
public void computeLocalV2(Coordinates target) { if(this.geod==null) computeGeodetic(); SimpleMatrix R = rotationMatrix(this); enu = R.mult(target.minusXYZ(this)); }
Example 11
Source File: LSPI.java From burlap with Apache License 2.0 | 2 votes |
/** * Runs LSTDQ on this object's current {@link SARSData} dataset. * @return the new weight matrix as a {@link SimpleMatrix} object. */ public SimpleMatrix LSTDQ(){ //set our policy Policy p = new GreedyQPolicy(this); //first we want to get all the features for all of our states in our data set; this is important if our feature database generates new features on the fly List<SSFeatures> features = new ArrayList<LSPI.SSFeatures>(this.dataset.size()); int nf = 0; for(SARS sars : this.dataset.dataset){ SSFeatures transitionFeatures = new SSFeatures(this.saFeatures.features(sars.s, sars.a), this.saFeatures.features(sars.sp, p.action(sars.sp))); features.add(transitionFeatures); nf = Math.max(nf, transitionFeatures.sActionFeatures.length); } SimpleMatrix B = SimpleMatrix.identity(nf).scale(this.identityScalar); SimpleMatrix b = new SimpleMatrix(nf, 1); for(int i = 0; i < features.size(); i++){ SimpleMatrix phi = this.phiConstructor(features.get(i).sActionFeatures, nf); SimpleMatrix phiPrime = this.phiConstructor(features.get(i).sPrimeActionFeatures, nf); double r = this.dataset.get(i).r; SimpleMatrix numerator = B.mult(phi).mult(phi.minus(phiPrime.scale(gamma)).transpose()).mult(B); SimpleMatrix denomenatorM = phi.minus(phiPrime.scale(this.gamma)).transpose().mult(B).mult(phi); double denomenator = denomenatorM.get(0) + 1; B = B.minus(numerator.scale(1./denomenator)); b = b.plus(phi.scale(r)); //DPrint.cl(0, "updated matrix for row " + i + "/" + features.size()); } SimpleMatrix w = B.mult(b); this.vfa = this.vfa.copy(); for(int i = 0; i < nf; i++){ this.vfa.setParameter(i, w.get(i, 0)); } return w; }