Methods Summary |
---|
public void | addSample(android.location.Location location, long duration)
updateTemporalHistogram(location.getTime(), duration);
// use time field to store duation of this location
// TODO: extend Location class with additional field for this.
location.setTime(duration);
mLocations.add(location);
|
public void | consolidate()
// If there is no new location added during this period, do nothing.
if (mLocations.size() == 0) {
return;
}
double[] newCenter = {0f, 0f, 0f};
long newDuration = 0l;
// update cluster center
for (Location location : mLocations) {
double[] vector = getLocationVector(location);
long duration = location.getTime(); // in seconds
if (duration == 0) {
throw new RuntimeException("location duration is zero");
}
newDuration += duration;
for (int i = 0; i < VECTOR_LENGTH; ++i) {
newCenter[i] += vector[i] * duration;
}
}
if (newDuration == 0l) {
throw new RuntimeException("new duration is zero!");
}
for (int i = 0; i < VECTOR_LENGTH; ++i) {
newCenter[i] /= newDuration;
}
// remove location data
mLocations.clear();
// The updated center is the weighted average of the existing and the new
// centers. Note that if the cluster is consolidated for the first time,
// the weight for the existing cluster would be zero.
averageCenter(newCenter, newDuration);
// update histogram
for (Map.Entry<String, Long> entry : mNewHistogram.entrySet()) {
String timeLabel = entry.getKey();
long duration = entry.getValue();
if (mHistogram.containsKey(timeLabel)) {
duration += mHistogram.get(timeLabel);
}
mHistogram.put(timeLabel, duration);
}
mDuration += newDuration;
mNewHistogram.clear();
|
public java.lang.String | getSemanticClusterId()
return mSemanticClusterId;
|
public boolean | hasSemanticClusterId()
return mSemanticClusterId != null;
|
public void | moveAwayCluster(android.bordeaux.services.LocationCluster cluster, float distance)
double[] vector = new double[VECTOR_LENGTH];
double dot = 0f;
for (int i = 0; i < VECTOR_LENGTH; ++i) {
dot += mCenter[i] * cluster.mCenter[i];
}
double norm = 0f;
for (int i = 0; i < VECTOR_LENGTH; ++i) {
vector[i] = mCenter[i] - dot * cluster.mCenter[i];
norm += vector[i] * vector[i];
}
norm = Math.sqrt(norm);
double radian = distance / EARTH_RADIUS;
for (int i = 0; i < VECTOR_LENGTH; ++i) {
mCenter[i] = cluster.mCenter[i] * Math.cos(radian) +
(vector[i] / norm) * Math.sin(radian);
}
|
public void | setSemanticClusterId(java.lang.String semanticClusterId)
mSemanticClusterId = semanticClusterId;
|
private void | updateTemporalHistogram(long time, long duration)
HashMap<String, String> timeFeatures = TimeStatsAggregator.getAllTimeFeatures(time);
String timeOfWeek = timeFeatures.get(TimeStatsAggregator.TIME_OF_WEEK);
long totalDuration = (mNewHistogram.containsKey(timeOfWeek)) ?
mNewHistogram.get(timeOfWeek) + duration : duration;
mNewHistogram.put(timeOfWeek, totalDuration);
String timeOfDay = timeFeatures.get(TimeStatsAggregator.TIME_OF_DAY);
totalDuration = (mNewHistogram.containsKey(timeOfDay)) ?
mNewHistogram.get(timeOfDay) + duration : duration;
mNewHistogram.put(timeOfDay, totalDuration);
|