Computes the gradient \(\mathsf{D}\hat{f}(\boldsymbol{x};\boldsymbol{h})\) and Hessian matrix \(\mathsf{H}\hat{f}(\boldsymbol{x};\boldsymbol{h})\) of the kernel density estimator \(\hat{f}(\boldsymbol{x};\boldsymbol{h})\) on the polysphere \(\mathcal{S}^{d_1} \times \cdots \times \mathcal{S}^{d_r}\).
grad_hess_kde_polysph(x, X, d, h, weights = as.numeric(c()),
projected = TRUE, proj_alt = TRUE, norm_grad_hess = FALSE,
log = FALSE, wrt_unif = FALSE, normalized = TRUE, norm_x = FALSE,
norm_X = FALSE, kernel = 1L, kernel_type = 1L, k = 10)A list with the following fields:
a column vector of size c(nx, 1) with the kernel
density estimator evaluated at x.
a matrix of size c(nx, sum(d) + r) with the gradient of
the kernel density estimator evaluated at x.
an array of size c(nx, sum(d) + r, sum(d) + r) with the
Hessian matrix of the kernel density estimator evaluated at x.
a matrix of size c(nx, sum(d) + r) with the evaluation
points.
a matrix of size c(n, sum(d) + r) with the sample.
vector of size r with dimensions.
vector of size r with bandwidths.
weights for each observation. If provided, a vector of size
n with the weights for multiplying each kernel. If not provided,
set internally to rep(1 / n, n), which gives the standard estimator.
compute the projected gradient and Hessian that
accounts for the radial projection? Defaults to TRUE.
alternative projection. Defaults to TRUE.
normalize the gradient and Hessian dividing by the
kernel density estimator? Defaults to FALSE.
compute the logarithm of the density? Defaults to FALSE.
flag to return a density with respect to the uniform
measure. If FALSE (default), the density is with respect to the
Lebesgue measure.
flag to compute the normalizing constant of the kernel
and include it in the kernel density estimator. Defaults to TRUE.
ensure a normalization of the data? Defaults to
FALSE.
kernel employed: 1 for von Mises--Fisher (default);
2 for Epanechnikov; 3 for softplus.
type of kernel employed: 1 for product kernel
(default); 2 for spherically symmetric kernel.
softplus kernel parameter. Defaults to 10.0.
# Simple check on (S^1)^2
n <- 3
d <- c(1, 1)
mu <- c(0, 1, 0, 1)
kappa <- c(5, 5)
h <- c(0.2, 0.2)
X <- r_vmf_polysph(n = n, d = d, mu = mu, kappa = kappa)
grh <- grad_hess_kde_polysph(x = X, X = X, d = d, h = h)
str(grh)
grh
Run the code above in your browser using DataLab