TorchSparseLogCategoricalDistribution¶
- class probly.representation.distribution.torch_sparse_log_categorical.TorchSparseLogCategoricalDistribution(group_ids: Tensor, entry_logits: Tensor)[source]¶
Bases:
TorchAxisProtected[Any],CategoricalDistribution[Tensor]Sparse categorical distribution with grouped log-weights.
Shape:
batch_shape. The final axis ofgroup_idsandentry_logitsstores sparse support entries. Entries with the same group id are combined by summing their exponentiated logits when converting to a dense categorical distribution.- clone(*, memory_format: memory_format = torch.preserve_format) Self[source]¶
Return a copy of the array.
- cpu(memory_format: memory_format = torch.preserve_format) Self[source]¶
Move the array to the CPU.
- cuda(device: device | str | None = None, non_blocking: bool = False, memory_format: memory_format = torch.preserve_format) Self[source]¶
Move the array to the GPU.
- entry_logits: torch.Tensor¶
- gather(dim: int, index: Tensor) Self[source]¶
Return a copy with gathered protected values along a batch dimension.
- group_ids: torch.Tensor¶
- permitted_functions = {}¶
- permute(*dims: Size | int | tuple[int] | list[int]) Self[source]¶
Return a permuted version of the array.
- protected_values(func: Callable | None = None) dict[str, TorchProtectedValue] | None[source]¶
Return all protected field values as-is.
Optionally takes the torch function that triggered the call for context. This can be used to conditionally modify the returned values or prevent them from being accessed.
- sample(num_samples: int = 1, rng: Generator | None = None) TorchSample[Tensor][source]¶
Sample from the equivalent dense categorical distribution.
- size(dim: int | None = None) int | Size[source]¶
Return the size of the array along the given dimension.
- to_dense(num_classes: int | None = None) TorchProbabilityCategoricalDistribution[source]¶
Convert sparse grouped logits to a dense categorical distribution.
- Parameters:
num_classes – Optional dense class count. Defaults to
max(group_ids) + 1.- Returns:
Dense categorical distribution with zero mass for absent groups.
- to_device(device: Literal['cpu'], /, *, stream: int | Any | None = None) Self[source]¶
Move the array to a device.
- type = 'categorical'¶
- uniform_logits() TorchSparseLogCategoricalDistribution[source]¶
Return a copy with identical groups and uniform sparse logits.
- Returns:
A sparse categorical distribution with shared
group_idsand zero logits.