Java Code Examples for org.apache.commons.math.util.FastMath#log1p()

The following examples show how to use org.apache.commons.math.util.FastMath#log1p() . 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: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example 2
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return 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
 */
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                    LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                    LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example 3
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example 4
Source File: BetaDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example 5
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public RealVector mapLog1pToSelf() {
    for (int i = 0; i < data.length; i++) {
        data[i] = FastMath.log1p(data[i]);
    }
    return this;
}
 
Example 6
Source File: Log1p.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.log1p(x);
}
 
Example 7
Source File: ComposableFunction.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double value(double d){
    return FastMath.log1p(d);
}
 
Example 8
Source File: Log1p.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.log1p(x);
}
 
Example 9
Source File: Log1p.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.log1p(x);
}