/** {@inheritDoc} */ @Override public double value(double x, double y) { return FastMath.pow(x, y); } };
/** {@inheritDoc} */ @Override public RealVector mapPowToSelf(double d) { for (int i = 0; i < data.length; i++) { data[i] = FastMath.pow(data[i], d); } return this; }
public static double R_pow(double x, double y) { return FastMath.pow(x, y); }
/** * Calculates the Nth generalized harmonic number. See * <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic * Series</a>. * * @param n the term in the series to calculate (must be ≥ 1) * @param m the exponent; special case m == 1.0 is the harmonic series * @return the nth generalized harmonic number */ private double generalizedHarmonic(final int n, final double m) { double value = 0; for (int k = n; k > 0; --k) { value += 1.0 / FastMath.pow(k, m); } return value; }
/** * <p> * Returns a <code>double</code> whose value is * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form. * </p> * * @param exponent * exponent to which this <code>BigFraction</code> is to be raised. * @return <tt>this<sup>exponent</sup></tt>. */ public double pow(final double exponent) { return FastMath.pow(numerator.doubleValue(), exponent) / FastMath.pow(denominator.doubleValue(), exponent); }
/** * For this distribution, X, this method returns P(X = x). * @param x the value at which the PMF is evaluated * @return PMF for this distribution */ public double probability(int x) { double ret; if (x < 0) { ret = 0.0; } else { ret = MathUtils.binomialCoefficientDouble(x + numberOfSuccesses - 1, numberOfSuccesses - 1) * FastMath.pow(probabilityOfSuccess, numberOfSuccesses) * FastMath.pow(1.0 - probabilityOfSuccess, x); } return ret; }
/** * The probability mass function P(X = x) for a Zipf distribution. * * @param x the value at which the probability density function is evaluated. * @return the value of the probability mass function at x */ public double probability(final int x) { if (x <= 0 || x > numberOfElements) { return 0.0; } return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent); }
/** * Access the initial domain value, based on <code>p</code>, used to * bracket a CDF root. This method is used by * {@link #inverseCumulativeProbability(double)} to find critical values. * * @param p the desired probability for the critical value * @return initial domain value */ @Override protected double getInitialDomain(double p) { // use median return FastMath.pow(scale * FastMath.log(2.0), 1.0 / shape); }
/** * For this distribution, X, this method returns P(X < <code>x</code>). * @param x the value at which the CDF is evaluated. * @return CDF evaluated at <code>x</code>. */ public double cumulativeProbability(double x) { double ret; if (x <= 0.0) { ret = 0.0; } else { ret = 1.0 - FastMath.exp(-FastMath.pow(x / scale, shape)); } return ret; }
/** * Returns the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @since 2.1 */ @Override public double density(double x) { if (x < 0) { return 0; } final double xscale = x / scale; final double xscalepow = FastMath.pow(xscale, shape - 1); /* * FastMath.pow(x / scale, shape) = * FastMath.pow(xscale, shape) = * FastMath.pow(xscale, shape - 1) * xscale */ final double xscalepowshape = xscalepow * xscale; return (shape / scale) * xscalepow * FastMath.exp(-xscalepowshape); }
/** {@inheritDoc} */ @Override protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH) { final double x = interpolatedTime - referenceTime; final double normalizedAbscissa = x / scalingH; Arrays.fill(stateVariation, 0.0); Arrays.fill(interpolatedDerivatives, 0.0); // apply Taylor formula from high order to low order, // for the sake of numerical accuracy final double[][] nData = nordsieck.getDataRef(); for (int i = nData.length - 1; i >= 0; --i) { final int order = i + 2; final double[] nDataI = nData[i]; final double power = FastMath.pow(normalizedAbscissa, order); for (int j = 0; j < nDataI.length; ++j) { final double d = nDataI[j] * power; stateVariation[j] += d; interpolatedDerivatives[j] += order * d; } } for (int j = 0; j < currentState.length; ++j) { stateVariation[j] += scaled[j] * normalizedAbscissa; interpolatedState[j] = currentState[j] + stateVariation[j]; interpolatedDerivatives[j] = (interpolatedDerivatives[j] + scaled[j] * normalizedAbscissa) / x; } }
/** Compute step grow/shrink factor according to normalized error. * @param error normalized error of the current step * @return grow/shrink factor for next step */ protected double computeStepGrowShrinkFactor(final double error) { return FastMath.min(maxGrowth, FastMath.max(minReduction, safety * FastMath.pow(error, exp))); }
product = 1.0; for (int i = begin; i < begin + length; i++) { product *= FastMath.pow(values[i], weights[i]);
/** * Round the given value to the specified number of decimal places. The * value is rounded using the given method which is any method defined in * {@link BigDecimal}. * * @param x the value to round. * @param scale the number of digits to the right of the decimal point. * @param roundingMethod the rounding method as defined in * {@link BigDecimal}. * @return the rounded value. * @since 1.1 */ public static float round(float x, int scale, int roundingMethod) { float sign = indicator(x); float factor = (float)FastMath.pow(10.0f, scale) * sign; return (float)roundUnscaled(x * factor, sign, roundingMethod) / factor; }
/** * Returns the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. */ @Override public double density(double x) { if (x < 0) return 0; return FastMath.pow(x / beta, alpha - 1) / beta * FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha)); }
/** * For this distribution, X, this method returns the critical point x, such * that P(X < x) = <code>p</code>. * <p> * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and * <code>Double.POSITIVE_INFINITY</code> for p=1.</p> * * @param p the desired probability * @return x, such that P(X < x) = <code>p</code> * @throws IllegalArgumentException if <code>p</code> is not a valid * probability. */ @Override public double inverseCumulativeProbability(double p) { double ret; if (p < 0.0 || p > 1.0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0); } else if (p == 0) { ret = 0.0; } else if (p == 1) { ret = Double.POSITIVE_INFINITY; } else { ret = scale * FastMath.pow(-FastMath.log(1.0 - p), 1.0 / shape); } return ret; }
setMaxGrowth(FastMath.pow(2.0, -exp));
final double w = FastMath.pow(diffNorm, -brightnessExponent); md.store(cosAngle(diff, md.normal()) * w, sd);
setMaxGrowth(FastMath.pow(2.0, -exp));
/** {@inheritDoc} */ public double integrate(final UnivariateRealFunction f, final double min, final double max) throws ConvergenceException, FunctionEvaluationException, IllegalArgumentException { clearResult(); verifyInterval(min, max); verifyIterationCount(); // compute first estimate with a single step double oldt = stage(f, min, max, 1); int n = 2; for (int i = 0; i < maximalIterationCount; ++i) { // improve integral with a larger number of steps final double t = stage(f, min, max, n); // estimate error final double delta = FastMath.abs(t - oldt); final double limit = FastMath.max(absoluteAccuracy, relativeAccuracy * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5); // check convergence if ((i + 1 >= minimalIterationCount) && (delta <= limit)) { setResult(t, i); return result; } // prepare next iteration double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / abscissas.length)); n = FastMath.max((int) (ratio * n), n + 1); oldt = t; } throw new MaxIterationsExceededException(maximalIterationCount); }