Example usage for org.apache.commons.math.util ResizableDoubleArray addElement

List of usage examples for org.apache.commons.math.util ResizableDoubleArray addElement

Introduction

In this page you can find the example usage for org.apache.commons.math.util ResizableDoubleArray addElement.

Prototype

public synchronized void addElement(double value) 

Source Link

Document

Adds an element to the end of this expandable array.

Usage

From source file:edu.harvard.med.screensaver.analysis.ZScoreFunction.java

public void initializeAggregates(Collection<Double> valuesToNormalizeOverController) {
    ResizableDoubleArray tmpDoubleValues = new ResizableDoubleArray();
    for (Double value : valuesToNormalizeOverController) {
        tmpDoubleValues.addElement(value);
    }//from w ww. ja  v a  2  s .c  om
    _stdDev = new StandardDeviation().evaluate(tmpDoubleValues.getElements());
    _mean = new Mean().evaluate(tmpDoubleValues.getElements());
    _initialized = true;
}

From source file:edu.harvard.med.screensaver.analysis.heatmaps.HeatMap.java

private void initialize(Filter<Pair<WellKey, ResultValue>> scoringFilter,
        AggregateFunction<Double> scoringFunc) {

    Collection<Double> aggregationValues = new ArrayList<Double>();
    for (WellKey wellKey : _resultValues.keySet()) {
        if (wellKey.getPlateNumber() == _plateNumber) {
            ResultValue rv = getResultValue(wellKey.getRow(), wellKey.getColumn());
            if (rv != null && !scoringFilter.exclude(new Pair<WellKey, ResultValue>(wellKey, rv))) {
                aggregationValues.add(getRawValue(wellKey.getRow(), wellKey.getColumn()));
            }//from  w  w  w .j a va 2 s.c o  m
        }
    }

    scoringFunc.initializeAggregates(aggregationValues);

    _statistics = new DescriptiveStatisticsImpl();
    ResizableDoubleArray medianValues = new ResizableDoubleArray();
    for (Double rawValue : aggregationValues) {
        double scoredValue = scoringFunc.compute(rawValue);
        _statistics.addValue(scoredValue);
        medianValues.addElement(scoredValue);
    }

    _median = new Median().evaluate(medianValues.getElements());

    _scalableColorFunction.setLowerLimit(_statistics.getMin());
    _scalableColorFunction.setUpperLimit(_statistics.getMax());
}

From source file:herbie.running.analysis.CalcLegTimesKTI.java

private void handleActivityStartOrEnd(Id personId, double time) {
    String mode;//from w w  w  .j  a v a2  s . co m
    if (this.agentPerformsPtInteraction.containsKey(personId)) {
        mode = standardPtMode;
    } else {
        mode = onlyPtWalk;
    }

    Frequency frequency = null;
    ResizableDoubleArray rawData = null;
    if (!this.frequencies.containsKey(mode)) {
        frequency = new Frequency();
        this.frequencies.put(mode, frequency);
        rawData = new ResizableDoubleArray();
        this.rawData.put(mode, rawData);
    } else {
        frequency = this.frequencies.get(mode);
        rawData = this.rawData.get(mode);
    }

    if (this.ptPerformingTime.get(personId) >= 0.0 && eventIsInTimeWindow(time)) {
        frequency.addValue(this.ptPerformingTime.get(personId));
        rawData.addElement(this.ptPerformingTime.get(personId));
    }

    this.agentPerformsAnyPt.remove(personId);
    this.agentPerformsPtInteraction.remove(personId);
    this.ptPerformingTime.remove(personId);
}

From source file:herbie.running.analysis.CalcLegTimesKTI.java

@Override
public void handleEvent(PersonArrivalEvent event) {
    Double depTime = this.agentDepartures.remove(event.getPersonId());
    Person agent = this.population.getPersons().get(event.getPersonId());

    if (depTime != null && agent != null) {

        Id personId = event.getPersonId();
        double travelTime = event.getTime() - depTime;
        String mode = event.getLegMode();

        if (mode.equals("transit_walk") || mode.equals("pt")) {
            this.agentPerformsAnyPt.put(personId, true);

            if (this.ptPerformingTime.containsKey(personId)) {
                travelTime = travelTime + this.ptPerformingTime.get(personId);
            }//from  w  ww .j  a v a2 s. co m
            this.ptPerformingTime.put(personId, travelTime);
        } else {
            Frequency frequency = null;
            ResizableDoubleArray rawData = null;
            if (!this.frequencies.containsKey(mode)) {
                frequency = new Frequency();
                this.frequencies.put(mode, frequency);
                rawData = new ResizableDoubleArray();
                this.rawData.put(mode, rawData);
            } else {
                frequency = this.frequencies.get(mode);
                rawData = this.rawData.get(mode);
            }
            if (travelTime >= 0.0 && eventIsInTimeWindow(event.getTime())) {
                frequency.addValue(travelTime);
                rawData.addElement(travelTime);
            }
        }
    }
}

From source file:herbie.running.analysis.ModeSharesEventHandler.java

@Override
public void handleEvent(final PersonArrivalEvent arrivalEvent) {
    this.doReset();
    PersonDepartureEvent departureEvent = this.pendantDepartures.remove(arrivalEvent.getPersonId());
    String mode = arrivalEvent.getLegMode();
    Frequency frequency;//from w  w  w  .j  a  v a2  s.  com
    ResizableDoubleArray rawDataElement;
    Link departureLink;
    Link arrivalLink;
    double distance;

    // Consistency check...
    if (departureEvent == null) {
        log.warn("One arrival do not correspond to any departure for agent " + arrivalEvent.getPersonId());
        return;
    } else if (!mode.equals(departureEvent.getLegMode())) {
        log.warn("Departure and arrival have uncompatible modes!");
        return;
    }
    // consistency check... DONE

    if (this.frequencies.containsKey(mode)) {
        frequency = this.frequencies.get(mode);
        rawDataElement = this.rawData.get(mode);
    } else {
        frequency = new Frequency();
        rawDataElement = new ResizableDoubleArray();

        this.frequencies.put(mode, frequency);
        this.rawData.put(mode, rawDataElement);
    }

    // compute data
    departureLink = this.network.getLinks().get(departureEvent.getLinkId());
    arrivalLink = this.network.getLinks().get(arrivalEvent.getLinkId());

    distance = CoordUtils.calcDistance(departureLink.getCoord(), arrivalLink.getCoord());

    // remember data
    frequency.addValue(distance);
    rawDataElement.addElement(distance);
    this.maxDistance = Math.max(distance, this.maxDistance);
}

From source file:herbie.running.population.algorithms.PopulationLegDistanceDistribution.java

@Override
public void run(Plan plan) {

    boolean isPtLeg = false;
    double distForPt = 0.0;
    String ptMode = "standardPt";
    String onlyPtWalkMode = "onlyPtWalk";
    boolean containsPt = false;

    for (PlanElement pe : plan.getPlanElements()) {

        if (pe instanceof Leg) {

            Leg leg = (Leg) pe;//from   w  w  w. j  a va 2  s .c o m

            String mode = leg.getMode();

            if (mode.equals("transit_walk") || mode.equals("pt")) {
                if (mode.equals("pt"))
                    containsPt = true;

                mode = ptMode;

                if (!isPtLeg)
                    distForPt = 0.0;
                isPtLeg = true;

            } else {
                isPtLeg = false;
            }

            Frequency frequency = null;
            ResizableDoubleArray rawData = null;
            if (!this.frequencies.containsKey(mode)) {
                frequency = new Frequency();
                this.frequencies.put(mode, frequency);
                rawData = new ResizableDoubleArray();
                this.rawData.put(mode, rawData);
            } else {
                frequency = this.frequencies.get(mode);
                rawData = this.rawData.get(mode);
            }

            double distance = 0.0;
            if (leg.getMode().equals("transit_walk")) {
                distance = DistanceCalculations.getWalkDistance((GenericRouteImpl) leg.getRoute(), network);
            } else {
                if (leg instanceof LegImpl && leg.getRoute() == null
                        && !(leg.getRoute() instanceof LinkNetworkRouteImpl)
                        && !(leg.getRoute() instanceof ExperimentalTransitRoute)) {
                    log.warn(
                            "Not enough information on leg-object. Distance is set to 0.0 for this leg. Therefore no distance contribution....");
                } else {
                    distance = DistanceCalculations.getLegDistance(leg.getRoute(), network);
                }
            }

            if (isPtLeg) {
                distForPt += distance;
            } else {
                if (distance >= 0.0) {
                    frequency.addValue(distance);
                    rawData.addElement(distance);
                }
            }

            //            frequency.addValue(leg.getRoute().getDistance());
            //            rawData.addElement(leg.getRoute().getDistance());
        } else {
            if (pe instanceof Activity) {
                Activity act = (Activity) pe;
                if (isPtLeg && !act.getType().equals("pt interaction")) {
                    String mode;
                    if (!containsPt)
                        mode = onlyPtWalkMode;
                    else
                        mode = ptMode;

                    Frequency frequency = null;
                    ResizableDoubleArray rawData = null;
                    if (!this.frequencies.containsKey(mode)) {
                        frequency = new Frequency();
                        this.frequencies.put(mode, frequency);
                        rawData = new ResizableDoubleArray();
                        this.rawData.put(mode, rawData);
                    } else {
                        frequency = this.frequencies.get(mode);
                        rawData = this.rawData.get(mode);
                    }

                    if (distForPt >= 0.0) {
                        frequency.addValue(distForPt);
                        rawData.addElement(distForPt);
                    }

                    distForPt = 0.0;
                    isPtLeg = false;
                    containsPt = false;
                }
            }
        }
    }
}

From source file:playground.anhorni.surprice.analysis.ModeSharesEventHandler.java

@Override
public void handleEvent(final PersonArrivalEvent arrivalEvent) {
    this.doReset();
    PersonDepartureEvent departureEvent = this.pendantDepartures.remove(arrivalEvent.getPersonId());
    String mode = arrivalEvent.getLegMode();
    Frequency frequency;/*from  w w w .ja va2  s.  c o m*/
    ResizableDoubleArray rawDataElement;

    // Consistency check...
    if (departureEvent == null) {
        log.warn("One arrival do not correspond to any departure for agent " + arrivalEvent.getPersonId());
        return;
    } else if (!mode.equals(departureEvent.getLegMode())) {
        log.warn("Departure and arrival have uncompatible modes!");
        return;
    }
    // consistency check... DONE

    if (this.frequencies.containsKey(mode)) {
        frequency = this.frequencies.get(mode);
        rawDataElement = this.rawData.get(mode);
    } else {
        frequency = new Frequency();
        rawDataElement = new ResizableDoubleArray();

        this.frequencies.put(mode, frequency);
        this.rawData.put(mode, rawDataElement);
    }
    double xyVal = 0.0;
    if (this.xy.equals("times")) {
        xyVal = this.computeTimes(arrivalEvent, departureEvent);
    } else {
        xyVal = this.computeDistances(arrivalEvent, departureEvent);
    }
    // remember data
    frequency.addValue(xyVal);
    rawDataElement.addElement(xyVal);
}

From source file:playground.meisterk.org.matsim.analysis.CalcLegTimesKTI.java

@Override
public void handleEvent(PersonArrivalEvent event) {
    Double depTime = this.agentDepartures.remove(event.getPersonId());
    Person agent = this.population.getPersons().get(event.getPersonId());
    if (depTime != null && agent != null) {

        double travelTime = event.getTime() - depTime;
        String mode = event.getLegMode();

        Frequency frequency = null;/* w  w w  . jav  a 2  s  .  co m*/
        ResizableDoubleArray rawData = null;
        if (!this.frequencies.containsKey(mode)) {
            frequency = new Frequency();
            this.frequencies.put(mode, frequency);
            rawData = new ResizableDoubleArray();
            this.rawData.put(mode, rawData);
        } else {
            frequency = this.frequencies.get(mode);
            rawData = this.rawData.get(mode);
        }

        frequency.addValue(travelTime);
        rawData.addElement(travelTime);

    }
}

From source file:playground.meisterk.org.matsim.population.algorithms.PopulationLegDistanceDistribution.java

@Override
public void run(Plan plan) {

    for (PlanElement pe : plan.getPlanElements()) {
        if (pe instanceof Leg) {
            Leg leg = (Leg) pe;/*from   ww  w .j  a va2  s  .c  om*/
            String mode = leg.getMode();

            Frequency frequency = null;
            ResizableDoubleArray rawData = null;
            if (!this.frequencies.containsKey(mode)) {
                frequency = new Frequency();
                this.frequencies.put(mode, frequency);
                rawData = new ResizableDoubleArray();
                this.rawData.put(mode, rawData);
            } else {
                frequency = this.frequencies.get(mode);
                rawData = this.rawData.get(mode);
            }

            frequency.addValue(leg.getRoute().getDistance());
            rawData.addElement(leg.getRoute().getDistance());
        }
    }

}