tdhook.latent.dimension_estimation.local_knn#
Classes#
Local intrinsic dimension estimation via k-NN distances [20]. |
Functions#
|
Resolve k to an integer. If 'auto', use int(n**0.5), clamped to valid range. |
|
Compute per-point local dimension. data: (N, D). Returns (N,) dimension estimates. |
Module Contents#
- tdhook.latent.dimension_estimation.local_knn._resolve_k(k, n)[source]#
Resolve k to an integer. If ‘auto’, use int(n**0.5), clamped to valid range.
- Parameters:
k (Union[int, Literal['auto']])
n (int)
- Return type:
int
- class tdhook.latent.dimension_estimation.local_knn.LocalKnnDimensionEstimator(k='auto', in_key='data', out_key='dimension', eps=1e-05)[source]#
Bases:
tensordict.nn.TensorDictModuleBaseLocal intrinsic dimension estimation via k-NN distances [20].
For each point x, d(x) = ln(2) / ln(R2k/Rk), where Rk and R2k are distances to the k-th and 2k-th nearest neighbors respectively.
Reads a data tensor from the input TensorDict. Expects (N, D) or (…, N, D). Outputs per-point dimension estimates of shape (…, N).
- Parameters:
k (Union[int, Literal['auto']])
in_key (str)
out_key (str)
eps (float)