---
title: 'TrajLoc: Trajectory Similarity & Motion Control'
url: https://www.emergentmind.com/topics/trajloc
type: topic
---

# TrajLoc: Trajectory Similarity & Motion Control

TrajLoc is a name used for two distinct trajectory-centered methods. In "Simple Distances for Trajectories via Landmarks" [1804.11284], TrajLoc denotes a landmark-based embedding for piecewise-linear trajectories in $\mathbb R^2$, with induced distances $D^{\parallel}$ and $D^\pi$ that can become bona-fide metrics under density and general-position assumptions on the landmark set. In "TrajLoc: Trajectory-Attention Localization for Multi-Object Motion Control" [2607.00861], TrajLoc denotes a control mechanism for text-and-image-conditioned video diffusion in which each object token’s cross-attention weights are overwritten by a Gaussian heatmap centered on the target location at every frame. The two uses are unrelated in task formulation: the former is a trajectory similarity and indexing method, whereas the latter is a multi-object motion-control method for image-to-video generation.

## 1. Disambiguation and scope

The term TrajLoc refers to two separate constructions documented in the literature [1804.11284] [2607.00861].

| Usage of TrajLoc | Defining representation | Main use |
|---|---|---|
| "Trajectories via Landmarks" | $\phi(\tau) = (d(\tau,\ell_1), \ldots, d(\tau,\ell_m))$ with induced distances $D^{\parallel}$ and $D^\pi$ | trajectory similarity, k-means clustering, classification, approximate nearest-neighbor search |
| "Trajectory-Attention Localization" | per-object Gaussian heatmap overwrite of cross-attention, plus trajectory and appearance token embeddings | precise multi-object motion control in image-to-video diffusion |

This disambiguation matters because the two methods operate on different objects, optimize different objectives, and are evaluated with different metrics. The landmark-based method maps trajectories to Euclidean vectors and then uses standard Euclidean machinery. The diffusion-based method modifies attention maps and prompt tokens inside pretrained image-to-video backbones. A plausible implication is that the shared name should not be taken to indicate architectural continuity.

## 2. Landmark-distance TrajLoc: formal construction

In the landmark-based formulation, $\tau$ is a piecewise-linear trajectory in $\mathbb R^2$, and $L=\{\ell_1,\ldots,\ell_m\}$ is a fixed set of $m$ landmark points. The embedding is defined by
\[
\phi(\tau)=(d(\tau,\ell_1),\ldots,d(\tau,\ell_m)),
\]
where, in the version called $D^{\parallel}$, the landmark coordinate is
\[
d(\tau,\ell)=\min_{p\in\tau}\|p-\ell\|_2.
\]
The induced distance between two trajectories $\tau_1,\tau_2$ is the Euclidean distance in the embedding space,
\[
D^{\parallel}(\tau_1,\tau_2)\equiv \|\phi(\tau_1)-\phi(\tau_2)\|_2
=
\left(\sum_{i=1}^m (d(\tau_1,\ell_i)-d(\tau_2,\ell_i))^2\right)^{1/2}.
\]

Symmetry and the triangle inequality follow immediately from the Euclidean norm in $\mathbb R^m$. The nontrivial issue is positive-definiteness. The stated theorem assumes that every critical vertex of $\tau$ lies at least distance $\tau_0$ from all other segments and that $L$ is chosen so that for every such critical point $c$ there are at least three landmarks in general position. In particular, if $L$ is a sufficiently dense grid with step size $\eta \lesssim \tau_0/16$ over a domain $\Omega$ containing all trajectories, then $\phi$ is injective on that family and $D^{\parallel}$ is a metric [1804.11284]. The proof sketch uses three landmarks around each critical point whose distance-circles intersect only at that point; equality of all landmark distances then forces the second trajectory to pass through the same critical points and ultimately coincide everywhere.

A second variant, $D^\pi$, retains closest-point coordinates rather than only scalar distances. For each landmark $\ell_i$,
\[
p_i(\tau)=\arg\min_{p\in\tau}\|p-\ell_i\|_2,
\]
and
\[
D^\pi(\tau_1,\tau_2)=\frac{1}{m}\sum_{i=1}^m \|p_i(\tau_1)-p_i(\tau_2)\|_2.
\]
This is a pseudometric via embedding into $\mathbb R^{2m}$ and becomes a metric under essentially the same density and general-position assumptions. The key structural point is that TrajLoc replaces alignment-heavy trajectory comparison with a fixed-dimensional Euclidean embedding.

## 3. Landmark-distance TrajLoc: algorithms and empirical profile

Landmark selection admits two stated modes. Random landmarks may be chosen uniformly or by Poisson process in $\Omega$. Data-driven landmarks may be selected from a small random sample of all GPS fixes or from points of interest known to be semantically important. For a trajectory with $k$ linear segments and $|L|=m$, each coordinate $d(\tau,\ell_i)$ can be computed in $O(k)$ time by projecting $\ell_i$ onto each segment, so computing $\phi(\tau)$ takes $O(m\cdot k)$ time and $O(m)$ space. Once the embeddings are precomputed, evaluating $D(\tau_1,\tau_2)$ takes $O(m)$ time. Standard Lloyd’s algorithm can then be applied directly for k-means, with cost $O(I\cdot N\cdot K\cdot m)$ for $N$ trajectories, $K$ clusters, and $I$ iterations. The same embeddings can be stored in Euclidean ANN indices such as FLANN, Annoy, or KGraph, with typical build time $O(N\cdot m\cdot \log N)$ and sub-millisecond query time even for $N\sim 10^5$, $m\sim 50$ [1804.11284].

The reported empirical evaluation spans clustering, classification, sensitivity to landmark weighting, and ANN search. In Geolife user 155 with 42 trajectories, using $m=20$ random Beijing POIs and Lloyd’s algorithm with $K=2$ or $3$ yielded coherent "central city" versus "northern" clusters. In driver classification on Geolife, with 128 users and up to 200 trajectories each for a total of approximately 20k trajectories, 5-NN in $D^\pi$ yielded mean error $7.08\%$, comparable to the best prior $($LCSS, DTW $\sim 7.2\%)$ and better than Euclidean-critical-point distance $(8.11\%)$. When fed to a Gaussian-kernel SVM, $D^\pi$ and $D^{\parallel}$ both achieved approximately $7.3\%$ error versus approximately $8.5\%$ for the raw Euclidean-critical-point embedding.

On the UCI "GPS Trajectories" Bus vs Car task with 123 trajectories, 5-NN in $D^{\parallel}$ with $m=20$ gave $20.27\%$ error versus approximately $31\%$-$34\%$ for DTW, Hausdorff, Euclidean, and related baselines, and a Gaussian-SVM on the $\phi$-vectors reduced error to $16.6\%$. A landmark-sensitivity experiment used two synthetic classes of 30 trajectories each that differed only in whether they passed near a special POI $q_1$. A small uniform landmark set produced approximately $47\%$-$50\%$ error, while re-weighting $q_1$’s coordinate by $w_1=0.9$ with weights summing to $1$ reduced 5-NN error in $D^{\parallel}$ to $5.9\%$ and weighted Gaussian-SVM error to $1.6\%$. For ANN search on the full Geolife dataset with $N\sim 17{,}000$, building a KGraph index on $\phi(\tau)$ for $m\in\{12,20,28,36,44,52\}$ took $100$-$130\,\mathrm s$ and used approximately $1\,\mathrm{GB}$ memory, while each 1-NN query took $0.0003$-$0.0004\,\mathrm s$ at recall $0.99$. By contrast, state-of-the-art dedicated DFT/DTW indices were reported to require minutes on hundreds of cores for a single query.

These results establish the landmark-based TrajLoc as a Euclideanization strategy: trajectory analysis is reduced to vector analysis once the landmark embedding has been computed.

## 4. Trajectory-attention TrajLoc: localization inside video diffusion

The 2026 TrajLoc method addresses precise multi-object motion control in text-and-image-conditioned video diffusion. Its central operation is performed inside cross-attention layers. In a standard layer, visual queries $Q_{\rm vid}\in\mathbb R^{M\times d}$ attend to text keys $K_{\rm txt}\in\mathbb R^{L\times d}$ with
\[
A=\mathrm{softmax}\bigl(Q_{\rm vid}K_{\rm txt}^\top/\sqrt d\,\bigr)\in\mathbb R^{M\times L},
\]
and the output is
\[
O=A\,V_{\rm txt},\quad V_{\rm txt}\in\mathbb R^{L\times d}.
\]
For each object $i$ and frame $t$, TrajLoc constructs a 2D Gaussian heatmap over the latent grid,
\[
H_{i,t}(u,v)=\exp\!\Bigl(
-\tfrac{(u-x_{i,t})^2+(v-y_{i,t})^2}{2\,\sigma^2}
\Bigr),\qquad \sigma=30\text{ px (image space)}.
\]
These per-frame maps are bilinearly downsampled to the latent grid, flattened over $(t,u,v)$ to a vector $\mathbf h_i\in\mathbb R^M$, and normalized so that $\sum_{m=1}^M h_i[m]=1$ [2607.00861].

If $q_i$ is the column index in $A$ corresponding to the text token for object $i$, the method replaces that column with $\mathbf h_i$ and then renormalizes every row:
\[
A'[m,q_i]\leftarrow h_i[m],
\]
\[
A'[m,:]\leftarrow \frac{A'[m,:]}{\sum_{k=1}^L A'[m,k]}.
\]
The modified output is
\[
O'=A'V_{\rm txt},
\]
which is used in place of the standard cross-attention output. In architectures such as WaN-2.1, where the full matrix $A$ is explicitly built, this replacement is exact. In CogVideoX-5B, the full attention matrix is too large to materialize, approximately $30\,\mathrm{GB}$ per layer, so the method uses an efficient two-SDPA approximation that splits keys and values into supervised columns $\{q_i\}$ and the remaining set $\mathcal U$, computes two small SDPA calls, and mixes them according to the total heatmap mass $H[m]=\sum_i h_i[m]$. The reported practical effect is that the attention cost per layer is doubled while remaining within memory limits.

The method’s stated departure point is that existing approaches entangle multiple trajectories within a shared, dense conditioning signal, which makes object-level correspondence difficult to preserve in crowded scenes. TrajLoc instead enforces a strict, per object spatial constraint that isolates instances independently. The same per object token interface carries trajectory and depth through a learned embedding and preserves identity by encoding first frame appearance in place of an object token. This design is reported to scale to scenes with up to 20 simultaneously controlled objects and to remain effective under occlusions and path crossings.

## 5. Token conditioning, optimization, and reported results in diffusion TrajLoc

Trajectory and appearance are encoded as dedicated text tokens. For object $i$, the trajectory input is a sequence
\[
\tau_i=(x_{i,1},y_{i,1},d_{i,1},p_1),\ldots,(x_{i,T},y_{i,T},d_{i,T},p_T),
\]
where $d_{i,t}$ is per-frame depth and $p_t=(t-1)/(T-1)$ is a normalized time channel. The encoder $\mathrm{Enc}_{\rm traj}$ consists of three 1D convolution layers with stride $2$ and channels $4\to 64\to 128\to 256$, followed by BN and GELU, then flattening to a $32$-dimensional vector $z_i$, and finally a two-layer MLP $4096\times 512$ producing a $4096$-dimensional trajectory token $\langle \mathrm{traj}_i\rangle$. Pretraining freezes the I2V model’s text encoder and learns $\mathrm{Enc}_{\rm traj}$ with
\[
\mathcal L_{\rm traj}
=
\mathrm{MSE}(\hat\tau_i,\tau_i)+\lambda_{\rm vel}\,\mathrm{MSE}(\Delta\hat\tau_i,\Delta\tau_i),
\qquad
\Delta\tau_i^t=\tau_i^t-\tau_i^{t-1},
\qquad
\lambda_{\rm vel}=1.
\]
After $500\,\mathrm K$ steps and approximately $12.8\,\mathrm M$ parameters, the decoder is discarded and $\mathrm{Enc}_{\rm traj}$ is frozen.

The appearance encoder $\mathrm{Enc}_{\rm app}$ takes the first-frame VAE latent $V_0\in\mathbb R^{C\times H_{\rm lat}\times W_{\rm lat}}$ and object center $(x_i^1,y_i^1)$. It uses one stride-2 convolution $(16\to 64)$ and two stride-1 convolutions $(64\to 64)$ with BN and GELU, producing an $8$-channel feature map at $H_{\rm lat}\times W_{\rm lat}$. The $8$-dimensional feature sampled at $(x_i^1,y_i^1)$ is projected by a $4096\times 8$ linear layer to $e_{o_i}\in\mathbb R^{4096}$. This replaces the generic category token embedding such as "girl" or "ball" in the prompt. Prompt construction uses a template of the form: "Scene where $o_0$ moves [traj$_0$] and $o_1$ moves [traj$_1$] …". Each $[\mathrm{traj}_i]$ is replaced with the frozen output $\langle \mathrm{traj}_i\rangle$, and each category embedding $o_i$ is replaced with $e_{o_i}$.

Fine-tuning uses LoRA on all cross-attention layers of a pretrained I2V diffusion model, specifically CogVideoX-5B or WaN 2.1-14B, with rank $64$ and $\alpha=64$. Only the LoRA weights and the appearance encoder are trained; the original model weights and $\mathrm{Enc}_{\rm traj}$ remain frozen. The objective combines standard diffusion noise-prediction MSE over all pixels with the same noise-MSE restricted to small bounding boxes centered on each trajectory point:
\[
\mathcal L=(1-\alpha)\,\mathcal L_{\rm diff}+\alpha\,\mathcal L_{\rm bbox},
\qquad \alpha=0.5.
\]
Training uses AdamW and bf16. The reported schedules are $8{,}500$ steps for CogVideoX-5B with batch size $3\times 3$ H100s, approximately $57\,\mathrm h$, and $12{,}000$ steps for WaN 2.1-14B with batch size $2\times 2$ H100s, approximately $50\,\mathrm h$. Diffusion uses $50$ steps, classifier-free guidance $6.0$ for CogVideoX or $5.0$ for WaN, and $\sigma=30$ px [2607.00861].

Evaluation covers six datasets and $446$ total clips with up to $20$ simultaneous objects, using static-camera scenes of $49$ frames at $720\times 480$. The in-distribution synthetic sets are MoVi-Extended, Pool, Football, and MOTSynth; the out-of-distribution real-world sets are MOT17 and DAVIS 2017. Metrics are PSNR, LPIPS, FVD, and EPE, where EPE is the $\ell_2$ distance between ground-truth and tracked object centers in the generated video. Across both backbones and all six datasets, TrajLoc is reported to outperform four baselines—Tora, MagicMotion, ATI, and Wan-Move—by an average gain of $+4.3\,\mathrm{dB}$ PSNR with range $0.7$-$10\,\mathrm{dB}$ and an average $51\%$ reduction in EPE with range $11$-$96\%$. On MoVi, example numbers are: for CogVideoX, $29.77\,\mathrm{dB}$ versus $20.87$-$20.33\,\mathrm{dB}$ and EPE $0.53$ versus $1.50$-$2.01$; for WaN, $29.24\,\mathrm{dB}$ versus $19.73$-$20.33$ and EPE $0.57$ versus $2.01$-$2.18$.

Ablations identify attention localization as the most critical component. Removing attention localization on WaN-14B causes PSNR to drop by $6.7\,\mathrm{dB}$ on MoVi and EPE to increase by a factor of $3.3$. Removing trajectory tokens reduces PSNR by $1.4\,\mathrm{dB}$ and increases EPE by up to $27\%$. Removing the depth channel yields a similar drop in depth-sensitive scenes, and removing the appearance encoder causes moderate FVD degradation. For CogVideoX, the self-attention approximation ablation reports that the 2-SDPA replacement is stronger on crowded datasets such as MOTSynth and MOT17, whereas the additive correction variant is slightly stronger on far-out-of-distribution DAVIS. Qualitatively, the reported failure modes of baselines are missing objects under occlusion, drifting over time, hallucinating duplicates, and failing in crowded crossings.

## 6. Relation to adjacent trajectory methods

TrajLoc should be distinguished from trajectory methods that solve next-location prediction rather than similarity search or generative motion control. TTDM, the "Travel Time Difference Model," defines a user trajectory as
\[
T=\langle (l_1,t_1),(l_2,t_2),\ldots,(l_n,t_n)\rangle,
\]
uses the actual travel time from all passed locations to each candidate next location, and compares it with a shortest-path travel time on a time-slot-indexed road-network graph. For a candidate location $l$, the model aggregates
\[
\Delta t_a^{\mathrm{sum}}(T,l)=\sum_{i=1}^n t_{\mathrm{actual}}(l_i,l\mid T),\qquad
\Delta t_s^{\mathrm{sum}}(T,l)=\sum_{i=1}^n t_{\mathrm{shortest}}(l_i\to l;k),
\]
and forms the average excess
\[
\bar{\Delta t}(T,l)=\frac{\Delta t_a^{\mathrm{sum}}(T,l)-\Delta t_s^{\mathrm{sum}}(T,l)}{n}.
\]
A decreasing function such as $f(x)=\exp(-x)$ or $f(x)=1/x$ converts this to
\[
P_{\mathrm{TTDM}}(l\mid T)=\frac{f(\bar{\Delta t}(T,l))}{\sum_{l'\in C(l_n)} f(\bar{\Delta t}(T,l'))},
\]
which can be linearly interpolated with a first-order Markov model,
\[
P_{\mathrm{Joint}}(l\mid T)=\alpha P_{\mathrm{TTDM}}(l\mid T)+(1-\alpha)P_{\mathrm{MM}}(l\mid T).
\]
The reported top-1 accuracy results are $0.417$, $0.527$, and $0.584$ for MM, TTDM, and TTDM+MM on VPR, and $0.500$, $0.538$, and $0.578$ on Taxi, with best interpolation weight $\alpha\approx 0.2$-$0.3$ [2003.07781].

The conceptual distinction is straightforward. Landmark-based TrajLoc embeds a completed trajectory into $\mathbb R^m$ and studies metric geometry, Euclidean learning, and ANN search. Diffusion-based TrajLoc injects trajectory and appearance into cross-attention and prompt tokens to control future video frames. TTDM predicts a next location from a partial trajectory using travel-time differences and Markov interpolation. A common source of confusion is therefore terminological rather than methodological: the three methods all process trajectories, but they belong to different task families, use different representations, and are evaluated with different criteria.

Source: https://www.emergentmind.com/topics/trajloc