List of usage examples for org.apache.commons.math.distribution NormalDistributionImpl inverseCumulativeProbability
@Override public double inverseCumulativeProbability(final double p) throws MathException
p
. From source file:de.tud.kom.p2psim.impl.util.stat.distributions.NormalDistribution.java
/** * returns a random value normally distributed with mu = _mu and sigma = * _sigma./*from w w w . j a va 2 s.c o m*/ * * @param _mu * @param _sigma * @return as double */ public static double returnValue(double _mu, double _sigma) { try { NormalDistributionImpl d = new NormalDistributionImpl(_mu, _sigma); return d.inverseCumulativeProbability(Simulator.getRandom().nextDouble()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
From source file:geogebra.common.kernel.statistics.AlgoZProportionEstimate.java
@Override public final void compute() { double n1 = n.getDouble(); double phat = proportion.getDouble(); double cLevel = level.getDouble(); NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1); double critZ = 0; try {//w w w. j av a 2 s .c om critZ = normalDist.inverseCumulativeProbability((1 - cLevel) / 2); } catch (Exception e) { result.setUndefined(); return; } se = Math.sqrt(phat * (1 - phat) / n1); double z = Math.abs(critZ); me = z * se; // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, phat - me)); result.add(new GeoNumeric(cons, phat + me)); }
From source file:geogebra.common.kernel.statistics.AlgoZProportion2Estimate.java
@Override public final void compute() { double n1 = n.getDouble(); double phat1 = proportion.getDouble(); double n2 = n_2.getDouble(); double phat2 = proportion2.getDouble(); double cLevel = level.getDouble(); NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1); double critZ = 0; try {// w ww .ja v a 2 s . com critZ = normalDist.inverseCumulativeProbability((1 - cLevel) / 2); } catch (Exception e) { result.setUndefined(); return; } double stat = phat1 - phat2; se = Math.sqrt(phat1 * (1 - phat1) / n1 + phat2 * (1 - phat2) / n2); double z = Math.abs(critZ); me = z * se; // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, stat - me)); result.add(new GeoNumeric(cons, stat + me)); }
From source file:geogebra.common.kernel.statistics.AlgoZMeanEstimate.java
@Override public final void compute() { if (!sd.isDefined() || !level.isDefined()) { result.setUndefined();/* ww w . ja v a 2s .c o m*/ return; } double n1, mean1; double sd1 = sd.getDouble(); double cLevel = level.getDouble(); if (list == null) { if (!n.isDefined() || !mean.isDefined()) { result.setUndefined(); return; } n1 = n.getDouble(); mean1 = mean.getDouble(); } else { if (!list.isDefined()) { result.setUndefined(); return; } n1 = list.size(); mean1 = list.mean(); } NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1); double critZ = 0; try { critZ = normalDist.inverseCumulativeProbability((1 - cLevel) / 2); } catch (Exception e) { result.setUndefined(); return; } double se = sd1 / Math.sqrt(n1); double z = Math.abs(critZ); me = z * se; // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, mean1 - me)); result.add(new GeoNumeric(cons, mean1 + me)); }
From source file:geogebra.common.kernel.statistics.AlgoNormalQuantilePlot.java
private void calculateZValues(int n) { zValues = new double[n]; NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1); double x;// w ww . ja v a 2s. com try { x = 1 - Math.pow(0.5, 1.0 / n); zValues[0] = normalDist.inverseCumulativeProbability(x); for (int i = 2; i < n; i++) { x = (i - 0.3175) / (n + 0.365); zValues[i - 1] = normalDist.inverseCumulativeProbability(x); } x = Math.pow(0.5, 1.0 / n); zValues[n - 1] = normalDist.inverseCumulativeProbability(x); } catch (MathException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:geogebra.common.kernel.statistics.AlgoZMean2Estimate.java
@Override public final void compute() { if (!sd.isDefined() || !sd_2.isDefined() || !level.isDefined()) { result.setUndefined();/* w ww .ja v a 2 s .com*/ return; } double n1, n2, mean1, mean2; double sd1 = sd.getDouble(); double sd2 = sd_2.getDouble(); double cLevel = level.getDouble(); if (list == null) { if (!n.isDefined() || !n_2.isDefined() || !mean.isDefined() || !mean_2.isDefined()) { result.setUndefined(); return; } n1 = n.getDouble(); n2 = n_2.getDouble(); mean1 = mean.getDouble(); mean2 = mean_2.getDouble(); } else { if (!list.isDefined() || !list2.isDefined()) { result.setUndefined(); return; } n1 = list.size(); n2 = list2.size(); mean1 = list.mean(); mean2 = list2.mean(); } NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1); double critZ = 0; try { critZ = normalDist.inverseCumulativeProbability((1 - cLevel) / 2); } catch (Exception e) { result.setUndefined(); return; } double stat = mean1 - mean2; se = Math.sqrt(sd1 * sd1 / n1 + sd2 * sd2 / n2); double z = Math.abs(critZ); me = z * se; // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, stat - me)); result.add(new GeoNumeric(cons, stat + me)); }
From source file:es.udc.gii.common.eaf.plugin.parameter.jade.JADECRAdaptiveParameter.java
@Override public double get(EvolutionaryAlgorithm algorithm) { double meana_cr; double cr_i;//from www . j a v a2s . c o m List<Individual> individuals; int cr_individuals; double cr_ind; //Hay que "chequear" que los individuos sean del tipo JADE: if (algorithm.getGenerations() > this.alg_generation) { //Calculamos mu; individuals = algorithm.getPopulation().getIndividuals(); meana_cr = 0.0; cr_individuals = 0; for (Individual i : individuals) { if (i instanceof JADEIndividual) { cr_ind = ((JADEIndividual) i).getCR(); if (cr_ind != -Double.MAX_VALUE) { meana_cr += cr_ind; cr_individuals++; } } else { throw new ConfigurationException( "JADECRAdaptiveParameter requires individuals of type JADEIndividual"); } } meana_cr /= cr_individuals; if (!Double.isNaN(meana_cr) && !Double.isInfinite(meana_cr)) { this.mu_cr = (1.0 - this.c) * this.mu_cr + this.c * meana_cr; this.mu_cr = (this.mu_cr > 1.0 ? 1.0 : (this.mu_cr < 0.0 ? 0.0 : this.mu_cr)); } this.alg_generation++; //System.out.println(this.mu_cr); } cr_i = 0.0; NormalDistributionImpl n = new NormalDistributionImpl(this.mu_cr, this.std_cr); try { double r = EAFRandom.nextDouble(); cr_i = n.inverseCumulativeProbability(r); cr_i = (cr_i > 1.0 ? 1.0 : (cr_i < 0.0 ? 0.0 : cr_i)); } catch (MathException ex) { Logger.getLogger(JADECRAdaptiveParameter.class.getName()).log(Level.SEVERE, null, ex); } return cr_i; }
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./*from ww w. j ava 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:org.peerfact.impl.util.stats.distributions.LimitedNormalDistribution.java
/** * Returns a random value that is distributed as a Normal Distribution with * an upper and lower limit.//from w ww . jav a2 s .c o m * * @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) { double lmax; double lmin; double lpmax = 1; double lpmin = 0; double lpfactor; NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu, _sigma); if (_min == null) { if (_max != null) { // only max is limted lmax = _max.doubleValue(); try { lpmax = llimitedNormal.cumulativeProbability(lmax); } catch (MathException e) { e.printStackTrace(); } } } else { if (_max == null) { // only min is limited. lmin = _min.doubleValue(); try { lpmin = llimitedNormal.cumulativeProbability(lmin); } catch (MathException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // both sides limited. // 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; }