4#ifndef LIBQE_TRAJECTORY_DISTANCE_HPP
5#define LIBQE_TRAJECTORY_DISTANCE_HPP
25 arma::mat J(N, N, arma::fill::zeros);
26 for (
int k = 1; k < N; ++k) {
27 double b =
static_cast<double>(k) / std::sqrt(4.0 * k * k - 1.0);
34 arma::vec w = 2.0 * arma::square(evecs.row(0).t());
55 const arma::vec& coeffs_ax,
56 const arma::vec& coeffs_ay,
57 const arma::vec& coeffs_bx,
58 const arma::vec& coeffs_by,
62 if (t_end <= t_start)
return 0.0;
65 double mid = 0.5 * (t_start + t_end);
66 double half_len = 0.5 * (t_end - t_start);
69 for (
size_t i = 0; i < rule.nodes.n_elem; ++i) {
70 double t_eval = mid + half_len * rule.nodes[i];
77 double dist = std::sqrt(dx * dx + dy * dy);
79 total += rule.weights[i] * dist;
82 return half_len * total;
87 const arma::vec& coeffs_fol_x,
88 const arma::vec& coeffs_fol_y,
89 const arma::vec& coeffs_ldr_x,
90 const arma::vec& coeffs_ldr_y,
93 if (lag < 0.0 || lag >= 0.999)
return 0.0;
97 double mid = 0.5 * (t_start + t_end);
98 double half_len = 0.5 * (t_end - t_start);
101 for (
size_t i = 0; i < rule.nodes.n_elem; ++i) {
102 double t_fol = mid + half_len * rule.nodes[i];
103 double t_ldr = t_fol - lag;
110 double dx = x_fol - x_ldr;
111 double dy = y_fol - y_ldr;
112 double dist = std::sqrt(dx * dx + dy * dy);
114 total += rule.weights[i] * dist;
117 double integral = half_len * total;
118 double interval = 1.0 - lag;
119 return (interval > 1e-6) ? (integral / interval) : 0.0;
124 const std::vector<arma::vec>& all_coeffs_x,
125 const std::vector<arma::vec>& all_coeffs_y
127 size_t K = all_coeffs_x.size();
128 arma::mat D(K, K, arma::fill::zeros);
130 for (
size_t i = 0; i < K; ++i) {
131 for (
size_t j = i + 1; j < K; ++j) {
133 all_coeffs_x[i], all_coeffs_y[i],
134 all_coeffs_x[j], all_coeffs_y[j]
Thin LAPACK-free implementations of SVD, QR, and symmetric eigendecomposition for use in WASM / no-LA...
void eig_sym(arma::vec &eigval, arma::mat &eigvec, const arma::mat &S)
Eigendecomposition of a real symmetric matrix.
Definition linalg_fallback.hpp:129
Definition adjacency.hpp:16
double lagged_curve_distance(const arma::vec &coeffs_fol_x, const arma::vec &coeffs_fol_y, const arma::vec &coeffs_ldr_x, const arma::vec &coeffs_ldr_y, double lag=0.0)
Compute lagged curve distance: 1/(1-lag) * integral_{lag}^1 ||F_follower(t) - F_leader(t - lag)|| dt.
Definition trajectory_distance.hpp:86
double integrated_curve_distance(const arma::vec &coeffs_ax, const arma::vec &coeffs_ay, const arma::vec &coeffs_bx, const arma::vec &coeffs_by, double t_start=0.0, double t_end=1.0)
Compute integrated Euclidean distance between two 2D parametric polynomial curves.
Definition trajectory_distance.hpp:54
const GaussLegendreRule & get_gl_rule_32()
Obtain exact 32-point Gauss-Legendre quadrature nodes and weights on [-1, 1] via Golub-Welsch.
Definition trajectory_distance.hpp:22
arma::mat pairwise_trajectory_distance_matrix(const std::vector< arma::vec > &all_coeffs_x, const std::vector< arma::vec > &all_coeffs_y)
Compute pairwise integrated distance matrix across K polynomial trajectory curves.
Definition trajectory_distance.hpp:123
double eval_poly_scalar(const arma::vec &coeffs, double t)
Evaluate a 1D polynomial sum(c_k * t^k) at a single time t.
Definition trajectory.hpp:221
Definition trajectory_distance.hpp:16
arma::vec weights
Definition trajectory_distance.hpp:18
arma::vec nodes
Definition trajectory_distance.hpp:17
Parametric trajectory curve fitting, LOOCV-2D degree selection, and differential geometry (velocity,...