deadleaves.distributions#
Classes#
Distribution data class |
|
Base class for custom distributions |
|
Distribution with density that follows the power law. |
|
Distribution with density that follows the cosine |
|
Distribution with cosine density and exponential peaks. |
|
Distribution class which return a constant value. |
|
Distribution to sample images uniformly from an image data set. |
Functions#
|
Return dictionary mapping keys to distribution classes and required parameters. |
Module Contents#
- class deadleaves.distributions.DistSpec#
Distribution data class
- cls: Type[torch.distributions.distribution.Distribution]#
Distribution class
- required: set[str]#
Parameters of the distribution
- deadleaves.distributions.get_dist_kw() dict[str, DistSpec]#
Return dictionary mapping keys to distribution classes and required parameters.
- class deadleaves.distributions.BaseDistribution(*args, **kwargs)#
Bases:
torch.distributions.distribution.DistributionBase class for custom distributions
- Raises:
- NotImplementedError:
- Class contains empty methods for
initialization (__init__)
probability density function (pdf)
inverse cumulative function (icdf)
- _batch_shape: torch.Size#
The shape over which parameters are batched.
- _validate_args()#
Validate input arguments.
- Raises:
ValueError
- abstractmethod pdf(x: torch.Tensor) torch.Tensor#
Returns the probability density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- cdf(x: torch.Tensor) torch.Tensor#
Returns (approximation of) the cumulative density function evaluated at x. If not implemented this method will compute the cdf as approximation via the pdf.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- abstractmethod icdf(p: torch.Tensor) torch.Tensor#
Returns the inverse cumulative density function evaluated at p.
- Args:
- p (torch.Tensor):
Probability value(s) to evaluate.
- ppf(p: torch.Tensor) torch.Tensor#
Returns the percent point function, i.e. approximation of inverse cumulative function evaluated at p.
- Args:
p (torch.Tensor): Probability value(s) to evaluate.
- sample(n=1) torch.Tensor#
Generates a sample from the distribution.
- Args:
n (int, optional): Number of samples. Defaults to 1.
- class deadleaves.distributions.PowerLaw(low: float, high: float, k: float = 3)#
Bases:
BaseDistributionDistribution with density that follows the power law.
- Args:
- low (float):
Minimal allowed value.
- high (float):
Maximal allowed value.
- k (float, optional):
Power law exponent. Defaults to 3.
- property arg_constraints: dict#
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- __str__() str#
Returns a readable string representation of the object.
- property support#
Returns a
Constraintobject representing this distribution’s support.
- pdf(x: torch.Tensor) torch.Tensor#
Returns the probability density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- cdf(x: torch.Tensor) torch.Tensor#
Returns (approximation of) the cumulative density function evaluated at x. If not implemented this method will compute the cdf as approximation via the pdf.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- icdf(p: torch.Tensor) torch.Tensor#
Returns the inverse cumulative density function evaluated at p.
- Args:
- p (torch.Tensor):
Probability value(s) to evaluate.
- class deadleaves.distributions.Cosine(amplitude: float = 0.5, frequency: int = 4)#
Bases:
BaseDistributionDistribution with density that follows the cosine
- Args:
- amplitude (float):
Amplitude of cosine. Value must be between 0.0 and 1.0. Defaults to 0.5.
- frequency (int):
Frequency of cosine. Defaults to 4, i.e. peaks at the cardinals.
- property support#
Returns a
Constraintobject representing this distribution’s support.
- property arg_constraints#
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- __str__() str#
Returns a readable string representation of the object.
- pdf(x: torch.Tensor) torch.Tensor#
Returns the probability density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- cdf(x: torch.Tensor) torch.Tensor#
Returns (approximation of) the cumulative density function evaluated at x. If not implemented this method will compute the cdf as approximation via the pdf.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- class deadleaves.distributions.ExpCosine(frequency: int = 4, exponential_constant: float = 3)#
Bases:
BaseDistributionDistribution with cosine density and exponential peaks.
- Args:
- frequency (int):
Frequency of cosine. Defaults to 4, i.e. peaks at the cardinals.
- exponential_constant (float):
Growth constant of exponential component. Larger values generate stronger peaks. Negative values invert the peaks. Defaults to 3.
- property support#
Returns a
Constraintobject representing this distribution’s support.
- property arg_constraints#
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- __str__() str#
Returns a readable string representation of the object.
- pdf(x: torch.Tensor) torch.Tensor#
Returns the probability density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- class deadleaves.distributions.Constant(value: float)#
Bases:
torch.distributions.distribution.DistributionDistribution class which return a constant value.
- Args:
- value (float):
Constant value to be return in each sampling.
- property arg_constraints#
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- property support#
Returns a
Constraintobject representing this distribution’s support.
- _batch_shape: torch.Size#
The shape over which parameters are batched.
- value: float#
- __str__() str#
Returns a readable string representation of the object.
- pdf(x: torch.Tensor) torch.Tensor#
Returns the probability density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- cdf(x: torch.Tensor) torch.Tensor#
Returns the cumulative density function evaluated at x.
- Args:
- x (torch.Tensor):
Value(s) to evaluate.
- icdf(p: torch.Tensor) torch.Tensor#
Returns the inverse cumulative density function evaluated at p.
- Args:
- p (torch.Tensor):
Probability value(s) to evaluate.
- sample(n=1) torch.Tensor#
Generates a sample from the distribution.
- Args:
n (int, optional): Number of samples. Defaults to 1.
- class deadleaves.distributions.Image(dir: pathlib.Path | str)#
Bases:
torch.distributions.distribution.DistributionDistribution to sample images uniformly from an image data set.
- Args:
- dir (Path | str):
Path to image data set directory.
- property arg_constraints#
Returns a dictionary from argument names to
Constraintobjects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
- property support#
Returns a
Constraintobject representing this distribution’s support.
- _batch_shape: torch.Size#
The shape over which parameters are batched.
- dir: pathlib.Path | str#
Path to image data set directory.
- files: list[pathlib.Path]#
List of image files in the directory.
- n_files: int#
Number of image files.
- __str__() str#
Returns a readable string representation of the object.
- sample(n=1) list[pathlib.Path]#
Draws a sample from the available images.
- Args:
n (int, optional): Number of samples. Defaults to 1.