---
title: Top-k Representative Similar Subtrajectory Query (TRSSQ)
url: https://www.emergentmind.com/topics/top-k-representative-similar-subtrajectory-query-trssq
type: topic
---

# Top-k Representative Similar Subtrajectory Query (TRSSQ)

Top-\(k\) Representative Similar Subtrajectory Query (TRSSQ) is a trajectory-mining query problem that seeks the \(k\) most representative subtrajectories similar to a query trajectory. In the formulation studied in "GTRSS: Graph-based Top-\(k\) Representative Similar Subtrajectory Query" [2507.05542], each data trajectory contributes a single representative subtrajectory, defined as the contiguous segment with maximum similarity to the query, and the TRSSQ result consists of the \(k\) distinct trajectories whose representative subtrajectories attain the largest similarity scores. The problem is motivated by the observation that existing methods rely on costly filtering-validation frameworks, resulting in slow response times, and the cited work proposes a graph-based alternative that avoids full-dataset scanning and heavy computation [2507.05542].

## 1. Formalization of TRSSQ

A trajectory of length \(n\) is defined as a sequence of points
\[
T=(p_1,p_2,\dots,p_n),\quad p_i=(x_i,y_i),
\]
with timestamp omitted for simplicity. A database of \(N\) trajectories is
\[
\mathcal D=\{T_{d_1},T_{d_2},\dots,T_{d_N}\}.
\]
A subtrajectory is any contiguous segment
\[
T_{i:j}=(p_i,p_{i+1},\dots,p_j),\quad 1\le i<j\le n.
\]

Given a data trajectory \(T_d\) and a query \(T_q\), the representative similar subtrajectory is defined as
\[
R_d=\arg\max_{T_{i:j}\subset T_d}{\rm Sim}(T_q,T_{i:j}),
\]
where \({\rm Sim}(\cdot,\cdot)\) is the similarity measure. Its score is
\[
S_d={\rm Sim}(T_q,R_d).
\]

The TRSSQ objective is then expressed over the set of representative subtrajectories \(\{R_1,\dots,R_N\}\) extracted from the database trajectories. For a requested top-\(k\), the target result is
\[
\mathcal R^*=\arg\max_{\mathcal R\subset\{R_i\},\,|\mathcal R|=k}\sum_{R\in\mathcal R}{\rm Sim}(T_q,R).
\]
Equivalently, if \(S_i={\rm Sim}(T_q,R_i)\), then
\[
\mathcal R^*=\text{the \(k\) distinct trajectories }T_{d_i}\text{ with largest }S_i.
\]

This formulation places the query emphasis on per-trajectory best-matching contiguous segments rather than on full-trajectory similarity. A plausible implication is that TRSSQ is tailored to settings in which only part of a trajectory is relevant to the query, while still enforcing diversity at the trajectory level by selecting distinct source trajectories.

## 2. Data Trajectory Similarity Metric

The cited framework introduces the Data Trajectory Similarity Metric (DTSM) because traditional measures such as DTW, EDR, and ERP compute whole-trajectory similarity but cannot directly measure the best aligned subsegments between two arbitrary trajectories [2507.05542]. DTSM addresses this by identifying the single most similar subtrajectory pair.

The overall DTSM definition is
\[
\Phi(T_{d_1},T_{d_2})=
\max_{\substack{1\le i<k\le n_1\\1\le j<\ell\le n_2}}
O_s\bigl(T_{d_1}[i:k],\,T_{d_2}[j:\ell]\bigr),
\]
where \(O_s(\cdot,\cdot)\) is a subtrajectory-to-subtrajectory similarity score. The maximizing pair is the most similar subtrajectory pair.

DTSM uses a point-pair matching rule parameterized by a threshold \(\epsilon\). With
\[
d(p,p')=\|p-p'\|_2,
\]
and subsegments \(A=T_{i:k}\), \(B=T'_{j:\ell}\), it counts
\[
C(A,B)=\bigl|\{(u,v)\mid d(p_{i+u-1},p'_{j+v-1})\le \epsilon\}\bigr|
\]
and
\[
D(A,B)=\bigl|\{(u,v)\mid d(p_{i+u-1},p'_{j+v-1})> \epsilon\}\bigr|.
\]
The corresponding similarity is
\[
O_s(A,B)=C(A,B)-D(A,B).
\]

For efficient computation, the method constructs a matrix \(A\in\{-1,1\}^{n_1\times n_2}\),
\[
A_{u,v}=
\begin{cases}
1,&d(p_{1;u},p_{2;v})\le\epsilon,\\
-1,&\text{otherwise}.
\end{cases}
\]
It then defines a recursive dynamic-programming quantity
\[
S(i,k,j,\ell)=\max\bigl\{S(i+1,k,j+1,\ell)+\mathrm{subcost}(p_{1;i},p_{2;j}),\;\dots\bigr\},
\]
where
\[
\mathrm{subcost}(p,p')=
\begin{cases}
+1,&d(p,p')\le\epsilon,\\
-1,&d(p,p')>\epsilon.
\end{cases}
\]
The paper specifies six alignment cases, denoted C1–C6, that govern the transition structure.

A central pruning rule states that if \(A_{i,j}=-1\), then no subsegment beginning at \((i,j)\) can exceed \(0\):
\[
\Phi\bigl(T_{d_1}[i:k],T_{d_2}[j:\ell]\bigr)\le 0
\quad\implies\quad
\text{prune }(i,j).
\]
The paper proves this rule by induction. Algorithm 1 implements the DP with memoization and early termination. Its worst-case complexity is reported as \(O(n_1\,n_2)\) in practice, versus \(O(n_1^2n_2^2)\) if done naively. This suggests that DTSM is not merely a scoring function but also a computational device that makes large-scale subtrajectory retrieval operationally feasible.

## 3. Dual-layer graph indexing

The GTRSS framework builds a dual-layer graph index in an offline phase. The two directed graphs are GARI, the Global Aggregated Representative Index, and CNDI, the Comprehensive Node Detail Index. In both layers, trajectories are nodes, and edges connect trajectories that are likely to share top-\(k\) subsegments [2507.05542].

The upper layer, GARI, is built through Representative Node Selection and Aggregation (RNSA). The process begins with grid and R-tree filtering. First, the spatial bounding box \((\min_x,\min_y,\max_x,\max_y)\) is computed. The space is then partitioned into \(M\times M\) equal grids of size
\[
w=(\max_x-\min_x)/M,\qquad h=(\max_y-\min_y)/M.
\]
Each cell maintains an R-tree of contained trajectories, and one center trajectory is selected per nonempty cell, producing the representative set \(D_g\).

GARI is then formed by computing \(\Phi(T_i,T_j)\) via DTSM for each pair \((T_i,T_j)\in D_g\). For each node \(T_i\), the other representative trajectories are sorted by similarity and partitioned into three buckets: \(A_{\rm close}\), consisting of the top \(\alpha\%\) most similar; \(A_{\rm middle}\), the next \(\beta\%\); and \(A_{\rm far}\), the remaining \((100-\alpha-\beta)\%\) least similar. One neighbor is sampled from each bucket, and directed edges are added accordingly.

The lower layer, CNDI, is built through Comprehensive Node Fine-grained Integration (CNFI). For each trajectory \(T\) in the full database \(\mathcal D\), the framework obtains \(\eta\) nearest neighbors \(D_{\rm close}\) via R-tree lookup and uniformly samples \(\eta\) random trajectories \(D_{\rm rand}\). It computes \(\Phi(T,T')\) for all \(T'\in D_{\rm close}\cup D_{\rm rand}\), sorts each set by similarity, and selects a fraction \(\lambda\) from the close set and \((1-\lambda)\) from the random set as final neighbors.

The separation into an aggregated upper graph and a detailed lower graph gives the framework both coarse and fine search structure. A plausible implication is that the upper layer is intended to improve global entry-point quality, while the lower layer supports local refinement around promising regions of the trajectory space.

## 4. Online query answering

For a query trajectory \(T_q\) and top-\(k\), the online phase proceeds in three stages: search on GARI, search on CNDI, and extraction of the final top-\(k\) representative subtrajectories [2507.05542].

The search on GARI starts from a randomly selected node \(v\). The framework computes
\[
S(v)=\Phi(T_q,v).
\]
For each neighbor \(u\) of \(v\), it computes \(S(u)=\Phi(T_q,u)\). If any neighbor has a larger score than the current node, the search moves to
\[
v\leftarrow \arg\max S(u),
\]
and repeats; otherwise it terminates at \(v^*\). The paper characterizes this hill-climbing process as a way to quickly find a globally representative trajectory.

The second stage starts from \(v^*\) and performs the same hill-climbing search in the lower graph CNDI. During this search, the framework maintains a visited set \(\mathcal V\) containing all visited nodes and their scores. When no neighbor improves the current score, the process stops at \(u^*\).

The final stage uses the visited set \(\mathcal V\). For each visited trajectory, the framework already has the representative subsegment and its score. It sorts these scores and returns the top \(k\) distinct trajectories’ subsegments.

This procedure differs from full-dataset scanning in that it restricts expensive similarity computation to graph neighborhoods explored during ascent. The reliance on a visited set rather than only the terminal node also indicates that the output is assembled from the local search trace rather than from a single endpoint.

## 5. Complexity characteristics

The indexing space complexity is
\[
O\bigl(M^2\cdot d_{\rm upper}+N\cdot d_{\rm lower}\bigr),
\]
where \(d_{\rm upper}\) and \(d_{\rm lower}\) are neighbor counts per node.

For the offline phase, the reported costs are divided into three components. Grid and R-tree processing requires \(O(N\log N)\). GARI construction, dominated by pairwise DTSM computation over \(|D_g|\approx M^2\), requires \(O(M^4L^2)\). CNDI neighbor construction requires \(O(N\,\eta\,L^2)\). The total offline time is therefore
\[
O\bigl(N\log N + M^4L^2 + N\,\eta\,L^2\bigr).
\]

For the online phase, each hill-climbing step visits \(d\) neighbors and invokes DTSM in \(O(L^2)\). The number of steps is stated to be \(O(\log N)\) in practice. Each of the two hill-climbing phases therefore costs
\[
O\bigl((\log N)\times d\times L^2\bigr),
\]
and the total online complexity is given as \(O(d\,L^2\log N)\).

These expressions clarify the design trade-off. The framework expends substantial offline effort to construct graph structure and preselect neighborhoods, then amortizes that effort during query processing. This suggests a deployment model in which query latency is prioritized over index-construction cost.

## 6. Empirical evaluation and reported behavior

The reported experiments use two real datasets: Xi’an (DiDi GAIA), with 3.1 M trajectories from October 2016, and Chengdu (DiDi GAIA), with 5.8 M trajectories from November 2016 [2507.05542]. After cleaning, the study samples 30 000 data trajectories and 2 000 query trajectories per city. Query lengths lie in \([30,90]\), and data lengths lie in \([90,300]\).

The baselines are OSF [10], described as subtrajectory filtering in Euclidean space; Grid, described as a simple uniform-cell spatial filter; LBF (RSSE) [14], described as a learning-based representative similarity estimator with filtering+validation; and the recent neural similarity models T3S [35] and TMN [37]. Evaluation uses Relative Rank (RR), where lower is better; Hit-Rate@\(k\) (HR@k), where higher is better; and R10@50, defined as the overlap between actual top-10 and predicted top-50.

The paper reports that GTRSS+CMA, using CMA as internal subtrajectory search, is best in all settings of Table I under DTW, EDR, and ERP. Under DTW, the Xi’an / Chengdu results are reported as follows.

| Method | HR@20 | R10@50 |
|---|---:|---:|
| T3S | 0.0215/0.0257 | 0.0531/0.0618 |
| TMN | 0.1197/0.1022 | 0.2692/0.2286 |
| RSSE | 0.2398/0.3129 | 0.5076/0.5683 |
| GTRSS(CMA) | 0.9215/0.5482 | 0.9255/0.7770 |
| GTRSS(POS) | 0.6785/0.6295 | 0.6695/0.6202 |
| GTRSS(PSS) | 0.8333/0.8061 | 0.8510/0.8254 |

The same table also reports HR@50 values of 0.0569/0.0628 for T3S, 0.2279/0.1897 for TMN, 0.3727/0.4301 for RSSE, 0.8963/0.5939 for GTRSS(CMA), 0.6692/0.6195 for GTRSS(POS), and 0.7745/0.7563 for GTRSS(PSS). The summary states that similar patterns hold for EDR and ERP.

For efficiency, the per-query times under DTW+PSS on Xi’an / Chengdu are reported as Grid \(\approx 10^4\) s, OSF \(\approx 10^3\) s, LBF \(\approx 10^3\) s, GTRSS+ExactS \(\approx 10^2\) s, and GTRSS+(CMA/POS/PSS) \(\le 10^1\) s. The paper further states that GTRSS+CMA answers a 2 kB query in \(\sim 2\) s, 100\(\times\) faster than prior state-of-the-art. In the abstract, the broader summary is that the method achieves retrieval accuracy of over 90 percent and up to two orders of magnitude speedup in query performance [2507.05542].

Scalability experiments vary the dataset size from 0.03 M to 0.8 M trajectories and report that GTRSS query time grows sublinearly, whereas OSF, Grid, and LBF scale linearly or worse. Ablation studies report that omitting the upper-layer GARI drops HR@50 by 40–50 points, removing random neighbors reduces HR by 15–20 points because search easily traps local optima, and recording all visited nodes improves final top-\(k\) recall by 5–10 points. These ablations situate TRSSQ performance not only in the similarity metric but also in the interaction between graph topology, initialization, and search trace retention.

Source: https://www.emergentmind.com/topics/top-k-representative-similar-subtrajectory-query-trssq