index_ridge: Index a ridge curve, creating the Smoothed and Indexed...

View source: R/euler.R

index_ridgeR Documentation

Index a ridge curve, creating the Smoothed and Indexed Estimated Ridge (SIER)

Description

Indexing of an unordered collection of points defining the estimated density ridge curve. The indexing is done by a multidimensional scaling map to the real line, while the smoothing is done by local polynomial regression for polyspherical-on-scalar regression.

Usage

index_ridge(endpoints, X, d, l_index = 1000, f_index = 2,
  probs_scores = seq(0, 1, l = 101), verbose = FALSE, type_bwd = c("1se",
  "min")[1], p = 0, ...)

Arguments

endpoints

a matrix of size c(nx, sum(d) + r) with the end points of the ridge algorithm to be indexed.

X

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

d

vector of size r with dimensions.

l_index

length of the grid index used for finding projections. Defaults to 1e3.

f_index

factor with the range of the grid for finding ridge projections. Defaults to 2, which is twice the range of MDS indexes.

probs_scores

probabilities for indexing the ridge on the probs_scores-quantiles of the scores. Defaults to seq(0, 1, l = 101).

verbose

show diagnostic plots? Defaults to FALSE.

type_bwd

type of cross-validation bandwidth for Nadaraya–Watson, either "min" (minimizer of the cross-validation loss) or "1se" (the "one standard error rule", smoother). Defaults to "1se".

p

degree of local fit, either 0 or 1. Defaults to 0.

...

further arguments passed to bw_cv_kre_polysph.

Details

Indexing is designed to work with collection of ridge points that admit a linear ordering, so that mapping to the real line by multidimensional scaling is adequate. The indexing will not work properly if the ridge points define a closed curve.

Value

A list with the following fields:

scores_X

a vector of size n with the SIER scores for X.

projs_X

a matrix of size c(n, sum(d) + r) with the projections of X onto the SIER.

ord_X

a vector of size n with the ordering of X induced by the SIER scores.

scores_grid

a vector of size length(probs_scores) with score quantiles associated to the probabilities probs_scores.

ridge_grid

a vector of size length(probs_scores) with the SIER evaluated at scores_grid.

mds_index

a vector of size nx with the multidimensional scaling indexes.

ridge_fun

a function that parametrizes the SIER.

h

bandwidth used for the local polynomial regression.

probs_scores

object probs_scores.

Examples

## Test on (S^1)^2

# Sample
set.seed(132121)
r <- 2
d <- rep(1, r)
n <- 200
ind_dj <- comp_ind_dj(d = d)
Th <- matrix(runif(n = n * (r - 1), min = -pi / 2, max = pi / 2),
             nrow = n, ncol = r - 1)
Th[, r - 1] <- sort(Th[, r - 1])
Th <- cbind(Th, sdetorus::toPiInt(
  pi + Th[, r - 1] + runif(n = n, min = -pi / 4, max = pi / 4)))
X <- angles_to_torus(Th)
col_X_alp <- viridis::viridis(n, alpha = 0.25)
col_X <- viridis::viridis(n)

# Euler
h_rid <- rep(0.75, r)
h_eu <- h_rid^2
N <- 200
eps <- 1e-6
Y <- euler_ridge(x = X, X = X, d = d, h = h_rid, h_euler = h_eu,
                 N = N, eps = eps, keep_paths = TRUE)

# Visualization
i <- N # Between 1 and N
plot(rbind(torus_to_angles(Y$paths[, , 1])), col = col_X_alp, pch = 19,
     axes = FALSE, xlim = c(-pi, pi), ylim = c(-pi, pi),
     xlab = "", ylab = "")
points(rbind(torus_to_angles(Y$paths[, , i])), col = col_X, pch = 16,
       cex = 0.75)
sdetorus::torusAxis(1:2)
for (k in seq_len(nrow(Y$paths))) {

  xy <- torus_to_angles(t(Y$paths[k, , ]))
  sdetorus::linesTorus(x = xy[, 1], y = xy[, 2], col = col_X_alp[k])

}

# SIER
ind_rid <- index_ridge(endpoints = Y$ridge_y, X = X, d = d,
                       probs_scores = seq(0, 1, l = 50))
xy <- torus_to_angles(ind_rid$ridge_grid)
sdetorus::linesTorus(x = xy[, 1], y = xy[, 2], col = 2, lwd = 2)
points(torus_to_angles(ind_rid$ridge_fun(quantile(ind_rid$scores_grid))),
       col = 4, pch = 19)

# Scores
plot(density(ind_rid$scores_X), type = "l", xlab = "Scores",
     ylab = "Density", main = "Scores density")
for (i in 1:n) rug(ind_rid$scores_X[i], col = col_X[i])

polykde documentation built on April 16, 2025, 1:11 a.m.