r_kde_polysph: Sample from polyspherical kernel density estimator

View source: R/samplers.R

r_kde_polysphR Documentation

Sample from polyspherical kernel density estimator

Description

Simulates from the distribution defined by a polyspherical kernel density estimator on \mathbb{S}^{d_1} \times \ldots \times \mathbb{S}^{d_r}.

Usage

r_kde_polysph(
  n,
  X,
  d,
  h,
  kernel = 1,
  kernel_type = 1,
  k = 10,
  intrinsic = FALSE,
  norm_X = FALSE
)

Arguments

n

sample size.

X

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

d

vector of size r with dimensions.

h

vector of size r with bandwidths.

kernel

kernel employed: 1 for von Mises–Fisher (default); 2 for Epanechnikov; 3 for softplus.

kernel_type

type of kernel employed: 1 for product kernel (default); 2 for spherically symmetric kernel.

k

softplus kernel parameter. Defaults to 10.0.

intrinsic

use the intrinsic distance, instead of the extrinsic-chordal distance, in the kernel? Defaults to FALSE.

norm_X

ensure a normalization of the data?

Details

The function uses r_kern_polysph to sample from the considered kernel.

Value

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

Examples

if (requireNamespace("sdetorus", quietly = TRUE)) {
  # Simulated data on (S^1)^2
  n <- 50
  samp <- r_path_s1r(n = n, r = 2, k = c(1, 2), angles = TRUE)
  plot(samp, xlim = c(-pi, pi), ylim = c(-pi, pi), col = rainbow(n),
       axes = FALSE, xlab = "", ylab = "", pch = 16, cex = 0.75)
  points(torus_to_angles(r_kde_polysph(n = 10 * n, X = angles_to_torus(samp),
                                       d = c(1, 1), h = c(0.1, 0.1))),
         col = "black", pch = 16, cex = 0.2)
  sdetorus::torusAxis()
}

if (requireNamespace("scatterplot3d", quietly = TRUE)) {
  # Simulated data on S^2
  n <- 50
  samp <- r_path_s2r(n = n, r = 1, sigma = 0.1, kappa = 5,
                     spiral = TRUE)[, , 1]
  sc3d <- scatterplot3d::scatterplot3d(
    samp, xlim = c(-1, 1), ylim = c(-1, 1), zlim = c(-1, 1),
    xlab = "", ylab = "", zlab = "", color = rainbow(n), pch = 16
  )
  xyz <- r_kde_polysph(n = 10 * n, X = samp, d = 2, h = 0.1)
  sc3d$points3d(xyz[, 1], xyz[, 2], xyz[, 3], col = "black", pch = 16,
                cex = 0.2)
}

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