List of usage examples for org.apache.commons.math.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:playground.johannes.gsv.synPop.analysis.ActivityDistanceTruncatedTask.java
@Override protected DescriptiveStatistics statistics(Collection<ProxyPerson> persons, String purpose, String mode) { DescriptiveStatistics stats = super.statistics(persons, purpose, mode); if (threshold > 0) { DescriptiveStatistics newStats = new DescriptiveStatistics(); for (int i = 0; i < stats.getN(); i++) { double val = stats.getElement(i); if (val >= threshold) { newStats.addValue(val); }// w w w .ja va 2 s .co m } return newStats; } else { return stats; } }
From source file:playground.johannes.gsv.synPop.analysis.LegDistanceTask.java
protected DescriptiveStatistics statistics(Collection<ProxyPerson> persons, String purpose, String mode) { DescriptiveStatistics stats = new DescriptiveStatistics(); int cntNoVal = 0; for (ProxyPerson person : persons) { ProxyPlan plan = person.getPlan(); for (int i = 0; i < plan.getLegs().size(); i++) { ProxyObject leg = plan.getLegs().get(i); ProxyObject act = plan.getActivities().get(i + 1); if (mode == null || mode.equalsIgnoreCase(leg.getAttribute(CommonKeys.LEG_MODE))) { if (purpose == null || purpose.equalsIgnoreCase((String) act.getAttribute(CommonKeys.ACTIVITY_TYPE))) { String distStr = leg.getAttribute(attKey); if (distStr != null) { double d = Double.parseDouble(distStr); stats.addValue(d); } else { cntNoVal++;//from w ww . j ava 2 s .c o m } } } } } if (cntNoVal > 0) { logger.warn(String.format("No value specified for %s trips of purpose %s.", cntNoVal, purpose)); } return stats; }
From source file:playground.johannes.gsv.synPop.analysis.PkmTask.java
@Override public void analyze(Collection<ProxyPerson> persons, Map<String, DescriptiveStatistics> results) { Set<String> purposes = new HashSet<String>(); for (ProxyPerson person : persons) { ProxyPlan plan = person.getPlan(); for (int i = 0; i < plan.getActivities().size(); i++) { purposes.add((String) plan.getActivities().get(i).getAttribute(CommonKeys.ACTIVITY_TYPE)); }// w w w .jav a 2 s. c o m } purposes.add(null); for (String purpose : purposes) { double pkm = 0; for (ProxyPerson person : persons) { ProxyPlan plan = person.getPlans().get(0); for (int i = 1; i < plan.getLegs().size(); i++) { ProxyObject leg = plan.getLegs().get(i); if (mode == null || mode.equalsIgnoreCase(leg.getAttribute(CommonKeys.LEG_MODE))) { ProxyObject act = plan.getActivities().get(i + 1); if (purpose == null || purpose.equalsIgnoreCase(act.getAttribute(CommonKeys.ACTIVITY_TYPE))) { String value = leg.getAttribute(CommonKeys.LEG_ROUTE_DISTANCE); if (value != null) { pkm += Double.parseDouble(value); } } } } } if (purpose == null) purpose = "all"; DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(pkm); results.put(String.format("pkm.route.%s", purpose), stats); } }
From source file:playground.johannes.gsv.synPop.analysis.PkmTaskSeason.java
@Override public void analyze(Collection<ProxyPerson> persons, Map<String, DescriptiveStatistics> results) { Set<String> seasons = new HashSet<String>(); for (ProxyPerson person : persons) { String month = (String) person.getAttribute(MIDKeys.PERSON_MONTH); if (month != null) { String season = "winter"; if (month.equalsIgnoreCase(MIDKeys.APRIL)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.MAY)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.JUNE)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.JULY)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.AUGUST)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.SEPTEMBER)) { season = "summer"; } else if (month.equalsIgnoreCase(MIDKeys.OCTOBER)) { season = "summer"; }/*from www. ja va 2 s . c om*/ seasons.add(season); } } // purposes.add(null); for (String season : seasons) { double pkm = 0; for (ProxyPerson person : persons) { String theSeason = person.getAttribute(CommonKeys.ACTIVITY_TYPE); ProxyPlan plan = person.getPlans().get(0); for (int i = 1; i < plan.getLegs().size(); i++) { ProxyObject leg = plan.getLegs().get(i); if (mode == null || mode.equalsIgnoreCase(leg.getAttribute(CommonKeys.LEG_MODE))) { // ProxyObject act = plan.getActivities().get(i + 1); if (season == null || season.equalsIgnoreCase(theSeason)) { String value = leg.getAttribute(CommonKeys.LEG_ROUTE_DISTANCE); if (value != null) { pkm += Double.parseDouble(value); } } } } } if (season == null) season = "all"; DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(pkm); results.put(String.format("pkm.route.%s", season), stats); } }
From source file:playground.johannes.gsv.synPop.analysis.SpeedFactorAnalyzer.java
@Override public void analyze(Collection<ProxyPerson> persons, Map<String, DescriptiveStatistics> results) { Set<String> modes = new HashSet<String>(); for (ProxyPerson person : persons) { ProxyPlan plan = person.getPlan(); for (int i = 0; i < plan.getLegs().size(); i++) { modes.add(plan.getLegs().get(i).getAttribute(CommonKeys.LEG_MODE)); }/*from ww w . j a va2 s .c om*/ } modes.add(null); for (String mode : modes) { TDoubleArrayList distances = new TDoubleArrayList(persons.size() * 3); TDoubleArrayList durations = new TDoubleArrayList(persons.size() * 3); double sumDist = 0; double sumDur = 0; for (ProxyPerson person : persons) { ProxyPlan plan = person.getPlan(); for (ProxyObject leg : plan.getLegs()) { if (mode == null || mode.equalsIgnoreCase(leg.getAttribute(CommonKeys.LEG_MODE))) { String distVal = leg.getAttribute(CommonKeys.LEG_ROUTE_DISTANCE); String startVal = leg.getAttribute(CommonKeys.LEG_START_TIME); String endVal = leg.getAttribute(CommonKeys.LEG_END_TIME); if (distVal != null && startVal != null && endVal != null) { double dist = Double.parseDouble(distVal); double start = Double.parseDouble(startVal); double end = Double.parseDouble(endVal); double tt = end - start; if (tt > 0) { distances.add(dist); durations.add(tt); sumDist += dist; sumDur += tt; } } } } } if (mode == null) mode = "all"; String key = String.format("%s.%s", KEY, mode); double factor = sumDist / sumDur; DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(factor); results.put(key, stats); if (outputDirectoryNotNull()) { TDoubleDoubleHashMap map = Correlations.mean(distances.toNativeArray(), durations.toNativeArray(), new LinearDiscretizer(1000)); try { TXTWriter.writeMap(map, "Distance", "Traveltime", getOutputDirectory() + key + ".txt"); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:playground.johannes.gsv.synPop.analysis.TripDayVolumeTask.java
@Override public void analyze(Collection<ProxyPerson> persons, Map<String, DescriptiveStatistics> results) { TObjectIntHashMap<String> values = new TObjectIntHashMap<>(); for (ProxyPerson person : persons) { String day = person.getAttribute(CommonKeys.DAY); for (ProxyPlan plan : person.getPlans()) { int cnt = 0; for (ProxyObject leg : plan.getLegs()) { if (mode.equalsIgnoreCase(leg.getAttribute(CommonKeys.LEG_MODE))) { cnt++;// w ww. j a v a2s . co m } } values.adjustOrPutValue(day, cnt, cnt); } } TObjectIntIterator<String> it = values.iterator(); for (int i = 0; i < values.size(); i++) { it.advance(); DescriptiveStatistics tmp = new DescriptiveStatistics(); tmp.addValue(it.value()); results.put(it.key(), tmp); } }
From source file:playground.johannes.gsv.synPop.mid.analysis.SeasonsTask.java
@Override public void analyze(Collection<ProxyPerson> persons, Map<String, DescriptiveStatistics> results) { TObjectIntHashMap<String> map = new TObjectIntHashMap<String>(); for (ProxyPerson person : persons) { String month = person.getAttribute(MIDKeys.PERSON_MONTH); String season = "NA"; if (MIDKeys.NOVEMBER.equalsIgnoreCase(month)) { season = "win"; } else if (MIDKeys.DECEMBER.equalsIgnoreCase(month)) { season = "win"; } else if (MIDKeys.JANUARY.equalsIgnoreCase(month)) { season = "win"; } else if (MIDKeys.FEBRUARY.equalsIgnoreCase(month)) { season = "win"; } else if (MIDKeys.MARCH.equalsIgnoreCase(month)) { season = "win"; } else if (month != null) { season = "sum"; }//from w ww . j a va 2 s .co m String day = person.getAttribute(CommonKeys.DAY); String week = "wkday"; if (CommonKeys.SATURDAY.equalsIgnoreCase(day)) { week = "wkend"; } else if (CommonKeys.SUNDAY.equalsIgnoreCase(day)) { week = "wkend"; } Set<String> modes = new HashSet<String>(); for (ProxyObject leg : person.getPlan().getLegs()) { modes.add(leg.getAttribute(CommonKeys.LEG_MODE)); } for (String mode : modes) { StringBuilder key = new StringBuilder(100); key.append(season); key.append("."); key.append(day); key.append("."); key.append(mode); map.adjustOrPutValue(key.toString(), 1, 1); key = new StringBuilder(100); key.append(season); key.append("."); key.append(week); key.append("."); key.append(mode); map.adjustOrPutValue(key.toString(), 1, 1); } } TObjectIntIterator<String> it = map.iterator(); for (int i = 0; i < map.size(); i++) { it.advance(); DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(it.value()); results.put(it.key(), stats); } }
From source file:playground.johannes.mz2005.analysis.ActivityChainsTask.java
@Override public void analyze(Set<Trajectory> trajectories, Map<String, DescriptiveStatistics> results) { DescriptiveStatistics stats = new DescriptiveStatistics(); TObjectDoubleHashMap<String> chains = new TObjectDoubleHashMap<String>(); for (Trajectory trajectory : trajectories) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < trajectory.getElements().size(); i += 2) { String type = ((Activity) trajectory.getElements().get(i)).getType(); builder.append(type);//from w ww. j a v a 2 s . c o m builder.append("-"); } String chain = builder.toString(); chains.adjustOrPutValue(chain, 1, 1); stats.addValue((trajectory.getElements().size() + 1) / 2); } results.put(KEY, stats); if (outputDirectoryNotNull()) { try { TXTWriter.writeMap(chains, "chain", "n", getOutputDirectory() + "/actchains.txt", true); writeHistograms(stats, new DummyDiscretizer(), KEY, false); } catch (IOException e) { e.printStackTrace(); } } }
From source file:playground.johannes.mz2005.analysis.EscortsActivtyTypeTask.java
@Override public void analyze(Set<Trajectory> trajectories, Map<String, DescriptiveStatistics> results) { Map<String, DescriptiveStatistics> statsMap = new HashMap<String, DescriptiveStatistics>(); for (Trajectory trajectory : trajectories) { for (int i = 2; i < trajectory.getElements().size(); i += 2) { Activity destination = (Activity) trajectory.getElements().get(i); int escorts = escortData.getEscorts(trajectory.getPerson(), i - 1); // if (escorts > 0) { DescriptiveStatistics stats = statsMap.get(destination.getType()); if (stats == null) { stats = new DescriptiveStatistics(); statsMap.put(destination.getType(), stats); }// w ww . j a v a2 s .co m stats.addValue(escorts); // } } } try { TXTWriter.writeStatistics(statsMap, getOutputDirectory() + "/escorts_type.txt"); } catch (IOException e) { e.printStackTrace(); } }
From source file:playground.johannes.mz2005.analysis.TripDistEscortTask.java
@Override public void analyze(Set<Trajectory> trajectories, Map<String, DescriptiveStatistics> results) { TDoubleObjectHashMap<DescriptiveStatistics> statsMap = new TDoubleObjectHashMap<DescriptiveStatistics>(); for (Trajectory trajectory : trajectories) { for (int i = 2; i < trajectory.getElements().size(); i += 2) { Activity destination = (Activity) trajectory.getElements().get(i); Id id = destination.getFacilityId(); Coord dest = facilities.getFacilities().get(id).getCoord(); Activity origin = (Activity) trajectory.getElements().get(i - 2); id = origin.getFacilityId(); ActivityFacility fac = facilities.getFacilities().get(id); Coord source = fac.getCoord(); double d = calculator.distance(MatsimCoordUtils.coordToPoint(source), MatsimCoordUtils.coordToPoint(dest)); int escorts = escortData.getEscorts(trajectory.getPerson(), i - 1); DescriptiveStatistics stats = statsMap.get(escorts); if (stats == null) { stats = new DescriptiveStatistics(); statsMap.put(escorts, stats); }// ww w.j a v a 2 s . c o m if (d > 0) stats.addValue(d); } } try { TXTWriter.writeStatistics(statsMap, "escorts", getOutputDirectory() + "/d_trip_escorts.txt"); } catch (IOException e) { e.printStackTrace(); } }