use of cern.colt.list.DoubleArrayList in project tdq-studio-se by Talend.
the class KnownDoubleQuantileEstimator method quantileElements.
/**
* Computes the specified quantile elements over the values previously added.
* @param phis the quantiles for which elements are to be computed. Each phi must be in the interval [0.0,1.0]. <tt>phis</tt> must be sorted ascending.
* @return the approximate quantile elements.
*/
public DoubleArrayList quantileElements(DoubleArrayList phis) {
/*
* The KNOWN quantile finder reads off quantiles from FULL buffers only.
* Since there might be a partially full buffer, this method first satisfies this constraint by temporarily filling a few +infinity, -infinity elements to make up a full block.
* This is in full conformance with the explicit approximation guarantees.
*
* For those of you working on online apps:
* The approximation guarantees are given for computing quantiles AFTER N elements have been filled, not for intermediate displays.
* If you have one thread filling and another thread displaying concurrently, you will note that in the very beginning the infinities will dominate the display.
* This could confuse users, because, of course, they don't expect any infinities, even if they "disappear" after a short while.
* To prevent panic exclude phi's close to zero or one in the early phases of processing.
*/
DoubleBuffer partial = this.bufferSet._getPartialBuffer();
int missingValues = 0;
if (partial != null) {
// any auxiliary infinities needed?
missingValues = bufferSet.k() - partial.size();
if (missingValues <= 0)
throw new RuntimeException("Oops! illegal missing values.");
// System.out.println("adding "+missingValues+" infinity elements...");
this.addInfinities(missingValues, partial);
// determine beta (N + Infinity values = beta * N)
this.beta = (this.totalElementsFilled + missingValues) / (double) this.totalElementsFilled;
} else {
this.beta = 1.0;
}
DoubleArrayList quantileElements = super.quantileElements(phis);
// remove the temporarily added infinities.
if (partial != null)
removeInfinitiesFrom(missingValues, partial);
// now you can continue filling the remaining values, if any.
return quantileElements;
}
use of cern.colt.list.DoubleArrayList in project onebusaway-application-modules by camsys.
the class CurrentVehicleEstimationServiceImpl method computeCumulativeProbabilityForRealTimeBlockLocations.
private void computeCumulativeProbabilityForRealTimeBlockLocations(Map<Date, Record> recordsByTime, List<BlockLocation> locations, double minProbabilityForConsideration, List<CurrentVehicleEstimateBean> beans) {
DoubleArrayList ps = new DoubleArrayList();
for (BlockLocation location : locations) {
Date t = new Date(location.getTime());
Record record = recordsByTime.get(t);
CoordinatePoint userLocation = record.getLocation();
CoordinatePoint vehicleLocation = location.getLocation();
double d = SphericalGeometryLibrary.distance(userLocation, vehicleLocation);
double p = _realTimeLocationDeviationModel.probability(d);
ps.add(p);
}
BlockLocation last = locations.get(locations.size() - 1);
double mu = Descriptive.mean(ps);
String debug = asString(ps);
addResult(last, mu, debug, minProbabilityForConsideration, beans);
}
use of cern.colt.list.DoubleArrayList in project onebusaway-application-modules by camsys.
the class BlockLocationHistoryTask method constructHistory.
private ScheduleDeviationHistory constructHistory(AgencyAndId tripId, BlockLocationArchiveRecordMap recordsByInstance) {
List<SortedMap<Integer, Double>> traces = new ArrayList<SortedMap<Integer, Double>>();
Range tRange = new Range();
sortAndArrangeTraces(recordsByInstance, traces, tRange);
int step = computeSamplingStep(traces);
int from = (int) (Math.ceil(tRange.getMin() / step) * step);
int to = (int) (Math.floor(tRange.getMax() / step) * step);
SortedMap<Integer, Double> mus = new TreeMap<Integer, Double>();
SortedMap<Integer, Double> sigmas = new TreeMap<Integer, Double>();
computeMeanAndStandardDeviationForTraces(traces, from, to, step, mus, sigmas);
removeOutlierTraces(traces, mus, sigmas);
int numOfTraces = traces.size();
DoubleArrayList scheduleTimes = new DoubleArrayList();
List<DoubleArrayList> scheduleDeviations = new ArrayList<DoubleArrayList>();
for (int i = 0; i < numOfTraces; i++) scheduleDeviations.add(new DoubleArrayList());
for (int t = from; t <= to; t += step) {
DoubleArrayList rawValues = new DoubleArrayList();
DoubleArrayList values = new DoubleArrayList();
for (SortedMap<Integer, Double> m : traces) {
if (t < m.firstKey() || t > m.lastKey()) {
rawValues.add(Double.NaN);
continue;
}
double schedDev = InterpolationLibrary.interpolate(m, t);
values.add(schedDev);
rawValues.add(schedDev);
}
if (values.size() < Math.max(_minSampleSize, 2))
continue;
double mu = Descriptive.mean(values);
double sigma = Descriptive.sampleStandardDeviation(values.size(), Descriptive.sampleVariance(values, mu));
int goodValueCount = pruneOutlierValues(rawValues, mu, sigma);
if (goodValueCount < _minSampleSize)
continue;
scheduleTimes.add(t);
for (int traceIndex = 0; traceIndex < traces.size(); traceIndex++) scheduleDeviations.get(traceIndex).add(rawValues.get(traceIndex));
}
scheduleTimes.trimToSize();
double[] scheduleTimesArray = scheduleTimes.elements();
double[][] scheduleDeviationsArrays = new double[numOfTraces][];
for (int traceIndex = 0; traceIndex < numOfTraces; traceIndex++) {
DoubleArrayList list = scheduleDeviations.get(traceIndex);
list.trimToSize();
scheduleDeviationsArrays[traceIndex] = list.elements();
}
return new ScheduleDeviationHistory(tripId, scheduleTimesArray, scheduleDeviationsArrays);
}
use of cern.colt.list.DoubleArrayList in project onebusaway-application-modules by camsys.
the class BlockLocationHistoryTask method computeMeanAndStandardDeviationForTraces.
private void computeMeanAndStandardDeviationForTraces(List<SortedMap<Integer, Double>> traces, int from, int to, int step, SortedMap<Integer, Double> mus, SortedMap<Integer, Double> sigmas) {
for (int x = from; x <= to; x += step) {
DoubleArrayList values = new DoubleArrayList();
for (SortedMap<Integer, Double> m : traces) {
if (x < m.firstKey() || x > m.lastKey())
continue;
double schedDev = InterpolationLibrary.interpolate(m, x);
values.add(schedDev);
}
if (values.size() < 2)
continue;
double mu = Descriptive.mean(values);
double sigma = Descriptive.sampleStandardDeviation(values.size(), Descriptive.sampleVariance(values, mu));
mus.put(x, mu);
sigmas.put(x, sigma);
}
}
use of cern.colt.list.DoubleArrayList in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTask method computeStopDirection.
private String computeStopDirection(NarrativeProviderImpl provider, Map<AgencyAndId, List<ProjectedPoint>> shapePointCache, Stop stop, StopEntry stopEntry) {
String direction = translateGtfsDirection(stop.getDirection());
if (direction != null)
return direction;
Collection<PointAndOrientation> orientations = getAllOrientationsForStop(provider, stopEntry);
DoubleArrayList ys = new DoubleArrayList();
DoubleArrayList xs = new DoubleArrayList();
for (PointAndOrientation po : orientations) {
double orientation = Math.toRadians(po.getOrientation());
double x = Math.cos(orientation);
double y = Math.sin(orientation);
xs.add(x);
ys.add(y);
}
if (ys.isEmpty())
return null;
if (ys.size() == 1) {
double theta = Math.atan2(ys.get(0), xs.get(0));
return getAngleAsDirection(theta);
}
double yMu = Descriptive.mean(ys);
double xMu = Descriptive.mean(xs);
/**
* Check for undefined case where angles are directly opposite
*/
if (yMu == 0.0 && xMu == 0.0)
return null;
double thetaMu = Math.atan2(yMu, xMu);
double yVariance = Descriptive.sampleVariance(ys, yMu);
double xVariance = Descriptive.sampleVariance(xs, xMu);
double yStdDev = Descriptive.sampleStandardDeviation(ys.size(), yVariance);
double xStdDev = Descriptive.sampleStandardDeviation(xs.size(), xVariance);
if (yStdDev > _stopDirectionStandardDeviationThreshold || xStdDev > _stopDirectionStandardDeviationThreshold) {
return null;
}
DoubleArrayList normalizedThetas = new DoubleArrayList();
for (PointAndOrientation po : orientations) {
double orientation = Math.toRadians(po.getOrientation());
double delta = orientation - thetaMu;
delta = normalizeDelta(delta);
orientation = thetaMu + delta;
normalizedThetas.add(orientation);
}
normalizedThetas.sort();
double thetaMedian = Descriptive.median(normalizedThetas);
return getAngleAsDirection(thetaMedian);
}
Aggregations