Example usage for org.apache.commons.math3.distribution NormalDistribution NormalDistribution

List of usage examples for org.apache.commons.math3.distribution NormalDistribution NormalDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution NormalDistribution NormalDistribution.

Prototype

public NormalDistribution(double mean, double sd) throws NotStrictlyPositiveException 

Source Link

Document

Create a normal distribution using the given mean and standard deviation.

Usage

From source file:gedi.util.math.stat.kernel.GaussianKernel.java

public GaussianKernel(double sd, double maxMassOutside) {
    super(new NormalDistribution(0, sd), maxMassOutside);
}

From source file:kr.ac.kaist.se.simulator.NormalDistributor.java

public NormalDistributor() {
    this.distGenerator = new NormalDistribution(0, 1);
    this.mean = 0;
    this.stDev = 1;
}

From source file:gedi.util.math.stat.kernel.GaussianKernel.java

public void setSd(double sd) {
    dist = new NormalDistribution(0, sd);
    updateDistribution();
}

From source file:iac_soap.statsq.NormVerdService.java

@Override
public NormVerdResponse calculateNormVerd(List<Double> data) throws MyFault {

    //Service Requirements 
    if (data.isEmpty()) {
        throw new MyFault("No data is provided");
    } else if (data.size() < 2) {
        throw new MyFault("A minimum of two data elements is required.");
    }//from w  w w  . j  a v a  2 s  .  c  o  m

    //Declaring Apache Commons DescriptiveStatistics
    DescriptiveStatistics stats = new DescriptiveStatistics();

    //Filling DescriptiveStatistics class with the provided dataset
    for (int i = 0; i < data.size(); i++) {
        stats.addValue(data.get(i));
    }

    //Let the DescriptiveStatistics class calculate the mean and standard deviation
    double mean = stats.getMean();
    double std = stats.getStandardDeviation();

    //Implementing the KolmogorovSmirnov test & calculating the kurtosis and skewness
    NormalDistribution x = new NormalDistribution(mean, std);
    double p_value = TestUtils.kolmogorovSmirnovTest(x, stats.getValues(), false);
    double kurtosis = stats.getKurtosis();
    double skewness = stats.getSkewness();
    boolean result = false;

    //Check if the dataset is a normal distribution:
    //KolmogorovSmirnov p_value should be >= 0.05
    //Both kurtosis and skewness should be between -2.0 and 2.0
    if (kurtosis < 2.0 && kurtosis > -2.0 && skewness < 2.0 && skewness > -2.0 && p_value >= 0.05) {
        result = true;
    }

    //Response message:
    NormVerdResponse nvr = new NormVerdResponse(result, p_value, kurtosis, skewness);

    return nvr;
}

From source file:cz.cuni.mff.d3s.spl.interpretation.MannWhitneyInterpretation.java

/** {@inheritDoc} */
@Override//  w  w w  .  j  av  a 2 s  .  c  o  m
public ComparisonResult compare(DataSnapshot left, DataSnapshot right) {
    double[] leftSamples = mergeSamples(left);
    double[] rightSamples = mergeSamples(right);

    double uStatMax = utest.mannWhitneyU(leftSamples, rightSamples);

    long lengthsMultiplied = (long) leftSamples.length * rightSamples.length;

    double uStatMin = lengthsMultiplied - uStatMax;

    /* https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test#Normal_approximation */
    double meanU = lengthsMultiplied / 2.0;
    double varU = lengthsMultiplied * (leftSamples.length + rightSamples.length + 1) / 12.0;

    double z = (uStatMin - meanU) / Math.sqrt(varU);

    NormalDistribution distribution = new NormalDistribution(0.0, 1.0);

    return new DistributionBasedComparisonResult(z, distribution);
}

From source file:com.ibm.og.util.Distributions.java

/**
 * Creates a normal distribution with a rangge of [average - 3*spread, average + 3*spread].
 * /*  ww  w .  jav a  2s. c  om*/
 * @param average the center of this distribution
 * @param spread distance of one standard deviation
 * @return a normal distribution instance
 * @throws IllegalArgumentException if average or spread are negative, or if average - 3*spread is
 *         negative
 */
public static Distribution normal(final double average, final double spread) {
    checkArgument(average >= 0.0, "average must be >= 0.0 [%s]", average);
    checkArgument(spread >= 0.0, "spread must be >= 0.0 [%s]", spread);

    if (DoubleMath.fuzzyEquals(spread, 0.0, Distributions.ERR)) {
        return constant(average);
    }

    final double min = average - (3 * spread);
    checkArgument(min >= 0.0, "three standard deviations must be >= 0.0 [%s]", min);
    final String s = String.format("NormalDistribution [average=%s, spread=%s]", average, spread);
    return new RealDistributionAdapter(new NormalDistribution(average, spread), s);
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.trafficgen.IATGen.java

/**
 * Constructor//ww w  . ja v a  2 s .c om
 *
 * @param distribution Distribution as String
 * @param para1 Parameter 1
 * @param para2 Parameter 2 (only needed when applicable)
 */
public IATGen(String distribution, double para1, double para2) {

    logger.trace("Distribution selected: {} with Parameters {} & {}", distribution, para1, para2);

    switch (distribution) {
    case "ChiSquared":
        this.distri = new ChiSquaredDistribution(para1);
        break;
    case "Exponential":
        this.distri = new ExponentialDistribution(para1);
        break;
    case "Gamma":
        this.distri = new GammaDistribution(para1, para2);
        break;
    case "Poisson":
        this.intDistri = new PoissonDistribution(para1, para2);
        break;
    default:
        this.distri = new NormalDistribution(para1, para2);
        break;
    }
}

From source file:it.cnr.isti.smartfed.test.DatacenterFacilities.java

public static List<FederationDatacenter> getNormalDistribution(int numOfDatacenters, int numHost) {
    Random r = new Random(13213);

    int core_variance = maxNumOfCores - minNumOfCores;
    int delta_cores = core_variance > 0 ? r.nextInt(core_variance) : 0;

    List<FederationDatacenter> list = new ArrayList<FederationDatacenter>();
    NormalDistribution nd = new NormalDistribution(numOfDatacenters / 2d, numOfDatacenters / 4d);

    // System.out.println("Aa"+numHost);

    for (int i = 0; i < numOfDatacenters; i++) {
        // create the virtual processor (PE)
        List<Pe> peList = new ArrayList<Pe>();
        int mips = 25000;
        for (int j = 0; j < minNumOfCores + delta_cores; j++) {
            peList.add(new Pe(j, new PeProvisionerSimple(mips)));
        }/*from w  w  w . j  av  a  2 s.  c  o  m*/

        // create the hosts
        List<Host> hostList = new ArrayList<Host>();
        HostProfile prof = HostProfile.getDefault();
        prof.set(HostParams.RAM_AMOUNT_MB, 16 * 1024 + "");

        int num;
        if (numOfDatacenters == 1) {
            num = numHost;
        } else {
            Double value = new Double(nd.density(i)) * numHost;
            num = value.intValue();
        }

        if (num < 1)
            num = 1;

        for (int k = 0; k < num; k++) {
            hostList.add(HostFactory.get(prof, peList));
        }

        // create the storage
        List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached

        // create the datacenters
        list.add(FederationDatacenterFactory.getDefault(hostList, storageList));
    }

    return list;
}

From source file:akori.Impact.java

static public void normalMatrix(double[][] matrix, int x, int y, int std) {
    double max = 0;
    NormalDistribution n = new NormalDistribution(0, 0.4);
    for (int i = x - std; i < x + std && matrix.length > i && i >= 0; ++i) {
        for (int j = y - std; j < y + std && matrix[0].length > j && j >= 0; ++j) {
            double r = Math.sqrt((i - x) * (i - x) + (j - y) * (j - y));
            if (r > 0 && r <= std) {
                matrix[i][j] = matrix[i][j] + n.density(r / std);
            }// w w w . j av  a2 s.c o m
        }
    }
}

From source file:ffx.algorithms.mc.CoordShakeMove.java

public CoordShakeMove(Atom[] atoms) {
    int nAtoms = atoms.length;
    this.atoms = new Atom[nAtoms];
    System.arraycopy(atoms, 0, this.atoms, 0, nAtoms);
    originalCoords = ResidueState.storeAtomicCoordinates(this.atoms);
    dist = new NormalDistribution(0, sigma);
}