Skip to contents

Given a 3D embedding of graph vertices and a list of trajectories (each a vector of vertex indices), this function:

  1. resamples all trajectories to a common length (to make them comparable),

  2. computes a pointwise mean or median trajectory in 3D,

  3. 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. If NULL, GCV-based selection is used by smooth.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, uses round(stats::median(lengths(trajectories))).

grid.length

Integer number of points on which to evaluate the fitted splines for the returned smoothed curve. If NULL, uses target.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.spline objects (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")
} # }