org.apache.commons.math.special.Beta Java Examples

The following examples show how to use org.apache.commons.math.special.Beta. 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: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #2
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #3
Source File: BetaDistribution.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
public double cdf(double x)  {
        if (x <= 0) {
            return 0;
        } else if (x >= 1) {
            return 1;
        } else {
            try {
                return Beta.regularizedBeta(x, alpha, beta);
            } catch (MathException e) {
                // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime
                // exceptions is bad. Better to return NaN and let the calling code deal with it.
                return Double.NaN;
//                throw MathRuntimeException.createIllegalArgumentException(
//                "Couldn't calculate beta cdf for alpha = " + alpha + ", beta = " + beta + ": " +e.getMessage());
            }
        }

    }
 
Example #4
Source File: BinomialDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated.
 * @return PDF for this distribution. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= getNumberOfTrials()) {
        ret = 1.0;
    } else {
        ret =
            1.0 - Beta.regularizedBeta(
                    getProbabilityOfSuccess(),
                    x + 1.0,
                    getNumberOfTrials() - x);
    }
    return ret;
}
 
Example #5
Source File: BinomialDistributionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated.
 * @return PDF for this distribution. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= getNumberOfTrials()) {
        ret = 1.0;
    } else {
        ret =
            1.0 - Beta.regularizedBeta(
                    getProbabilityOfSuccess(),
                    x + 1.0,
                    getNumberOfTrials() - x);
    }
    return ret;
}
 
Example #6
Source File: TDistributionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * For this disbution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #7
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #8
Source File: Cardumen_00121_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluated at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (((degreesOfFreedom) > 100) || ((degreesOfFreedom) <= 0)) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #9
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #10
Source File: Cardumen_0054_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluated at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #11
Source File: Cardumen_0054_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluated at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if ((degreesOfFreedom) > 100) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #12
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this disbution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #13
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #14
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #15
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns {@code P(X < x}).
 *
 * @param x Value at which the CDF is evaluated.
 * @return CDF evaluated at {@code x}.
 * @throws MathException if the cumulative probability can not be
 * computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                degreesOfFreedom / (degreesOfFreedom + (x * x)),
                0.5 * degreesOfFreedom,
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #16
Source File: BinomialDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated.
 * @return PDF for this distribution. 
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= getNumberOfTrials()) {
        ret = 1.0;
    } else {
        ret =
            1.0 - Beta.regularizedBeta(
                    getProbabilityOfSuccess(),
                    x + 1.0,
                    getNumberOfTrials() - x);
    }
    return ret;
}
 
Example #17
Source File: TDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &lt; <code>x</code>).
 * @param x the value at which the CDF is evaluated.
 * @return CDF evaluted at <code>x</code>.
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors.
 */
public double cumulativeProbability(double x) throws MathException{
    double ret;
    if (x == 0.0) {
        ret = 0.5;
    } else {
        double t =
            Beta.regularizedBeta(
                getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
                0.5 * getDegreesOfFreedom(),
                0.5);
        if (x < 0.0) {
            ret = 0.5 * t;
        } else {
            ret = 1.0 - 0.5 * t;
        }
    }

    return ret;
}
 
Example #18
Source File: PascalDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * 
 * @param x the value at which the PDF is evaluated
 * @return PDF for this distribution
 * @throws MathException if the cumulative probability can not be
 *            computed due to convergence or other numerical errors
 */
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = Beta.regularizedBeta(
                    getProbabilityOfSuccess(),
                    getNumberOfSuccesses(),
                    x + 1);
    }
    return ret;
}
 
Example #19
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) throws MathException {
    if (x <= 0) {
        return 0;
    } else if (x >= 1) {
        return 1;
    } else {
        return Beta.regularizedBeta(x, alpha, beta);
    }
}
 
Example #20
Source File: FDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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) {
    final double nhalf = numeratorDegreesOfFreedom / 2;
    final double mhalf = denominatorDegreesOfFreedom / 2;
    final double logx = Math.log(x);
    final double logn = Math.log(numeratorDegreesOfFreedom);
    final double logm = Math.log(denominatorDegreesOfFreedom);
    final double lognxm = Math.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom);
    return Math.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm -
           mhalf*lognxm - Beta.logBeta(nhalf, mhalf));
}
 
Example #21
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) throws MathException {
    if (x <= 0) {
        return 0;
    } else if (x >= 1) {
        return 1;
    } else {
        return Beta.regularizedBeta(x, alpha, beta);
    }
}
 
Example #22
Source File: FDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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) {
    final double nhalf = numeratorDegreesOfFreedom / 2;
    final double mhalf = denominatorDegreesOfFreedom / 2;
    final double logx = FastMath.log(x);
    final double logn = FastMath.log(numeratorDegreesOfFreedom);
    final double logm = FastMath.log(denominatorDegreesOfFreedom);
    final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom);
    return FastMath.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm -
           mhalf*lognxm - Beta.logBeta(nhalf, mhalf));
}
 
Example #23
Source File: BinomialDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 *
 * @param x the value at which the PDF is evaluated.
 * @return PDF for this distribution.
 * @throws MathException if the cumulative probability can not be computed
 *             due to convergence or other numerical errors.
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= numberOfTrials) {
        ret = 1.0;
    } else {
        ret = 1.0 - Beta.regularizedBeta(getProbabilityOfSuccess(),
                x + 1.0, numberOfTrials - x);
    }
    return ret;
}
 
Example #24
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) throws MathException {
    if (x <= 0) {
        return 0;
    } else if (x >= 1) {
        return 1;
    } else {
        return Beta.regularizedBeta(x, alpha, beta);
    }
}
 
Example #25
Source File: PascalDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated
 * @return PDF for this distribution
 * @throws MathException if the cumulative probability can not be computed
 *         due to convergence or other numerical errors
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = Beta.regularizedBeta(getProbabilityOfSuccess(),
            getNumberOfSuccesses(), x + 1);
    }
    return ret;
}
 
Example #26
Source File: BinomialDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, {@code X}, this method returns {@code P(X < x)}.
 *
 * @param x Value at which the PDF is evaluated.
 * @return PDF for this distribution.
 * @throws MathException if the cumulative probability can not be computed
 * due to convergence or other numerical errors.
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= numberOfTrials) {
        ret = 1.0;
    } else {
        ret = 1.0 - Beta.regularizedBeta(getProbabilityOfSuccess(),
                x + 1.0, numberOfTrials - x);
    }
    return ret;
}
 
Example #27
Source File: PascalDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, {@code X}, this method returns {@code P(X < x)}.
 *
 * @param x Value at which the PDF is evaluated.
 * @return PDF for this distribution.
 * @throws MathException if the cumulative probability can not be computed
 * due to convergence or other numerical errors.
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = Beta.regularizedBeta(probabilityOfSuccess,
            numberOfSuccesses, x + 1);
    }
    return ret;
}
 
Example #28
Source File: BinomialDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 *
 * @param x the value at which the PDF is evaluated.
 * @return PDF for this distribution.
 * @throws MathException if the cumulative probability can not be computed
 *             due to convergence or other numerical errors.
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else if (x >= getNumberOfTrials()) {
        ret = 1.0;
    } else {
        ret = 1.0 - Beta.regularizedBeta(getProbabilityOfSuccess(),
                x + 1.0, getNumberOfTrials() - x);
    }
    return ret;
}
 
Example #29
Source File: PascalDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated
 * @return PDF for this distribution
 * @throws MathException if the cumulative probability can not be computed
 *         due to convergence or other numerical errors
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = Beta.regularizedBeta(getProbabilityOfSuccess(),
            getNumberOfSuccesses(), x + 1);
    }
    return ret;
}
 
Example #30
Source File: PascalDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For this distribution, X, this method returns P(X &le; x).
 * @param x the value at which the PDF is evaluated
 * @return PDF for this distribution
 * @throws MathException if the cumulative probability can not be computed
 *         due to convergence or other numerical errors
 */
@Override
public double cumulativeProbability(int x) throws MathException {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = Beta.regularizedBeta(getProbabilityOfSuccess(),
            getNumberOfSuccesses(), x + 1);
    }
    return ret;
}