Example usage for java.lang Math log1p

List of usage examples for java.lang Math log1p

Introduction

In this page you can find the example usage for java.lang Math log1p.

Prototype

public static double log1p(double x) 

Source Link

Document

Returns the natural logarithm of the sum of the argument and 1.

Usage

From source file:org.renjin.primitives.random.Beta.java

public static double pnbeta2(double x, double o_x, double a, double b, double ncp, boolean lower_tail,
        boolean log_p) {
    double ans = pnbeta_raw(x, o_x, a, b, ncp);
    /* return R_DT_val(ans), but we want to warn about cancellation here */
    if (lower_tail) {
        return log_p ? Math.log(ans) : ans;
    } else {/*from   w  w  w  .  ja va  2 s  .  c o m*/
        if (ans > 1 - 1e-10) {
            return (DoubleVector.NaN);
        }
        ans = Math.min(ans, 1.0); /* Precaution */
        return log_p ? Math.log1p(-ans) : (1 - ans);
    }
}

From source file:org.renjin.primitives.random.ChiSquare.java

public static double pnchisq(double x, double df, double ncp, boolean lower_tail, boolean log_p) {
    double ans;/*from ww w  .  ja v  a  2 s.co m*/

    if (DoubleVector.isNaN(x) || DoubleVector.isNaN(df) || DoubleVector.isNaN(ncp)) {
        return x + df + ncp;
    }

    if (!DoubleVector.isFinite(df) || !DoubleVector.isFinite(ncp)) {
        return DoubleVector.NaN;
    }

    if (df < 0. || ncp < 0.) {
        return DoubleVector.NaN;
    }

    ans = pnchisq_raw(x, df, ncp, 1e-12, 8 * SignRank.DBL_EPSILON, 1000000, lower_tail);
    if (ncp >= 80) {
        if (lower_tail) {
            ans = Math.min(ans, 1.0); /* e.g., pchisq(555, 1.01, ncp = 80) */
        } else { /* !lower_tail */
            /* since we computed the other tail cancellation is likely */
            if (ans < 1e-10) {
                /*
                 * Is there any function for ML_ERROR?????
                 */
                //ML_ERROR(ME_PRECISION, "pnchisq");
            }
            ans = Math.max(ans, 0.0); /* Precaution PR#7099 */
        }
    }
    if (!log_p) {
        return ans;
    }
    /* if ans is near one, we can do better using the other tail */
    if (ncp >= 80 || ans < 1 - 1e-8) {
        return Math.log(ans);
    }
    ans = pnchisq_raw(x, df, ncp, 1e-12, 8 * SignRank.DBL_EPSILON, 1000000, !lower_tail);
    return Math.log1p(-ans);
}

From source file:peasy.PeasyCam.java

private void mouseZoom(final double delta) {
    safeSetDistance(distance + delta * Math.log1p(distance));
}

From source file:r.base.MathExt.java

@Primitive
public static double log1p(@Recycle double x) {
    return Math.log1p(x);
}

From source file:tech.tablesaw.columns.numbers.NumberMapFunctions.java

/**
 * Returns the natural log of the values in this column, after adding 1 to each so that zero
 * values don't return -Infinity/*from w  ww.j  a  v a2 s  .  c  om*/
 */
default DoubleColumn log1p() {
    DoubleColumn newColumn = DoubleColumn.create(name() + "[1og1p]", size());
    for (int i = 0; i < size(); i++) {
        newColumn.set(i, Math.log1p(getDouble(i)));
    }
    return newColumn;
}

From source file:ubic.BAMSandAllen.Util.java

public static DoubleMatrix<String, String> log1pMatrix(DoubleMatrix<String, String> input) {
    DoubleMatrix<String, String> result = input.copy();
    for (int i = 0; i < result.rows(); i++) {
        for (int j = 0; j < result.columns(); j++) {
            double value = result.get(i, j);
            result.set(i, j, Math.log1p(value));
        }/*from w w w  .  j a  v  a  2 s.  c  o m*/
    }
    return result;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.Maths.java

/**
 * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
 * @param a//from w w w  .  j  a v a  2  s.c  o m
 * @return dataset
 */
@SuppressWarnings("cast")
public static AbstractDataset log1p(final AbstractDataset a) {
    final int isize;
    final IndexIterator it = a.getIterator();
    AbstractDataset ds;
    final int dt = a.getDtype();

    switch (dt) {
    case AbstractDataset.INT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final byte[] i8data = ((ByteDataset) a).data;
        final float[] oi8data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final byte ix = i8data[it.index];
            float ox;
            ox = (float) (Math.log1p(ix));
            oi8data[i++] = ox;
        }
        break;
    case AbstractDataset.INT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final short[] i16data = ((ShortDataset) a).data;
        final float[] oi16data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final short ix = i16data[it.index];
            float ox;
            ox = (float) (Math.log1p(ix));
            oi16data[i++] = ox;
        }
        break;
    case AbstractDataset.INT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final int[] i32data = ((IntegerDataset) a).data;
        final double[] oi32data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final int ix = i32data[it.index];
            double ox;
            ox = (double) (Math.log1p(ix));
            oi32data[i++] = ox;
        }
        break;
    case AbstractDataset.INT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final long[] i64data = ((LongDataset) a).data;
        final double[] oi64data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final long ix = i64data[it.index];
            double ox;
            ox = (double) (Math.log1p(ix));
            oi64data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYINT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final byte[] ai8data = ((CompoundByteDataset) a).data;
        final float[] oai8data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final byte ix = ai8data[it.index + j];
                float ox;
                ox = (float) (Math.log1p(ix));
                oai8data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final short[] ai16data = ((CompoundShortDataset) a).data;
        final float[] oai16data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final short ix = ai16data[it.index + j];
                float ox;
                ox = (float) (Math.log1p(ix));
                oai16data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final int[] ai32data = ((CompoundIntegerDataset) a).data;
        final double[] oai32data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final int ix = ai32data[it.index + j];
                double ox;
                ox = (double) (Math.log1p(ix));
                oai32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final long[] ai64data = ((CompoundLongDataset) a).data;
        final double[] oai64data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final long ix = ai64data[it.index + j];
                double ox;
                ox = (double) (Math.log1p(ix));
                oai64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.FLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final float[] f32data = ((FloatDataset) a).data;
        final float[] of32data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = f32data[it.index];
            float ox;
            ox = (float) (Math.log1p(ix));
            of32data[i++] = ox;
        }
        break;
    case AbstractDataset.FLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final double[] f64data = ((DoubleDataset) a).data;
        final double[] of64data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = f64data[it.index];
            double ox;
            ox = (double) (Math.log1p(ix));
            of64data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYFLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final float[] af32data = ((CompoundFloatDataset) a).data;
        final float[] oaf32data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final float ix = af32data[it.index + j];
                float ox;
                ox = (float) (Math.log1p(ix));
                oaf32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYFLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final double[] af64data = ((CompoundDoubleDataset) a).data;
        final double[] oaf64data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final double ix = af64data[it.index + j];
                double ox;
                ox = (double) (Math.log1p(ix));
                oaf64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.COMPLEX64:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64);
        final float[] c64data = ((ComplexFloatDataset) a).data;
        final float[] oc64data = ((ComplexFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = c64data[it.index];
            final float iy = c64data[it.index + 1];
            float ox;
            float oy;
            ox = (float) (0.5 * Math.log1p(ix * ix + 2. * ix + iy * iy));
            oy = (float) (Math.atan2(iy, ix + 1));
            oc64data[i++] = ox;
            oc64data[i++] = oy;
        }
        break;
    case AbstractDataset.COMPLEX128:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128);
        final double[] c128data = ((ComplexDoubleDataset) a).data;
        final double[] oc128data = ((ComplexDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = c128data[it.index];
            final double iy = c128data[it.index + 1];
            double ox;
            double oy;
            ox = (double) (0.5 * Math.log1p(ix * ix + 2. * ix + iy * iy));
            oy = (double) (Math.atan2(iy, ix + 1));
            oc128data[i++] = ox;
            oc128data[i++] = oy;
        }
        break;
    default:
        throw new IllegalArgumentException(
                "log1p supports integer, compound integer, real, compound real, complex datasets only");
    }

    ds.setName(a.getName());
    addFunctionName(ds, "log1p");
    return ds;
}