Example usage for org.apache.commons.math.distribution NormalDistributionImpl NormalDistributionImpl

List of usage examples for org.apache.commons.math.distribution NormalDistributionImpl NormalDistributionImpl

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution NormalDistributionImpl NormalDistributionImpl.

Prototype

public NormalDistributionImpl(double mean, double sd) 

Source Link

Document

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

Usage

From source file:org.renjin.primitives.random.Distributions.java

public static double qlnorm(@Recycle double p, @Recycle double meanlog, @Recycle double sdlog,
        boolean lowerTail, boolean logP) {
    return Math.exp(q(new NormalDistributionImpl(meanlog, sdlog), p, lowerTail, logP));
}

From source file:org.renjin.stats.internals.Distributions.java

@Internal
@DataParallel//from ww w  . ja va2  s.  co m
public static double dnorm(@Recycle double x, @Recycle double mean, @Recycle double sd, boolean log) {
    return d(new NormalDistributionImpl(mean, sd), x, log);
}

From source file:org.renjin.stats.internals.Distributions.java

@DataParallel
@Internal//from w ww .ja  v a2s .  co  m
public static double pnorm(@Recycle double q, @Recycle double mean, @Recycle double sd, boolean lowerTail,
        boolean logP) {
    return p(new NormalDistributionImpl(mean, sd), q, lowerTail, logP);
}

From source file:org.renjin.stats.internals.Distributions.java

@DataParallel
@Internal//w  ww.  ja va  2  s . c  o m
public static double plnorm(@Recycle double q, @Recycle double logmean, @Recycle double logsd,
        boolean lowerTail, boolean logP) {
    return p(new NormalDistributionImpl(logmean, logsd), Math.log(q), lowerTail, logP);
}

From source file:org.renjin.stats.internals.Distributions.java

@DataParallel
@Internal/*from ww w  .j  a v  a 2 s . co  m*/
public static double qnorm(@Recycle double p, @Recycle double mean, @Recycle double sd, boolean lowerTail,
        boolean logP) {
    return q(new NormalDistributionImpl(mean, sd), p, lowerTail, logP);
}

From source file:org.renjin.stats.internals.Distributions.java

@DataParallel
@Internal//  ww  w . jav  a 2 s  .  c  o  m
public static double qlnorm(@Recycle double p, @Recycle double meanlog, @Recycle double sdlog,
        boolean lowerTail, boolean logP) {
    return Math.exp(q(new NormalDistributionImpl(meanlog, sdlog), p, lowerTail, logP));
}

From source file:org.xenmaster.monitoring.data.Record.java

protected final void applyStatistics(Collection<Double> values) {
    // Let's get statistical
    DescriptiveStatistics ds = new DescriptiveStatistics();

    for (double util : values) {
        ds.addValue(util);/*from   w  w  w.jav  a 2  s  . com*/
    }

    double a = ds.getMean();
    double stdDev = ds.getStandardDeviation();

    // TODO: actually test this and generate warning
    // Check if all vCPUs have a fair load, e.g. [45, 60, 50] would be fair, [90, 4, 2] indicates you should learn threading
    if (stdDev > 0.8) {
        Logger.getLogger(getClass())
                .info((vm ? "VM" : "Host") + " " + reference + " has an unfair load distribution");
    }

    if (stdDev > 0) {
        try {
            NormalDistributionImpl ndi = new NormalDistributionImpl(ds.getMean(), stdDev);
            double cp = ndi.cumulativeProbability(90);
            if (cp > 0.8) {
                // 80% of the CPUs have a >90% load
                // TODO warning
                Logger.getLogger(getClass()).info((vm ? "VM" : "Host") + " " + reference
                        + " has a load >=90% on 80% of the available CPUs");
            }
        } catch (MathException ex) {
            Logger.getLogger(getClass()).error("Flawed maths", ex);
        }
    }
}

From source file:playground.sergioo.ptsim2013.qnetsimengine.PTQLink.java

final void addFromUpstream(final QVehicle veh) {
    double now = network.simEngine.getMobsim().getSimTimer().getTimeOfDay();
    activateLink();/*from   w  w  w  . j  a va2  s  .  c om*/
    this.linkEnterTimeMap.put(veh, now);
    this.usedStorageCapacity += veh.getSizeInEquivalents();
    String[] parts = link.getId().toString().split(TransitSheduleToNetwork.SEPARATOR);
    double earliestExitTime = now;
    if (stopStopTime != null) {
        if (parts.length == 2) {
            double variance = stopStopTime.getStopStopTimeVariance(
                    Id.create(parts[0], TransitStopFacility.class),
                    Id.create(parts[1], TransitStopFacility.class), now);
            if (variance != 0) {
                try {
                    double r = MatsimRandom.getRandom().nextDouble();
                    earliestExitTime += new NormalDistributionImpl(
                            stopStopTime.getStopStopTime(Id.create(parts[0], TransitStopFacility.class),
                                    Id.create(parts[1], TransitStopFacility.class), now),
                            Math.sqrt(variance)).inverseCumulativeProbability(r);
                } catch (MathException e) {
                    e.printStackTrace();
                }
            } else
                earliestExitTime += stopStopTime.getStopStopTime(Id.create(parts[0], TransitStopFacility.class),
                        Id.create(parts[1], TransitStopFacility.class), now);
        } else
            earliestExitTime += link.getLength() / 3.0;
    } else {
        double speed = veh.getMaximumVelocity();
        if (speed == 7.22) {
            if (link.getNumberOfLanes() > 8)
                speed = 50 / 3.6;
            else if (link.getNumberOfLanes() > 6)
                speed = 40 / 3.6;
            else
                TIMES: for (int i = 0; i < TIMES.length; i++)
                    if (TIMES[i] == (int) (now / 3600) % 24)
                        try {
                            double r = MatsimRandom.getRandom().nextDouble();
                            speed = new NormalDistributionImpl(
                                    veh.getMaximumVelocity() - 0.5556
                                            - (MEANS_S[i] > MEANS_R[i] ? (MEANS_S[i] - MEANS_R[i]) / 3.6 : 0),
                                    STDS_R[i] * 1.1 / 3.6).inverseCumulativeProbability(r);
                            break TIMES;
                        } catch (MathException e) {
                            e.printStackTrace();
                        }
            speed = Math.max(MIN_SPEED_BUS, speed);
        }
        double vehicleTravelTime = this.length / speed;
        earliestExitTime += Math.max(this.freespeedTravelTime, vehicleTravelTime);
    }
    earliestExitTime = Math.floor(earliestExitTime);
    veh.setEarliestLinkExitTime(earliestExitTime);
    veh.setCurrentLink(this.getLink());
    this.vehQueue.add(veh);
    this.network.simEngine.getMobsim().getEventsManager().processEvent(
            new LinkEnterEvent(now, veh.getDriver().getId(), this.getLink().getId(), veh.getId()));
    if (HOLES) {
        holes.poll();
    }
}

From source file:playground.sergioo.ptsim2013.qnetsimengine.PTQLink2.java

final void addFromUpstream(final QVehicle veh) {
    double now = network.simEngine.getMobsim().getSimTimer().getTimeOfDay();
    activateLink();/*from w  w w  . ja v a  2  s.c  o  m*/
    this.linkEnterTimeMap.put(veh, now);
    this.usedStorageCapacity += veh.getSizeInEquivalents();
    double speed = veh.getMaximumVelocity();
    if (speed == 7.22) {
        if (link.getNumberOfLanes() > 5)
            speed = 50 / 3.6;
        else if (link.getFreespeed() > 4)
            speed = 40 / 3.6;
        else
            TIMES: for (int i = 0; i < TIMES.length; i++)
                if (TIMES[i] == (int) (now / 3600) % 24)
                    try {
                        double r = MatsimRandom.getRandom().nextDouble();
                        speed = new NormalDistributionImpl(
                                veh.getMaximumVelocity() - 0.5556
                                        - (MEANS_S[i] > MEANS_R[i] ? (MEANS_S[i] - MEANS_R[i]) / 3.6 : 0),
                                STDS_R[i] * 1.1 / 3.6).inverseCumulativeProbability(r);
                        break TIMES;
                    } catch (MathException e) {
                        e.printStackTrace();
                    }
        speed = Math.max(MIN_SPEED_BUS, speed);
    }
    double vehicleTravelTime = this.length / speed;
    double earliestExitTime = now + Math.max(this.freespeedTravelTime, vehicleTravelTime);
    earliestExitTime = Math.floor(earliestExitTime);
    veh.setEarliestLinkExitTime(earliestExitTime);
    veh.setCurrentLink(this.getLink());
    this.vehQueue.add(veh);
    this.network.simEngine.getMobsim().getEventsManager().processEvent(
            new LinkEnterEvent(now, veh.getDriver().getId(), this.getLink().getId(), veh.getId()));
    if (HOLES) {
        holes.poll();
    }
}

From source file:playground.sergioo.weeklySimulation.preprocess.WeeklyPlans.java

private static void addSecondaryActivitiesDay(Plan plan, int dayPos, Config config) {
    Id<ActivityFacility> homeFacilityId = null;
    Coord homeCoord = null;//  w  w  w . j a v a  2  s.  com
    for (PlanElement planElement : plan.getPlanElements())
        if (planElement instanceof Activity && ((Activity) planElement).getType().equals("home")) {
            homeFacilityId = ((Activity) planElement).getFacilityId();
            homeCoord = ((Activity) planElement).getCoord();
        }
    boolean carAvailable = !((PersonImpl) plan.getPerson()).getCarAvail().equals("never")
            && ((PersonImpl) plan.getPerson()).hasLicense();
    double totalDurations = 9 * 3600;
    try {
        totalDurations = new NormalDistributionImpl(9 * 3600, 2 * 3600)
                .inverseCumulativeProbability(Math.random());
    } catch (MathException e) {
        e.printStackTrace();
    }
    ((ActivityImpl) plan.getPlanElements().get(plan.getPlanElements().size() - 1))
            .setEndTime(dayPos * Time.MIDNIGHT + totalDurations);
    String typeLast = ((ActivityImpl) plan.getPlanElements().get(0)).getType();
    Coord lastCoord = ((ActivityImpl) plan.getPlanElements().get(0)).getCoord();
    Id<ActivityFacility> lastFacilityId = ((ActivityImpl) plan.getPlanElements().get(0)).getFacilityId();
    Activity activity = null;
    while (totalDurations < Time.MIDNIGHT - 2 * 3600) {
        String prevActivityType = ((ActivityImpl) plan.getPlanElements().get(plan.getPlanElements().size() - 1))
                .getType();
        Coord prevActivityCoord = ((ActivityImpl) plan.getPlanElements().get(plan.getPlanElements().size() - 1))
                .getCoord();
        plan.addLeg(new LegImpl(carAvailable ? TransportMode.car : TransportMode.pt));
        String type = !prevActivityType.equals("home") && Math.random() < PROB_HOME ? "home"
                : getRandomActivityType(config.findParam("locationchoice", "flexible_types").split(","));
        double duration;
        try {
            duration = new NormalDistributionImpl(
                    config.planCalcScore().getActivityParams(type).getTypicalDuration(),
                    config.planCalcScore().getActivityParams(type).getMinimalDuration() / 2)
                            .inverseCumulativeProbability(Math.random());
        } catch (MathException e) {
            e.printStackTrace();
            return;
        }
        totalDurations += duration;
        if (type.equals("home")) {
            activity = new ActivityImpl(type, homeCoord);
            ((ActivityImpl) activity).setFacilityId(homeFacilityId);
        } else {
            ActivityFacility facility = getRandomFacilityAndLinkId(type, prevActivityCoord);
            activity = new ActivityImpl(type, facility.getCoord());
            ((ActivityImpl) activity).setFacilityId(facility.getId());
        }
        ((ActivityImpl) activity).setEndTime(dayPos * Time.MIDNIGHT + totalDurations);
        plan.addActivity(activity);
    }
    if (activity == null || !activity.getType().equals(typeLast)
            || !activity.getFacilityId().equals(lastFacilityId)) {
        if (totalDurations >= Time.MIDNIGHT) {
            totalDurations = Time.MIDNIGHT;
            ((ActivityImpl) plan.getPlanElements().get(plan.getPlanElements().size() - 1))
                    .setEndTime(dayPos * Time.MIDNIGHT + totalDurations - 1);
        }
        plan.addLeg(new LegImpl(carAvailable ? TransportMode.car : TransportMode.pt));
        totalDurations = Time.MIDNIGHT;
        activity = new ActivityImpl(typeLast, lastCoord);
        ((ActivityImpl) activity).setFacilityId(lastFacilityId);
        ((ActivityImpl) activity).setEndTime(dayPos * Time.MIDNIGHT + totalDurations);
        plan.addActivity(activity);
    }
}