kernel: Kernels on the sphere and their derivatives

kernelR Documentation

Kernels on the sphere and their derivatives

Description

An isotropic kernel L on \mathcal{S}^d and its normalizing constant are such that \int_{\mathcal{S}^d} c(h, d, L) L\left(\frac{1 - \boldsymbol{x}'\boldsymbol{y}}{h^2}\right) \,\mathrm{d}\boldsymbol{x} = 1 (extrinsic-chordal distance) or \int_{\mathcal{S}^d} c(h, d, L) L\left(\frac{\cos^{-1}(\boldsymbol{x}'\boldsymbol{y})^2}{2h^2}\right) \,\mathrm{d}\boldsymbol{x} = 1 (intrinsic distance).

Usage

L(t, kernel = "1", squared = FALSE, deriv = 0, k = 10,
  inc_sfp = TRUE)

c_kern(h, d, kernel = "1", kernel_type = "1", k = 10, log = FALSE,
  inc_sfp = TRUE, intrinsic = FALSE)

grad_L(x, y, h, kernel = 1, k = 10)

hess_L(x, y, h, kernel = 1, k = 10)

Arguments

t

vector with the evaluation points.

kernel

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

squared

square the kernel? Only for deriv = 0. Defaults to FALSE.

deriv

kernel derivative. Must be 0, 1, or 2. Defaults to 0.

k

softplus kernel parameter. Defaults to 10.0.

inc_sfp

include softplus(k) in the constant? Defaults to TRUE.

h

vector of size r with bandwidths.

d

vector of size r with dimensions.

kernel_type

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

log

compute the logarithm of the constant? Defaults to FALSE.

intrinsic

consider the intrinsic distance? Defaults to FALSE.

x

a matrix of size c(nx, sum(d) + r) with the evaluation points.

y

center of the kernel, a vector of size sum(d) + r.

Details

The gradient and Hessian are computed for the functions \boldsymbol{x} \mapsto L\left(\frac{1 - \boldsymbol{x}'\boldsymbol{y}}{h^2}\right).

Value

  • L: a vector with the kernel evaluated at t.

  • grad_L: a vector with the gradient evaluated at x.

  • hess_L: a matrix with the Hessian evaluated at x.

Examples

# Constants in terms of h
h_grid <- seq(0.01, 4, l = 100)
r <- 2
d <- 2
dr <- rep(d, r)
c_vmf <- sapply(h_grid, function(hi)
  log(c_kern(h = rep(hi, r), d = dr, kernel = 1, kernel_type = 2)))
c_epa <- sapply(h_grid, function(hi)
  log(c_kern(h = rep(hi, r), d = dr, kernel = 2, kernel_type = 2)))
c_sfp <- sapply(h_grid, function(hi)
  log(c_kern(h = rep(hi, r), d = dr, kernel = 3, k = 1, kernel_type = 2)))
plot(h_grid, c_epa, type = "l", ylab = "Constant", xlab = "h", col = 2)
lines(h_grid, c_sfp, col = 3)
lines(h_grid, c_vmf, col = 1)
abline(v = sqrt(2), lty = 2, col = 2)

# Kernel and its derivatives
h <- 0.5
x <- c(sqrt(2), -sqrt(2), 0) / 2
y <- c(-sqrt(2), sqrt(3), sqrt(3)) / 3
L(t = (1 - sum(x * y)) / h^2)
grad_L(x = x, y = y, h = h)
hess_L(x = x, y = y, h = h)

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