Search in sources :

Example 1 with MathIllegalArgumentException

use of org.apache.commons.math3.exception.MathIllegalArgumentException in project cloudsim-plus by manoelcampos.

the class ExperimentRunner method computeConfidenceErrorMargin.

/**
 * <p>
 * Computes the confidence interval error margin for a given set of samples
 * in order to enable finding the interval lower and upper bound around a
 * mean value. By this way, the confidence interval can be computed as [mean
 * + errorMargin .. mean - errorMargin].
 * </p>
 *
 * <p>
 * To reduce the confidence interval by half, one have to execute the
 * experiments 4 more times. This is called the "Replication Method" and
 * just works when the samples are i.i.d. (independent and identically
 * distributed). Thus, if you have correlation between samples of each
 * simulation run, a different method such as a bias compensation,
 * {@link #isApplyBatchMeansMethod() batch means} or regenerative method has
 * to be used. </p>
 *
 * <b>NOTE:</b> How to compute the error margin is a little bit confusing.
 * The Harry Perros' book states that if less than 30 samples are collected,
 * the t-Distribution has to be used to that purpose.
 *
 * However, this article
 * <a href="https://en.wikipedia.org/wiki/Confidence_interval#Basic_Steps">Wikipedia
 * article</a>
 * says that if the standard deviation of the real population is known, it
 * has to be used the z-value from the Standard Normal Distribution.
 * Otherwise, it has to be used the t-value from the t-Distribution to
 * calculate the critical value for defining the error margin (also called
 * standard error). The book "Numeric Computation and Statistical Data
 * Analysis on the Java Platform" confirms the last statement and such
 * approach was followed.
 *
 * @param stats the statistic object with the values to compute the error
 * margin of the confidence interval
 * @param confidenceLevel the confidence level, in the interval from ]0 to
 * 1[, such as 0.95 to indicate 95% of confidence.
 * @return the error margin to compute the lower and upper bound of the
 * confidence interval
 *
 * @see
 * <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm">Critical
 * Values of the Student's t Distribution</a>
 * @see
 * <a href="https://en.wikipedia.org/wiki/Student%27s_t-distribution">t-Distribution</a>
 * @see <a href="http://www4.ncsu.edu/~hp/files/simulation.pdf">Harry
 * Perros, "Computer Simulation Techniques: The definitive introduction!,"
 * 2009</a>
 * @see <a href="http://www.springer.com/gp/book/9783319285290">Numeric
 * Computation and Statistical Data Analysis on the Java Platform</a>
 */
protected double computeConfidenceErrorMargin(SummaryStatistics stats, double confidenceLevel) {
    try {
        // Creates a T-Distribution with N-1 degrees of freedom
        final double degreesOfFreedom = stats.getN() - 1;
        /*
		    The t-Distribution is used to determine the probability that
		    the real population mean lies in a given interval.
             */
        final TDistribution tDist = new TDistribution(degreesOfFreedom);
        final double significance = 1.0 - confidenceLevel;
        final double criticalValue = tDist.inverseCumulativeProbability(1.0 - significance / 2.0);
        System.out.printf("\n\tt-Distribution critical value for %d samples: %f\n", stats.getN(), criticalValue);
        // Calculates the confidence interval error margin
        return criticalValue * stats.getStandardDeviation() / Math.sqrt(stats.getN());
    } catch (MathIllegalArgumentException e) {
        return Double.NaN;
    }
}
Also used : MathIllegalArgumentException(org.apache.commons.math3.exception.MathIllegalArgumentException) TDistribution(org.apache.commons.math3.distribution.TDistribution)

Example 2 with MathIllegalArgumentException

use of org.apache.commons.math3.exception.MathIllegalArgumentException in project chordatlas by twak.

the class Concarnie method removeOverlaps.

private void removeOverlaps(List<Problem> current) {
    Closer<Problem> closer = new Closer();
    for (Problem a : current) {
        try {
            Region<Euclidean2D> ar = a.chull.createRegion();
            b: for (Problem b : current) if (a != b)
                for (Vector2D v : b.chull.getVertices()) {
                    Location vInA = ar.checkPoint(v);
                    if (vInA == Location.BOUNDARY || vInA == Location.INSIDE) {
                        closer.add(a, b);
                        continue b;
                    }
                }
        } catch (InsufficientDataException th) {
        } catch (MathIllegalArgumentException th) {
        }
    }
    for (Set<Problem> close : closer.close()) {
        List<Problem> intersecting = new ArrayList<Problem>(close);
        Collections.sort(intersecting, (a, b) -> -Double.compare(a.area(), b.area()));
        for (int i = 1; i < intersecting.size(); i++) {
            Problem togo = intersecting.get(i);
            togo.addPortal();
            current.remove(togo);
        }
    }
}
Also used : InsufficientDataException(org.apache.commons.math3.exception.InsufficientDataException) ArrayList(java.util.ArrayList) Euclidean2D(org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D) Paint(java.awt.Paint) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) MathIllegalArgumentException(org.apache.commons.math3.exception.MathIllegalArgumentException) Location(org.apache.commons.math3.geometry.partitioning.Region.Location)

Aggregations

MathIllegalArgumentException (org.apache.commons.math3.exception.MathIllegalArgumentException)2 Paint (java.awt.Paint)1 ArrayList (java.util.ArrayList)1 TDistribution (org.apache.commons.math3.distribution.TDistribution)1 InsufficientDataException (org.apache.commons.math3.exception.InsufficientDataException)1 Euclidean2D (org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D)1 Vector2D (org.apache.commons.math3.geometry.euclidean.twod.Vector2D)1 Location (org.apache.commons.math3.geometry.partitioning.Region.Location)1