Example usage for java.lang Math E

List of usage examples for java.lang Math E

Introduction

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

Prototype

double E

To view the source code for java.lang Math E.

Click Source Link

Document

The double value that is closer than any other to e, the base of the natural logarithms.

Usage

From source file:FILA.Produtor.java

private double Poisson(double y, int x) {
    return Math.pow(Math.E, -y) * Math.pow(y, x) / Fatorial(x);
}

From source file:org.apache.flink.api.java.sampling.PoissonSampler.java

/**
 * Sample the input elements, for each input element, generate its count following a poisson
 * distribution./*from  w  w  w  .j av a2 s. c  o m*/
 *
 * @param input Elements to be sampled.
 * @return The sampled result which is lazy computed upon input elements.
 */
@Override
public Iterator<T> sample(final Iterator<T> input) {
    if (fraction == 0) {
        return EMPTY_ITERABLE;
    }

    return new SampledIterator<T>() {
        T currentElement;
        int currentCount = 0;

        @Override
        public boolean hasNext() {
            if (currentCount > 0) {
                return true;
            } else {
                samplingProcess();
                if (currentCount > 0) {
                    return true;
                } else {
                    return false;
                }
            }
        }

        @Override
        public T next() {
            if (currentCount <= 0) {
                samplingProcess();
            }
            currentCount--;
            return currentElement;
        }

        public int poisson_ge1(double p) {
            // sample 'k' from Poisson(p), conditioned to k >= 1.
            double q = Math.pow(Math.E, -p);
            // simulate a poisson trial such that k >= 1.
            double t = q + (1 - q) * random.nextDouble();
            int k = 1;
            // continue standard poisson generation trials.
            t = t * random.nextDouble();
            while (t > q) {
                k++;
                t = t * random.nextDouble();
            }
            return k;
        }

        private void skipGapElements(int num) {
            // skip the elements that occurrence number is zero.
            int elementCount = 0;
            while (input.hasNext() && elementCount < num) {
                currentElement = input.next();
                elementCount++;
            }
        }

        private void samplingProcess() {
            if (fraction <= THRESHOLD) {
                double u = Math.max(random.nextDouble(), EPSILON);
                int gap = (int) (Math.log(u) / -fraction);
                skipGapElements(gap);
                if (input.hasNext()) {
                    currentElement = input.next();
                    currentCount = poisson_ge1(fraction);
                }
            } else {
                while (input.hasNext()) {
                    currentElement = input.next();
                    currentCount = poissonDistribution.sample();
                    if (currentCount > 0) {
                        break;
                    }
                }
            }
        }
    };
}

From source file:org.canova.api.util.MathUtils.java

/**
 * 1 / 1 + exp(-x)/*  ww w.  jav  a  2  s  .  co  m*/
 *
 * @param x
 * @return
 */
public static double sigmoid(double x) {
    return 1.0 / (1.0 + Math.pow(Math.E, -x));
}

From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java

/**
  * LWR prediction/*from   www  .  j a  v a  2 s .  c  om*/
  * 
  * @param X
  * @param Y
  * @param x0
  * @param tau
  * @return
  */
public Double LWRPredict(ArrayRealVector X, ArrayRealVector Y, double x0, final double tau) {
    ArrayRealVector X0 = new ArrayRealVector(X.getDimension(), x0);
    ArrayRealVector delta = X.subtract(X0);
    ArrayRealVector sqDists = delta.ebeMultiply(delta);
    UnivariateFunction expTau = new UnivariateFunction() {
        @Override
        public double value(double arg0) {
            //log.info(" cp univariate tau " + tau);
            return Math.pow(Math.E, -arg0 / (2 * tau));
        }
    };
    ArrayRealVector W = sqDists.map(expTau);
    double Xt_W_X = X.dotProduct(W.ebeMultiply(X));
    if (Xt_W_X == 0.0) {
        log.error(" cp LWR cannot predict - 0 denominator returning NULL");
        log.error("Xcv is " + X.toString());
        log.error("Ycv is " + Y.toString());
        log.error("x0 is " + x0);
        return null; // <==== NOTE: a caller must be prepared for it
    }
    double theta = (1.0 / Xt_W_X) * X.ebeMultiply(W).dotProduct(Y);

    return theta * x0;
}

From source file:edu.cuny.qc.speech.AuToBI.core.Aggregation.java

/**
 * Treating this aggregation as a Gaussian probability distribution function, evaluates the probability that a value
 * generated was generated by this aggregation.
 *
 * @param value the value to evaluate/*from   w  ww  . jav a 2  s  .  c  om*/
 * @return the gaussian PDF evaluated at value
 */
public double evaluateGaussianPDF(double value) {
    double mean = getMean();
    double stdev = getStdev();

    double pdf = 1 / (stdev * Math.sqrt(2 * Math.PI));
    pdf *= Math.pow(Math.E, (-(value - mean) * (value - mean)) / (2 * stdev * stdev));
    return pdf;
}

From source file:org.rm3l.ddwrt.tiles.status.bandwidth.BandwidthMonitoringTile.java

public void fillIfaceDataPoint(@NotNull final String iface) {

    if (DDWRTCompanionConstants.TEST_MODE || BW_MONIT_TEST) {
        //FIXME TEST MODE
        final double random = new Random().nextDouble() * 1024;

        bandwidthMonitoringIfaceData.addData(iface,
                new DataPoint(System.currentTimeMillis(), random * Math.sqrt(random * Math.E)));
    }/*  w w w  . j a v a2  s  .c o m*/

    //FIXME Add real data down this line
}

From source file:org.apache.cassandra.gms.FailureDetector.java

double p(double t) {
    double mean = mean();
    double exponent = (-1) * (t) / mean;
    return Math.pow(Math.E, exponent);
}

From source file:it.unimi.dsi.sux4j.mph.PaCoTrieDistributorMonotoneMinimalPerfectHashFunction.java

/** Creates a new PaCo-trie-based monotone minimal perfect hash function using the given
 * elements and transformation strategy. 
 * /* w  ww. j  ava2s.co  m*/
 * @param elements the elements among which the trie must be able to rank.
 * @param transform a transformation strategy that must turn the elements in <code>elements</code> into a list of
 * distinct, prefix-free, lexicographically increasing (in iteration order) bit vectors.
 */
public PaCoTrieDistributorMonotoneMinimalPerfectHashFunction(final Iterable<? extends T> elements,
        final TransformationStrategy<? super T> transform) throws IOException {

    this.transform = transform;
    defRetValue = -1; // For the very few cases in which we can decide

    long maxLength = 0;
    long totalLength = 0;
    BitVector bv;
    final RandomGenerator random = new XorShift1024StarRandomGenerator();

    ProgressLogger pl = new ProgressLogger(LOGGER);
    pl.displayLocalSpeed = true;
    pl.displayFreeMemory = true;
    pl.itemsName = "keys";

    pl.start("Creating chunked hash store...");
    final ChunkedHashStore<BitVector> chunkedHashStore = new ChunkedHashStore<BitVector>(
            TransformationStrategies.identity());
    chunkedHashStore.reset(random.nextLong());
    for (T s : elements) {
        bv = transform.toBitVector(s);
        chunkedHashStore.add(bv);
        maxLength = Math.max(maxLength, bv.length());
        totalLength += bv.length();
        pl.lightUpdate();
    }

    pl.done();

    LOGGER.debug("Maximum length: " + maxLength);
    LOGGER.debug("Average length: " + totalLength / (double) chunkedHashStore.size());

    size = chunkedHashStore.size();

    if (size == 0) {
        bucketSize = log2BucketSize = 0;
        distributor = null;
        offset = null;
        chunkedHashStore.close();
        return;
    }

    final long averageLength = (totalLength + size - 1) / size;

    int t = Fast.mostSignificantBit(
            (int) Math.floor(averageLength - Math.log(size) - Math.log(averageLength - Math.log(size)) - 1));
    final int firstbucketSize = 1 << t;
    LOGGER.debug("First bucket size estimate: " + firstbucketSize);

    final Iterable<BitVector> bitVectors = TransformationStrategies.wrap(elements, transform);

    LOGGER.info("Creating distributor...");

    PaCoTrieDistributor<BitVector> firstDistributor = new PaCoTrieDistributor<BitVector>(bitVectors, t,
            TransformationStrategies.identity());

    if (firstDistributor.numBits() == 0 || firstbucketSize >= size)
        log2BucketSize = t;
    else {
        // Reassign bucket size based on empirical estimation
        log2BucketSize = t
                - Fast.mostSignificantBit((int) Math.ceil(size / (firstDistributor.numBits() * Math.log(2))));
    }

    bucketSize = 1 << log2BucketSize;
    LOGGER.debug("Second bucket size estimate: " + bucketSize);

    if (firstbucketSize == bucketSize)
        distributor = firstDistributor;
    else {
        firstDistributor = null;
        distributor = new PaCoTrieDistributor<BitVector>(bitVectors, log2BucketSize,
                TransformationStrategies.identity());
    }

    LOGGER.debug("Bucket size: " + bucketSize);
    final int bucketSizeMask = bucketSize - 1;

    LOGGER.info("Generating offset function...");

    offset = new GOV3Function.Builder<BitVector>().keys(bitVectors)
            .transform(TransformationStrategies.identity()).store(chunkedHashStore)
            .values(new AbstractLongBigList() {
                public long getLong(long index) {
                    return index & bucketSizeMask;
                }

                public long size64() {
                    return size;
                }
            }, log2BucketSize).indirect().build();

    chunkedHashStore.close();

    LOGGER.debug("Forecast distributor bit cost: "
            + (size / bucketSize) * (maxLength + log2BucketSize - Math.log(size)));
    LOGGER.debug("Actual distributor bit cost: " + distributor.numBits());
    LOGGER.debug("Forecast bit cost per element: " + (GOV3Function.C + Fast.log2(Math.E)
            - Fast.log2(Fast.log2(Math.E)) + Fast.log2(maxLength - Fast.log2(size))));
    LOGGER.info("Actual bit cost per element: " + (double) numBits() / size);
}

From source file:com.bigdata.dastor.gms.FailureDetector.java

double p(double t) {
    double mean = mean();
    double exponent = (-1) * (t) / mean;
    return 1 - (1 - Math.pow(Math.E, exponent));
}

From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java

public double ackley(double[] x) {

    double s1 = 0.0d;
    double s2 = 0.0d;

    for (int i = 0; i < x.length; i++) {
        s1 += x[i] * x[i];/*  w w  w  .j  ava2s .  c  o m*/
        s2 += Math.cos(2 * Math.PI * x[i]);
    }

    return -20 * Math.exp(-0.2 * Math.sqrt(1.0 / x.length * s1)) - Math.exp(1.0 / x.length * s2) + 20 + Math.E;
}