List of usage examples for org.apache.commons.math MathException MathException
public MathException(Throwable rootCause)
MathException with specified nested Throwable root cause. From source file:edu.umbc.cs.maple.utils.PairedTTester.java
/** Returns the significance level of a paired t-test of the two samples * @return the significance level of the paired t-test of the two samples * @throws MathException/*from ww w . j a v a2s. co m*/ */ public double pairedTTest() throws MathException { double[] samples1 = JavaUtils.collectionToPrimitiveArray(m_samples1); double[] samples2 = JavaUtils.collectionToPrimitiveArray(m_samples2); if (samples1.length != samples2.length) throw new MathException("The samples are different lengths."); return pairedTTest(samples1, samples2); }
From source file:beast.evolution.operators.GMRFMultilocusSkyrideBlockUpdateOperator.java
public static DenseVector newNewtonRaphson(double[] data1, double[] data2, DenseVector currentGamma, SymmTridiagMatrix proposedQ, int maxIterations, double stopValue) throws MathException { DenseVector iterateGamma = currentGamma.copy(); DenseVector tempValue = currentGamma.copy(); int numberIterations = 0; while (gradient(data1, data2, iterateGamma, proposedQ).norm(Vector.Norm.Two) > stopValue) { try {/*from w ww . j a va 2 s. com*/ jacobian(data2, iterateGamma, proposedQ).solve(gradient(data1, data2, iterateGamma, proposedQ), tempValue); } catch (no.uib.cipr.matrix.MatrixNotSPDException e) { Logger.getLogger("dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator") .fine("Newton-Raphson F"); throw new MathException(""); } catch (no.uib.cipr.matrix.MatrixSingularException e) { Logger.getLogger("dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator") .fine("Newton-Raphson F"); throw new MathException(""); } iterateGamma.add(tempValue); numberIterations++; if (numberIterations > maxIterations) { Logger.getLogger("dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator") .fine("Newton-Raphson F"); throw new MathException("Newton Raphson algorithm did not converge within " + maxIterations + " step to a norm less than " + stopValue + "\n" + "Try starting BEAST with a more accurate initial tree."); } } Logger.getLogger("dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator") .fine("Newton-Raphson S"); return iterateGamma; }
From source file:cz.paulrz.montecarlo.random.ParallelPercentile.java
/** * Returns an estimate of the <code>p</code>th percentile of the values * in the <code>values</code> array, starting with the element in (0-based) * position <code>begin</code> in the array and including <code>length</code> * values./*from w w w .j a v a 2s .c o m*/ * <p> * Calls to this method do not modify the internal <code>quantile</code> * state of this statistic.</p> * <p> * <ul> * <li>Returns <code>Double.NaN</code> if <code>length = 0</code></li> * <li>Returns (for any value of <code>p</code>) <code>values[begin]</code> * if <code>length = 1 </code></li> * <li>Throws <code>IllegalArgumentException</code> if <code>values</code> * is null , <code>begin</code> or <code>length</code> is invalid, or * <code>p</code> is not a valid quantile value (p must be greater than 0 * and less than or equal to 100)</li> * </ul></p> * <p> * See {@link ParallelPercentile} for a description of the percentile estimation * algorithm used.</p> * * @param values array of input values * @param p the percentile to compute * @param begin the first (0-based) element to include in the computation * @param length the number of array elements to include * @return the percentile value * @throws IllegalArgumentException if the parameters are not valid or the * input array is null */ public double evaluate(final double[] values, final int begin, final int length, final double p) throws MathException { test(values, begin, length); if ((p > 100) || (p <= 0)) { throw new OutOfRangeException(p, 0, 100); } if (length == 0) { return Double.NaN; } if (length == 1) { return values[begin]; // always return single value for n = 1 } double n = length; double pos = p * (n + 1) / 100; double fpos = FastMath.floor(pos); int intPos = (int) fpos; double dif = pos - fpos; double[] work; int[] pivotsHeap; if (values == getDataRef()) { work = getDataRef(); pivotsHeap = cachedPivots; } else { work = new double[length]; System.arraycopy(values, begin, work, 0, length); pivotsHeap = new int[(0x1 << MAX_CACHED_LEVELS) - 1]; Arrays.fill(pivotsHeap, -1); } if (pos < 1) { return select(work, pivotsHeap, 0); } if (pos >= n) { return select(work, pivotsHeap, length - 1); } Future<Double> lowerFuture = CpuPool.executorService.submit(new SelectWorker(work, pivotsHeap, intPos - 1)); Future<Double> upperFuture = CpuPool.executorService.submit(new SelectWorker(work, pivotsHeap, intPos)); try { double lower = lowerFuture.get(); double upper = upperFuture.get(); return lower + dif * (upper - lower); } catch (InterruptedException e) { throw new MathException(e); } catch (ExecutionException e) { throw new MathException(e); } }