probly.representation.distribution.torch_categorical.TorchCategoricalDistributionSample¶
- class probly.representation.distribution.torch_categorical.TorchCategoricalDistributionSample(tensor: D, sample_dim: int, weights: torch.Tensor | None = None)[source]¶
Bases:
CategoricalDistributionSample[TorchCategoricalDistribution],TorchSample[TorchCategoricalDistribution]Sample type for empirical second-order categorical distributions.
- 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.
- classmethod from_iterable(samples: Iterable[ArrayLike[D]], weights: Iterable[float] | None = None, sample_dim: SampleAxis | None = None, sample_axis: SampleAxis | None = 'auto', dtype: torch.dtype | None = None) Self[source]¶
Create an TorchSample from a sequence of samples.
- Parameters:
samples – The predictions to create the sample from.
weights – Optional weights for the samples.
sample_dim – The dimension along which samples are organized.
sample_axis – Alias for sample_dim for compatibility.
dtype – Desired data type of the array.
- Returns:
The created TorchSample.
- classmethod from_sample(sample: Sample[T], **kwargs: Unpack[SampleParams]) Self[source]¶
Create a new Sample from an existing Sample.
- Parameters:
sample – The sample to create the new sample from.
kwargs – Parameters for sample creation.
- Returns:
The created Sample.
- move_sample_axis(new_sample_axis: int) TorchSample[source]¶
Alias for
TorchSample.move_sample_dim().
- move_sample_dim(new_sample_dim: int) TorchSample[source]¶
Return a new TorchSample with the sample dimension moved to new_sample_dim.
- Parameters:
new_sample_dim – The new sample dimension.
- Returns:
A new TorchSample with the sample dimension moved.
- permute(*dims: Size | int | tuple[int] | list[int]) Self[source]¶
Return a permuted version of the array.
- sample_space[source]¶
alias of
TorchCategoricalDistribution
- property samples: D¶
Return an iterator over the samples.
- size(dim: int | None = None) int | Size[source]¶
The total number of elements in the underlying array.
- tensor: D¶
- to(*args: Any, **kwargs: Any) Self[source]¶
Moves and/or casts the underlying tensor. See torch.Tensor.to for details.
- Parameters:
*args – Positional arguments to pass to torch.Tensor.to.
**kwargs – Keyword arguments to pass to torch.Tensor.to.
- Returns:
A copy of the TorchSample.