Skip to contents

nmfkc.kernel.beta.nearest.med estimates the Gaussian kernel parameter \(\beta\) by computing the median of nearest-neighbor distances among covariates. This is useful for setting the scale parameter in kernel-based NMF with covariates.

Usage

nmfkc.kernel.beta.nearest.med(U, block_size = 1000)

Arguments

U

covariate matrix \(U(K,N)=(u_1,\dots,u_N)\), where each column corresponds to an individual. Each row may be normalized in advance.

block_size

number of samples to process at once. If \(N \le 1000\), it is automatically set to \(N\).

Value

A list with components:

beta

estimated kernel parameter \(\beta=1/(2 d_{med}^2)\)

beta_candidates

a numeric vector of candidate values obtained by multiplying the estimate \(\beta\) by powers of 10, i.e.\ \(\{\beta \cdot 10^{-2},\,\beta \cdot 10^{-1},\,\beta,\,\beta \cdot 10^{1}\}\)

dist_median

the median nearest-neighbor distance

block_size_used

actual block size used in computation

Details

The function computes all pairwise squared distances between columns of \(U\), excludes self-distances, and takes the median of the nearest-neighbor distances (after square root). This median is then used to set \(\beta\).