Distributions

This module provides probability distribution implementations for concept-based models.

Summary

Distribution Classes

Delta

Delta (Dirac delta) distribution - a deterministic distribution.

Class Documentation

class Delta(value: List[float] | Tensor, validate_args=None)[source]

Bases: Distribution

Delta (Dirac delta) distribution - a deterministic distribution.

This distribution always returns the same fixed value when sampled, making it useful for representing deterministic variables in Probabilistic Models.

The Delta distribution has zero variance and assigns all probability mass to a single point.

arg_constraints

Empty dict - no constraints on parameters.

Type:

Dict

support

Support of the distribution (None for Delta).

Type:

Optional[torch.Tensor]

has_rsample

Whether reparameterized sampling is supported (False).

Type:

bool

Parameters:
  • value – The deterministic value (list or tensor).

  • validate_args – Whether to validate arguments (default: None).

Properties:

mean: Returns the deterministic value.

Examples

>>> import torch
>>> from torch_concepts.distributions import Delta
>>> dist = Delta(torch.tensor([1.0, 2.0, 3.0]))
>>> sample = dist.sample()
>>> print(sample)  # tensor([1., 2., 3.])
>>> print(dist.mean)  # tensor([1., 2., 3.])
arg_constraints: Dict[str, Any] = {}
support: Tensor | None = None
has_rsample = False
property mean

Return the mean of the distribution.

For a Delta distribution, the mean is the deterministic value itself.

Returns:

The deterministic value.

Return type:

torch.Tensor

sample(sample_shape=())[source]

Generate a sample from the distribution.

For a Delta distribution, always returns the deterministic value.

Parameters:

sample_shape – Shape of the sample (default: empty tuple).

Returns:

The deterministic value.

Return type:

torch.Tensor

rsample(sample_shape=())[source]

Generate a reparameterized sample from the distribution.

For a Delta distribution, this is the same as sample().

Parameters:

sample_shape – Shape of the sample (default: empty tuple).

Returns:

The deterministic value.

Return type:

torch.Tensor

log_prob(value)[source]

Calculate the log probability of a value.

For a Delta distribution, technically the log probability is -inf for any value except the deterministic value, and +inf at the deterministic value. This implementation returns 0.

Parameters:

value – Value to compute log probability for.

Returns:

Log probability (zeros).

Return type:

torch.Tensor