Example usage for org.apache.commons.math MathException printStackTrace

List of usage examples for org.apache.commons.math MathException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.math MathException printStackTrace.

Prototype

@Override
public void printStackTrace() 

Source Link

Document

Prints the stack trace of this exception to the standard error stream.

Usage

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.PoissonDistribution.java

/**
 * returns a random value Poisson distributed with lamda = _lamda.
 * @param _lamda//from   ww w  .j  a  va  2 s .  c  o  m
 * @return  as double
 */
public static double returnValue(double _lamda) {
    try {
        PoissonDistributionImpl d = new PoissonDistributionImpl(_lamda);
        return d.inverseCumulativeProbability(Simulator.getRandom().nextDouble());
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return 0;
    }
}

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.ExponentialDistribution.java

/**
 * returns a random value exponentially distributed with mu = _mu.
 * //from   w  w  w .j  a va 2s.  c om
 * @param _mu
 * @return as double
 */
public static double returnValue(double _mu) {
    try {
        ExponentialDistributionImpl d = new ExponentialDistributionImpl(_mu);
        return d.inverseCumulativeProbability(Simulator.getRandom().nextDouble());
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return 0;
    }
}

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.LimitedNormalDistribution.java

/**
 * Returns a random value that is distributed as a Normal Distribution with
 * an upper and lower limit.// ww  w  . j a va  2 s. c  om
 * 
 * @param _mu
 *            average
 * @param _sigma
 *            standard deviation
 * @param _min
 *            lower limit, set to "null", if no limit
 * @param _max
 *            upper limit, set to "null", if no limit
 * @return as double
 */
public static double returnValue(double _mu, double _sigma, Double _min, Double _max) {
    int llimitType;
    double lmax;
    double lmin;
    double lpmax = 1;
    double lpmin = 0;
    double lpfactor;

    NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu, _sigma);
    if (_min == null) {
        if (_max == null) {
            llimitType = LIMIT_NORMAL_DIST_NONE;
        } else {
            // only max is limted
            llimitType = LIMIT_NORMAL_DIST_MAX;
            lmax = _max.doubleValue();
            try {
                lpmax = llimitedNormal.cumulativeProbability(lmax);
            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (_max == null) {
            // only min is limited.
            llimitType = LIMIT_NORMAL_DIST_MIN;
            lmin = _min.doubleValue();
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
            } catch (MathException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            // both sides limited.
            llimitType = LIMIT_NORMAL_DIST_BOTH;

            // make sure min is really smaller than max.
            if (_max.doubleValue() > _min.doubleValue()) {
                lmin = _min.doubleValue();
                lmax = _max.doubleValue();
            } else {
                lmax = _min.doubleValue();
                lmin = _max.doubleValue();
            }

            // get min and max probabilites that are possible
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
                lpmax = llimitedNormal.cumulativeProbability(lmax);

                lpfactor = lpmax - lpmin;

            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    }
    lpfactor = lpmax - lpmin;

    double lrandom = lpmin + Simulator.getRandom().nextDouble() * lpfactor;
    double lresult;

    try {
        lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        lresult = 0;
    }

    return lresult;

}

From source file:dr.math.distributions.GammaDistribution.java

private static void testQuantileCM(double y, double shape, double scale) {

    long time = System.currentTimeMillis();

    double value = 0;
    try {/*from  w  ww .  j  av  a  2  s.  c  om*/
        for (int i = 0; i < 1000; i++) {
            value = (new org.apache.commons.math.distribution.GammaDistributionImpl(shape, scale))
                    .inverseCumulativeProbability(y);
        }
        value = (new org.apache.commons.math.distribution.GammaDistributionImpl(shape, scale))
                .inverseCumulativeProbability(y);
    } catch (MathException e) {
        e.printStackTrace();
    }
    long elapsed = System.currentTimeMillis() - time;

    System.out.println("commons.maths inverseCDF, " + y + ", for shape=" + shape + ", scale=" + scale + " : "
            + value + ", time=" + elapsed + "ms");

}

From source file:evaluation.loadGenerator.randomVariable.Binomial.java

@Override
public int drawIntSample() {
    try {/*from w  w w  .  j ava 2 s.co  m*/
        return randomDataImpl.nextBinomial(numberOfTrials, probabilityOfSuccess);
    } catch (MathException e) {
        e.printStackTrace();
        throw new RuntimeException(errorMessage);
    }
}

From source file:evaluation.loadGenerator.randomVariable.Weibull.java

@Override
public double drawDoubleSample() {
    try {//ww  w  . jav  a2  s . c o  m
        return randomDataImpl.nextWeibull(shape, scale);
    } catch (MathException e) {
        e.printStackTrace();
        throw new RuntimeException(errorMessage);
    }
}

From source file:evaluation.loadGenerator.randomVariable.Zipf.java

@Override
public int drawIntSample() {
    try {/*ww  w.  j  a v  a 2s  . c  om*/
        return randomDataImpl.nextZipf(numberOfElements, exponent);
    } catch (MathException e) {
        e.printStackTrace();
        throw new RuntimeException(errorMessage);
    }
}

From source file:evaluation.loadGenerator.randomVariable.Hypergeometric.java

@Override
public int drawIntSample() {
    try {/*from   ww  w  . j  a  v  a 2  s.co  m*/
        return randomDataImpl.nextHypergeometric(populationSize, numberOfSuccesses, sampleSize);
    } catch (MathException e) {
        e.printStackTrace();
        throw new RuntimeException(errorMessage);
    }
}

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.PoissonDistribution.java

public double returnValue() {
    double random = Simulator.getRandom().nextDouble();
    int result;//from   w  w  w .  j av  a  2 s .c o m

    try {
        result = poisson.inverseCumulativeProbability(random);
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        result = 0;
    }

    return result;
}

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.NormalDistribution.java

@Override
public double returnValue() {
    double random = Simulator.getRandom().nextDouble();
    double result;

    try {//from   w  ww.ja  v  a 2 s .  c  o  m
        result = normal.inverseCumulativeProbability(random);
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        result = 0;
    }

    return result;
}