Java Code Examples for org.apache.commons.math3.util.MathArrays#distance1()
The following examples show how to use
org.apache.commons.math3.util.MathArrays#distance1() .
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: SomaticLikelihoodsEngine.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a likelihoods matrix, calculate the parameters of the Dirichlet posterior distribution on their allele * fractions, which define a discrete distribution. * @param log10Likelihoods matrix of alleles x reads * @param priorPseudocounts */ public static double[] alleleFractionsPosterior(final RealMatrix log10Likelihoods, final double[] priorPseudocounts) { final int numberOfAlleles = log10Likelihoods.getRowDimension(); Utils.validateArg(numberOfAlleles == priorPseudocounts.length, "Must have one pseudocount per allele."); double[] dirichletPosterior = new IndexRange(0, numberOfAlleles).mapToDouble(n -> 1.0); // initialize flat posterior boolean converged = false; while(!converged) { // alleleCounts = \sum_r \bar{z}_r, where \bar{z}_r is an a-dimensional vector of the expectation of z_r with respect to q(f) final double[] alleleCounts = getEffectiveCounts(log10Likelihoods, dirichletPosterior); final double[] newDirichletPosterior = MathArrays.ebeAdd(alleleCounts, priorPseudocounts); converged = MathArrays.distance1(dirichletPosterior, newDirichletPosterior) < CONVERGENCE_THRESHOLD; dirichletPosterior = newDirichletPosterior; } return dirichletPosterior; }
Example 2
Source File: SomaticLikelihoodsEngine.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a likelihoods matrix, calculate the parameters of the Dirichlet posterior distribution on their allele * fractions, which define a discrete distribution. * @param logLikelihoods matrix of alleles x reads * @param priorPseudocounts */ public static double[] alleleFractionsPosterior(final RealMatrix logLikelihoods, final double[] priorPseudocounts) { final int numberOfAlleles = logLikelihoods.getRowDimension(); Utils.validateArg(numberOfAlleles == priorPseudocounts.length, "Must have one pseudocount per allele."); double[] dirichletPosterior = new IndexRange(0, numberOfAlleles).mapToDouble(n -> 1.0); // initialize flat posterior boolean converged = false; while(!converged) { // alleleCounts = \sum_r \bar{z}_r, where \bar{z}_r is an a-dimensional vector of the expectation of z_r with respect to q(f) final double[] alleleCounts = getEffectiveCounts(logLikelihoods, dirichletPosterior); final double[] newDirichletPosterior = MathArrays.ebeAdd(alleleCounts, priorPseudocounts); converged = MathArrays.distance1(dirichletPosterior, newDirichletPosterior)/MathUtils.sum(newDirichletPosterior) < CONVERGENCE_THRESHOLD; dirichletPosterior = newDirichletPosterior; } return dirichletPosterior; }
Example 3
Source File: ManhattanDistance.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double compute(double[] a, double[] b) { return MathArrays.distance1(a, b); }
Example 4
Source File: ManhattanDistance.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double compute(double[] a, double[] b) { return MathArrays.distance1(a, b); }
Example 5
Source File: ManhattanDistance.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double compute(double[] a, double[] b) { return MathArrays.distance1(a, b); }
Example 6
Source File: ManhattanDistance.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double compute(double[] a, double[] b) { return MathArrays.distance1(a, b); }