Example usage for org.apache.commons.math3.distribution AbstractRealDistribution sample

List of usage examples for org.apache.commons.math3.distribution AbstractRealDistribution sample

Introduction

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

Prototype

public double sample() 

Source Link

Document

The default implementation uses the <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> inversion method.

Usage

From source file:eu.crisis_economics.abm.firm.plugins.RandomVariableLabourWageAlgorithm.java

static private double initGuard(AbstractRealDistribution labourWageDistribution) {
    if (labourWageDistribution == null)
        throw new NullArgumentException();
    return labourWageDistribution.sample();
}

From source file:it.cnr.isti.smartfed.federation.generation.DatacenterGenerator.java

/**
 * Generates the list of datacenters, and assigns the host to datacenters according
 * the given distribution. /*from ww w.ja  v  a 2  s.  c  o m*/
 * 
 * Note that a distribution can very well assign zero hosts to a datacenter.
 * However, since cloudsim does not support zero-host datacenter, we do not create 
 * the empty datacenters.
 * 
 * @param approxNumberDatacenters - the approximate total number of datacenters that will be created
 * @param numberTotalHost - the total number of host in all datacenters
 * @param distribution
 * @return
 */
public List<FederationDatacenter> getDatacenters(int approxNumberDatacenters, int numberTotalHost,
        AbstractRealDistribution distribution) {

    // create the list
    List<FederationDatacenter> list = new ArrayList<FederationDatacenter>(approxNumberDatacenters);

    // Here get the assignment vector
    int[] assign = DistributionAssignment.getAssignmentArray(approxNumberDatacenters, numberTotalHost,
            distribution);

    for (int i = 0; i < approxNumberDatacenters; i++) {
        if (assign[i] <= 0)
            continue;

        int numCore, mips, ram, bw, sto;
        double costBw, costSto, costMem;
        if (type == GenerationType.UNIFORM) {
            double value = distribution.sample();
            numCore = (int) coreAmount.denormalize(value);
            mips = (int) mipsAmount.denormalize(value);
            ram = (int) ramAmount.denormalize(value);
            bw = (int) bwAmount.denormalize(value);
            sto = (int) stoAmount.denormalize(value);

            costBw = costPerBw.denormalize(value);
            costSto = costPerSto.denormalize(value);
            costMem = costPerMem.denormalize(value);
        } else {
            numCore = (int) coreAmount.denormalize(distribution.sample());
            mips = (int) mipsAmount.denormalize(distribution.sample());
            ram = (int) ramAmount.denormalize(distribution.sample());
            bw = (int) bwAmount.denormalize(distribution.sample());
            sto = (int) stoAmount.denormalize(distribution.sample());

            costBw = costPerBw.denormalize(distribution.sample());
            costSto = costPerSto.denormalize(distribution.sample());
            costMem = costPerMem.denormalize(distribution.sample());
        }

        // create the datacenters
        FederationDatacenterProfile profile = FederationDatacenterProfile.getDefault();
        profile.set(DatacenterParams.COST_PER_BW, costBw + "");
        profile.set(DatacenterParams.COST_PER_STORAGE, costSto + "");
        // profile.set(DatacenterParams.COST_PER_SEC, costPerSec.sample()+"");
        profile.set(DatacenterParams.COST_PER_SEC, "0");
        profile.set(DatacenterParams.COST_PER_MEM, costMem + "");
        profile.set(DatacenterParams.MAX_BW_FOR_VM, bw + "");

        // choose a random country
        Range rangecountry = new Range(0, countries.length);
        int index = (int) Math.floor(rangecountry.denormalize(distribution.sample()));
        Country place = countries[index];
        profile.set(DatacenterParams.COUNTRY, place.toString());

        List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached
        List<Host> hostList = new ArrayList<Host>();
        List<Pe> peList = new ArrayList<Pe>();// create the virtual processor (PE)

        for (int j = 0; j < numCore; j++) {
            peList.add(new Pe(j, new PeProvisionerSimple(mips)));
        }

        // create the hosts
        HostProfile prof = HostProfile.getDefault();

        prof.set(HostParams.RAM_AMOUNT_MB, ram + "");
        prof.set(HostParams.BW_AMOUNT, bw + "");
        prof.set(HostParams.STORAGE_MB, sto + "");

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

        // populate the list
        list.add(FederationDatacenterFactory.get(profile, hostList, storageList));
    }

    return list;
}

From source file:org.lightjason.agentspeak.action.buildin.math.statistic.CRandomSample.java

/**
 * creates the sample structure/* www . j  a v a 2s  .co m*/
 *
 * @param p_distribution distribution object
 * @param p_size size of the returned values
 * @param p_parallel parallel flag
 * @return term with data
 */
private static ITerm samples(final AbstractRealDistribution p_distribution, final int p_size,
        final boolean p_parallel) {
    if (p_size < 2)
        return CRawTerm.from(p_distribution.sample());

    final List<Double> l_list = Arrays.stream(p_distribution.sample(p_size)).boxed()
            .collect(Collectors.toList());
    return CRawTerm.from(p_parallel ? Collections.synchronizedList(l_list) : l_list);

}

From source file:org.lightjason.agentspeak.action.builtin.math.statistic.CRandomSample.java

/**
 * creates the sample structure/* w  ww  .  jav a  2  s.  c  o m*/
 *
 * @param p_distribution distribution object
 * @param p_size size of the returned values
 * @param p_parallel parallel flag
 * @return term with data
 */
@Nonnull
private static ITerm samples(@Nonnull final AbstractRealDistribution p_distribution, final int p_size,
        final boolean p_parallel) {
    if (p_size < 2)
        return CRawTerm.from(p_distribution.sample());

    final List<Double> l_list = Arrays.stream(p_distribution.sample(p_size)).boxed()
            .collect(Collectors.toList());
    return CRawTerm.from(p_parallel ? Collections.synchronizedList(l_list) : l_list);

}