Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions engine/configs/geolife.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"data_path": "output/geolife.parquet",
"data_path": "data/geolife.parquet",
"seed": 42,
"budget_shares": [0.0025, 0.005, 0.01, 0.02],
"split": {
Expand All @@ -8,8 +8,8 @@
},
"algorithms": ["RDP", "SED"],
"knn": {
"k": 5,
"query_count": 10
"k": 10,
"query_count": 0
},
"range": {
"query_count": 500,
Expand Down
20 changes: 18 additions & 2 deletions engine/include/backend/engine/core/trajectory_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <span>
#include <vector>

namespace core {

// Smallest axis-aligned box around a trajectory's x/y.
struct BoundingBox {
double x_min = -std::numeric_limits<double>::infinity();
double x_max = std::numeric_limits<double>::infinity();
double y_min = -std::numeric_limits<double>::infinity();
double y_max = std::numeric_limits<double>::infinity();
};

struct TrajectoryView {
std::int32_t trajectory_id;
std::span<const std::int64_t> t;
std::span<const double> lat;
std::span<const double> lon;
std::span<const double> x;
std::span<const double> y;
BoundingBox bbox{};

std::size_t size() const { return t.size(); }
};
Expand All @@ -32,8 +42,13 @@ class TrajectoryDb {
const auto start = m_offsets[i];
const auto len = m_offsets[i + 1] - start;
return TrajectoryView{
m_trajectory_ids[i], {m_t.data() + start, len}, {m_lat.data() + start, len},
{m_lon.data() + start, len}, {m_x.data() + start, len}, {m_y.data() + start, len},
m_trajectory_ids[i],
{m_t.data() + start, len},
{m_lat.data() + start, len},
{m_lon.data() + start, len},
{m_x.data() + start, len},
{m_y.data() + start, len},
m_boxes[i],
};
}

Expand All @@ -48,6 +63,7 @@ class TrajectoryDb {
std::vector<double> m_lon;
std::vector<double> m_x;
std::vector<double> m_y;
std::vector<BoundingBox> m_boxes;
};

// Copies validated trajectories, including projected coordinates, in the given order.
Expand Down
3 changes: 3 additions & 0 deletions engine/include/backend/engine/evaluator/knn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace evaluator {
struct KnnScores {
double kendalls_tau = std::numeric_limits<double>::quiet_NaN();
double recall_at_k = std::numeric_limits<double>::quiet_NaN();
std::size_t query_count = 0;
std::size_t tau_query_count = 0; // queries with at least two shared neighbors
};

// Each score is averaged over the queries where it is defined, NaN if it is defined for none.
Expand All @@ -21,6 +23,7 @@ KnnScores evaluate_knn(const core::TrajectoryDb &compressed, const query::KnnWor

namespace evaluator::knn {

// Rank agreement on shared neighbors only; NaN when fewer than two are shared.
double kendalls_tau(const std::vector<std::size_t> &original,
const std::vector<std::size_t> &simplified);

Expand Down
2 changes: 1 addition & 1 deletion engine/include/backend/engine/query/knn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ KnnWorkload generate_knn_queries(const core::TrajectoryDb &original,
std::uint64_t seed = 42);

// Indices into trajectories of the k trajectories closest to query by discrete Fréchet
// distance, closest first.
// distance, closest first. Equal distances are ordered by database index.
std::vector<std::size_t> knn(const core::TrajectoryDb &trajectories,
const core::TrajectoryView &query, std::size_t k);

Expand Down
19 changes: 19 additions & 0 deletions engine/src/core/trajectory_db.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "backend/engine/core/trajectory_db.hpp"
#include "backend/engine/core/projection.hpp"
#include <algorithm>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>
Expand Down Expand Up @@ -37,6 +39,21 @@ TrajectoryDb::TrajectoryDb(std::vector<std::uint64_t> offsets,
xs[k] = p.x;
ys[k] = p.y;
}

// For each trajectory it goes throguh all its points
// and keeps min/max of x and y coordinates seen
constexpr double inf = std::numeric_limits<double>::infinity();
m_boxes.resize(size());
for (std::size_t i = 0; i < size(); ++i) {
BoundingBox box{inf, -inf, inf, -inf};
for (auto k = m_offsets[i]; k < m_offsets[i + 1]; ++k) {
box.x_min = std::min(box.x_min, xs[k]);
box.x_max = std::max(box.x_max, xs[k]);
box.y_min = std::min(box.y_min, ys[k]);
box.y_max = std::max(box.y_max, ys[k]);
}
m_boxes[i] = box;
}
}

TrajectoryDb subset(const TrajectoryDb &trajectories, std::span<const std::size_t> indices) {
Expand All @@ -55,10 +72,12 @@ TrajectoryDb subset(const TrajectoryDb &trajectories, std::span<const std::size_
result.m_lon.reserve(num_points);
result.m_x.reserve(num_points);
result.m_y.reserve(num_points);
result.m_boxes.reserve(indices.size());

for (const std::size_t i : indices) {
const auto trajectory = trajectories.trajectory(i);
result.m_trajectory_ids.push_back(trajectory.trajectory_id);
result.m_boxes.push_back(trajectory.bbox);
result.m_t.insert(result.m_t.end(), trajectory.t.begin(), trajectory.t.end());
result.m_lat.insert(result.m_lat.end(), trajectory.lat.begin(), trajectory.lat.end());
result.m_lon.insert(result.m_lon.end(), trajectory.lon.begin(), trajectory.lon.end());
Expand Down
2 changes: 2 additions & 0 deletions engine/src/evaluator/knn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ KnnScores evaluate_knn(const core::TrajectoryDb &compressed, const query::KnnWor
}

KnnScores scores;
scores.query_count = workload.entries.size();
scores.tau_query_count = tau_scored;
if (tau_scored != 0)
scores.kendalls_tau = tau_sum / static_cast<double>(tau_scored);
if (recall_scored != 0)
Expand Down
6 changes: 4 additions & 2 deletions engine/src/pipeline/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ std::size_t total_budget(const core::TrajectoryDb &trajectories, double share) {
}

void print_scores(const evaluator::Scoretable &scores) {
std::cout << " knn tau: " << scores.knn.kendalls_tau
std::cout << " knn tau on shared neighbors: " << scores.knn.kendalls_tau << " ("
<< scores.knn.tau_query_count << '/' << scores.knn.query_count << " queries)"
<< ", recall@k: " << scores.knn.recall_at_k << '\n';
std::cout << " where-at: within radius=" << scores.where_at.within_radius
<< ", average hit=" << scores.where_at.average_hit << '\n';
Expand All @@ -57,10 +58,11 @@ void print_scores(const evaluator::Scoretable &scores) {
void run(const Config &config) {
const auto [database, queries] = load_split(config);
print_size("database", database);
print_size("queries", queries);
print_size("query pool", queries);

const auto knn_workload =
query::generate_knn_queries(database, queries, config.knn, config.seed);
std::cout << "knn: " << knn_workload.entries.size() << " queries, k=" << knn_workload.k << '\n';
const auto where_at = query::generate_where_at_queries(database, config.where_at, config.seed);
std::cout << "where-at: " << where_at.queries.size() << " probes, "
<< where_at.skipped_trajectories << " trips without eligible time\n";
Expand Down
Loading
Loading