tdhook.latent.dimension_estimation.twonn#

Classes#

TwoNnDimensionEstimator

Intrinsic dimension estimation via the Two NN algorithm [21].

Functions#

_twonn(data, eps)

Compute Two NN intrinsic dimension. data: (N, D). Returns (d, x, y).

Module Contents#

class tdhook.latent.dimension_estimation.twonn.TwoNnDimensionEstimator(in_key='data', out_key='dimension', return_xy=False, eps=1e-05)[source]#

Bases: tensordict.nn.TensorDictModuleBase

Intrinsic dimension estimation via the Two NN algorithm [21].

Reads a data tensor from the input TensorDict. Expects (N, D) or (…, N, D). For (…, N, D), flattens all leading dims, computes one dimension per dataset, stacks and reshapes to preserve the original batch shape (excluding last two dims).

Parameters:
  • in_key (str)

  • out_key (str)

  • return_xy (bool)

  • eps (float)

in_key = 'data'[source]#
out_key = 'dimension'[source]#
return_xy = False[source]#
eps = 1e-05[source]#
in_keys[source]#
out_keys[source]#
forward(td)[source]#
Parameters:

td (tensordict.TensorDict)

Return type:

tensordict.TensorDict

__repr__()[source]#
tdhook.latent.dimension_estimation.twonn._twonn(data, eps)[source]#

Compute Two NN intrinsic dimension. data: (N, D). Returns (d, x, y).

Distances <= eps are treated as duplicates (excluded from nearest-neighbor selection).

Parameters:
  • data (torch.Tensor)

  • eps (float)

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor]