Java Code Examples for org.ejml.data.DenseMatrix64F#wrap()
The following examples show how to use
org.ejml.data.DenseMatrix64F#wrap() .
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: MultivariateNormalDistribution.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public static double[] nextMultivariateNormalViaBackSolvePrecision(double[] mean, double[] precision) { final int dim = mean.length; DenseMatrix64F p = DenseMatrix64F.wrap(dim,dim, precision); CholeskyDecompositionInner_D64 dd = new CholeskyDecompositionInner_D64(); dd.decompose(p); // Now holds Cholesky decomposition (destructive) double[] epsilon = new double[dim]; for (int i = 0; i < dim; ++i) { epsilon[i] = MathUtils.nextGaussian(); } // Back-solve TriangularSolver.solveTranL(p.getData(), epsilon, dim); for (int i = 0; i < dim; ++i) { epsilon[i] += mean[i]; } return epsilon; }
Example 2
Source File: IntegratedFactorAnalysisLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
@Override public double[] transformTreeTraits(double[] treeTraits) { //TODO: check that this does what it's supposed to. DenseMatrix64F treeTraitMatrix = DenseMatrix64F.wrap(numTaxa, numFactors, treeTraits); DenseMatrix64F loadingsMatrix = DenseMatrix64F.wrap(numFactors, dimTrait, loadingsTransposed.getParameterValues()); DenseMatrix64F traitMatrix = new DenseMatrix64F(numTaxa, dimTrait); org.ejml.ops.CommonOps.mult(treeTraitMatrix, loadingsMatrix, traitMatrix); if (DEBUG) { treeTraitMatrix.print(); loadingsMatrix.print(); traitMatrix.print(); } return traitMatrix.data; }
Example 3
Source File: MissingOps.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public static DenseMatrix64F wrapSpherical(final double[] source, final int offset, final int dim, final double[] buffer) { fillSpherical(source, offset, dim, buffer); DenseMatrix64F res = DenseMatrix64F.wrap(dim, dim, buffer); CommonOps.transpose(res); // Column major. return res; }
Example 4
Source File: MissingOps.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public static DenseMatrix64F wrapDiagonal(final double[] source, final int offset, final int dim, final double[] buffer) { for (int i = 0; i < dim; ++i) { buffer[i * dim + i] = source[i]; } return DenseMatrix64F.wrap(dim, dim, buffer); }
Example 5
Source File: MissingOps.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public static DenseMatrix64F wrapDiagonalInverse(final double[] source, final int offset, final int dim, final double[] buffer) { for (int i = 0; i < dim; ++i) { buffer[i * dim + i] = 1 / source[i]; } return DenseMatrix64F.wrap(dim, dim, buffer); }
Example 6
Source File: MissingOps.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public static DenseMatrix64F copy(ReadableMatrix source) { final int len = source.getDim(); double[] buffer = new double[len]; for (int i = 0; i < len; ++i) { buffer[i] = source.get(i); } return DenseMatrix64F.wrap(source.getMinorDim(), source.getMajorDim(), buffer); }
Example 7
Source File: MultivariateConditionalOnTipsRealizedDelegate.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
DenseMatrix64F getPrecisionBranch(double branchPrecision){ if (!hasDrift) { DenseMatrix64F P1 = new DenseMatrix64F(dimTrait, dimTrait); CommonOps.scale(branchPrecision, Pd, P1); return P1; } else { return DenseMatrix64F.wrap(dimTrait, dimTrait, precisionBuffer); } }
Example 8
Source File: NormalSufficientStatistics.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
NormalSufficientStatistics(double[] buffer, int index, int dim, DenseMatrix64F Pd, PrecisionType precisionType) { int partialOffset = (dim + precisionType.getMatrixLength(dim)) * index; this.mean = MissingOps.wrap(buffer, partialOffset, dim, 1); this.precision = DenseMatrix64F.wrap(dim, dim, precisionType.getScaledPrecision(buffer, partialOffset, Pd.data, dim)); }
Example 9
Source File: IntegratedFactorAnalysisLikelihood.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
private void fillInMeanForTaxon(final WrappedVector output, final DenseMatrix64F precision, final int taxon) { final double[] observed = observedIndicators[taxon]; // final Parameter Y = traitParameter.getParameter(taxon); // Solve for a value \mu_i s.t. P_i \mu_i = (L D_i Y_i) final double[] tmp = new double[numFactors]; final double[] tmp2 = new double[numFactors]; for (int factor = 0; factor < numFactors; ++factor) { double sum = 0; for (int k = 0; k < dimTrait; ++k) { sum += loadings[factor * dimTrait + k] * //loadingsTransposed.getParameterValue(k, factor) * // TODO Maybe a memory access issue here? observed[k] * gamma[k] * // traitPrecision.getParameterValue(k) * data[taxon * dimTrait + k]; // Y.getParameterValue(k); } tmp[factor] = sum; } DenseMatrix64F B = DenseMatrix64F.wrap(numFactors, 1, tmp); DenseMatrix64F X = DenseMatrix64F.wrap(numFactors, 1, tmp2); safeSolve(precision, B, X, false); for (int row = 0; row < numFactors; ++row) { output.set(row, X.unsafe_get(row, 0)); } // return ci; }
Example 10
Source File: MissingOps.java From beast-mcmc with GNU Lesser General Public License v2.1 | 4 votes |
public static DenseMatrix64F wrap(final double[] source, final int offset, final int numRows, final int numCols, final double[] buffer) { System.arraycopy(source, offset, buffer, 0, numRows * numCols); return DenseMatrix64F.wrap(numRows, numCols, buffer); }
Example 11
Source File: RepeatedMeasuresWishartStatistics.java From beast-mcmc with GNU Lesser General Public License v2.1 | 4 votes |
@Override public WishartSufficientStatistics getWishartStatistics() { if (forceResample) { likelihoodDelegate.fireModelChanged(); } double[] treeValues = (double[]) tipTrait.getTrait(tree, null); double[] dataValues = extensionDelegate.getExtendedValues(treeValues); DenseMatrix64F XminusY = DenseMatrix64F.wrap(nTaxa, dimTrait, buffer); DenseMatrix64F X = DenseMatrix64F.wrap(nTaxa, dimTrait, treeValues); DenseMatrix64F Y = DenseMatrix64F.wrap(nTaxa, dimTrait, dataValues); CommonOps.subtract(X, Y, XminusY); DenseMatrix64F outerProductMat = DenseMatrix64F.wrap(dimTrait, dimTrait, outerProduct); CommonOps.multTransA(XminusY, XminusY, outerProductMat); return new WishartSufficientStatistics(nTaxa, outerProduct); }
Example 12
Source File: RepeatedMeasuresTraitDataModel.java From beast-mcmc with GNU Lesser General Public License v2.1 | 4 votes |
@Override public DenseMatrix64F getExtensionVariance() { recomputeVariance(); double[] buffer = samplingVariance.toArrayComponents(); return DenseMatrix64F.wrap(dimTrait, dimTrait, buffer); }
Example 13
Source File: ContinuousDiffusionIntegrator.java From beast-mcmc with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void getBranchVariance(int bufferIndex, int precisionIndex, double[] variance) { getBranchPrecision(bufferIndex, precisionIndex, variance); DenseMatrix64F Var = DenseMatrix64F.wrap(dimTrait, dimTrait, variance); CommonOps.invert(Var); }
Example 14
Source File: MultivariateChainRule.java From beast-mcmc with GNU Lesser General Public License v2.1 | 4 votes |
public InverseGeneral(double[] vecMat) { this.dim = (int) Math.sqrt(vecMat.length); this.Mat = DenseMatrix64F.wrap(dim, dim, vecMat); this.temp = new DenseMatrix64F(dim, dim); }
Example 15
Source File: RandomRotation.java From multimedia-indexing with Apache License 2.0 | 3 votes |
/** * Randomly rotates a vector using the random rotation matrix that was created in the constructor. * * @param vector * The initial vector * @return The randomly rotated vector */ public double[] rotate(double[] vector) { DenseMatrix64F transformed = new DenseMatrix64F(1, vector.length); DenseMatrix64F original = DenseMatrix64F.wrap(1, vector.length, vector); CommonOps.mult(original, randomMatrix, transformed); return transformed.getData(); }