clean_euler_ridge: Clean ridge points coming from spurious fits

View source: R/euler.R

clean_euler_ridgeR Documentation

Clean ridge points coming from spurious fits

Description

Remove points from the ridge that are spurious. The cleaning is done by removing end points in the Euler algorithm that did not converge, do not have a negative second eigenvalue, or are in low-density regions.

Usage

clean_euler_ridge(e, X, p_out = NULL)

Arguments

e

outcome from euler_ridge or parallel_euler_ridge.

X

a matrix of size c(n, sum(d) + r) with the sample.

p_out

proportion of outliers to remove. Defaults to NULL (no cleaning).

Value

A list with the same structure as that returned by euler_ridge, but with the spurious points removed. An extra logical vector removed of length nx indicates which input points were dropped.

References

García-Portugués, E. and Meilán-Vila, A. (2023). Hippocampus shape analysis via skeletal models and kernel smoothing. In Larriba, Y. (Ed.), Statistical Methods at the Forefront of Biomedical Advances, pp. 63–82. Springer, Cham. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-3-031-32729-2_4")}

Examples


if (requireNamespace("scatterplot3d", quietly = TRUE)) {

  ## Test on S^2 with some spurious end points

  # Sample
  r <- 1
  d <- 2
  n <- 50
  ind_dj <- comp_ind_dj(d = d)
  X <- r_path_s2r(n = n, r = r, spiral = FALSE, Theta = cbind(c(1, 0, 0)),
                  sigma = 0.2)[, , 1]
  col_X <- rep(gray(0), n)
  col_X_alp <- rep(gray(0, alpha = 0.25), n)

  # Euler
  h_rid <- 0.5
  h_eu <- h_rid^2
  N <- 30
  eps <- 1e-6
  X0 <- r_unif_polysph(n = n, d = d)
  Y <- euler_ridge(x = X0, X = X, d = d, h = h_rid, h_euler = h_eu,
                   N = N, eps = eps, keep_paths = TRUE)
  Y_removed <- clean_euler_ridge(e = Y, X = X)$removed
  col_X[Y_removed] <- 2
  col_X_alp[Y_removed] <- 2

  # Visualization
  i <- N # Between 1 and N
  sc3 <- scatterplot3d::scatterplot3d(Y$paths[, , 1], color = col_X_alp,
                                      pch = 19, xlim = c(-1, 1),
                                      ylim = c(-1, 1), zlim = c(-1, 1),
                                      xlab = "x", ylab = "y", zlab = "z")
  sc3$points3d(rbind(Y$paths[, , i]), col = col_X, pch = 16, cex = 0.75)
  for (k in seq_len(nrow(Y$paths))) {

    sc3$points3d(t(Y$paths[k, , ]), col = col_X_alp[k], type = "l")

  }

}


polykde documentation built on Nov. 13, 2026, 1:08 a.m.