dist_polysph: Polyspherical distance

View source: R/RcppExports.R

dist_polysphR Documentation

Polyspherical distance

Description

Computation of the distance between points \boldsymbol{x} and \boldsymbol{y} on the polysphere \mathcal{S}^{d_1} \times \cdots \times \mathcal{S}^{d_r}:

\sqrt{\sum_{j=1}^r d_{\mathcal{S}^{d_j}}(\boldsymbol{x}_j, \boldsymbol{y}_j)^2},

where d_{\mathcal{S}^{d_j}}(\boldsymbol{x}_j, \boldsymbol{y}_j)= \cos^{-1}(\boldsymbol{x}_j' \boldsymbol{y}_j).

Usage

dist_polysph(x, y, ind_dj, norm_x = FALSE, norm_y = FALSE, std = TRUE)

dist_polysph_cross(x, y, ind_dj, norm_x = FALSE, norm_y = FALSE,
  std = TRUE)

dist_polysph_matrix(x, ind_dj, norm_x = FALSE, norm_y = FALSE,
  std = TRUE)

Arguments

x

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

y

either a matrix of size c(m, sum(d) + r) or a vector of length sum(d) + r.

ind_dj

0-based index separating the blocks of spheres that is computed with comp_ind_dj.

norm_x, norm_y

ensure a normalization of the data? Default to FALSE.

std

standardize distance to [0,1]? Uses that the maximum distance is \sqrt{r}\pi. Defaults to TRUE.

Value

  • dist_polysph: a vector of size n with the distances between x and y.

  • dist_polysph_matrix: a matrix of size c(n, n) with the pairwise distances of x.

  • dist_polysph_cross: a matrix of distances of size c(n, m) with the cross distances between x and y.

Examples

# Example on S^2 x S^3 x S^1
d <- c(2, 3, 1)
ind_dj <- comp_ind_dj(d)
n <- 3
x <- r_unif_polysph(n = n, d = d)
y <- r_unif_polysph(n = n, d = d)

# Distances of x to y
dist_polysph(x = x, y = y, ind_dj = ind_dj, std = FALSE)
dist_polysph(x = x, y = y[1, , drop = FALSE], ind_dj = ind_dj, std = FALSE)

# Pairwise distance matrix of x
dist_polysph_matrix(x = x, ind_dj = ind_dj, std = FALSE)

# Cross distances between x and y
dist_polysph_cross(x = x, y = y, ind_dj = ind_dj, std = FALSE)

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