Fit Smooth-Spline Curves to the Mean/Median 3D Trajectory
Source:R/gfc_flow.R
fit.trajectory.smooth.splines.RdGiven a 3D embedding of graph vertices and a list of trajectories (each a vector of vertex indices), this function:
resamples all trajectories to a common length (to make them comparable),
computes a pointwise mean or median trajectory in 3D,
fits a smooth spline to each coordinate as a function of trajectory index.
The spline fit for coordinate i uses: $$fit_i = stats::smooth.spline(x = seq_along(y_i), y = y_i, df = df)$$ where \(y_i\) is the i-th coordinate of the mean/median trajectory.
Usage
fit.trajectory.smooth.splines(
embed.3d,
trajectories,
df = NULL,
center = c("mean", "median"),
target.length = NULL,
grid.length = NULL
)Arguments
- embed.3d
Numeric matrix/data.frame with exactly 3 columns; row r gives the 3D coordinates for vertex r (1-based indexing).
- trajectories
List of integer vectors; each vector is a trajectory of vertex indices (1-based). Trajectories may have different lengths.
- df
Degrees of freedom passed to
stats::smooth.spline. IfNULL, GCV-based selection is used bysmooth.spline.- center
One of
"mean"or"median"; how to compute the representative (pointwise) trajectory after resampling.- target.length
Integer common length used after resampling. If
NULL, usesround(stats::median(lengths(trajectories))).- grid.length
Integer number of points on which to evaluate the fitted splines for the returned smoothed curve. If
NULL, usestarget.length.
Value
A list with class "gfc_mean_trajectory_spline" containing:
- center
Centering method used: "mean" or "median".
- df
Degrees of freedom used (input df; may be NULL).
- target.length
Common resampling length used.
- t
Integer vector
1:target.length.- t.grid
Numeric vector for spline evaluation (length
grid.length).- traj.center
Matrix (target.length x 3): pointwise mean/median trajectory.
- fits
List of three
smooth.splineobjects (x/y/z).- traj.smooth
Matrix (grid.length x 3): spline-smoothed trajectory.
- resampled.trajs
List of matrices; each is (target.length x 3) resampled coordinates.
Examples
if (FALSE) { # \dontrun{
res <- fit.trajectory.smooth.splines(embed.3d, trajectories, df = NULL, center = "median")
plot(res$traj.smooth[,1], res$traj.smooth[,2], type = "l")
} # }