gwinferno.numpyro_distributions.Powerlaw#
- class Powerlaw(alpha, minimum=0.0, maximum=1.0, low=0.0, high=1.0, validate_args=None)[source]#
Bases:
Distribution
Methods
cdf
(value)The cumulative distribution function of this distribution.
entropy
()Returns the entropy of the distribution.
enumerate_support
([expand])Returns an array with shape len(support) x batch_shape containing all values in the support.
expand
(batch_shape)Returns a new
ExpandedDistribution
instance with batch dimensions expanded to batch_shape.expand_by
(sample_shape)Expands a distribution by adding
sample_shape
to the left side of itsbatch_shape
.gather_pytree_aux_fields
()gather_pytree_data_fields
()get_args
()Get arguments of the distribution.
icdf
(q)The inverse cumulative distribution function of this distribution.
infer_shapes
(*args, **kwargs)Infers
batch_shape
andevent_shape
given shapes of args to__init__()
.log_prob
(*args, **kwargs)Evaluates the log probability density for a batch of samples given by value.
mask
(mask)Masks a distribution by a boolean or boolean-valued array that is broadcastable to the distributions
Distribution.batch_shape
.rsample
(key[, sample_shape])sample
(key[, sample_shape])Returns a sample from the distribution having shape given by sample_shape + batch_shape + event_shape.
sample_with_intermediates
(key[, sample_shape])Same as
sample
except that any intermediate computations are returned (useful for TransformedDistribution).set_default_validate_args
(value)shape
([sample_shape])The tensor shape of samples from this distribution.
to_event
([reinterpreted_batch_ndims])Interpret the rightmost reinterpreted_batch_ndims batch dimensions as dependent event dimensions.
tree_flatten
()tree_unflatten
(aux_data, params)validate_args
([strict])Validate the arguments of the distribution.
Attributes
arg_constraints
Returns the shape over which the distribution parameters are batched.
Returns the shape of a single sample from the distribution without batching.
has_enumerate_support
has_rsample
is_discrete
Mean of the distribution.
pytree_aux_fields
pytree_data_fields
reparametrized_params
support
Variance of the distribution.
- __call__(*args, **kwargs)#
Call self as a function.
- classmethod __init_subclass__(**kwargs)#
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __repr__()#
Return repr(self).
- Return type:
str
- property batch_shape: tuple[int, ...]#
Returns the shape over which the distribution parameters are batched.
- Returns:
batch shape of the distribution.
- Return type:
tuple
- cdf(value)[source]#
The cumulative distribution function of this distribution.
- Parameters:
value – samples from this distribution.
- Returns:
output of the cumulative distribution function evaluated at value.
- entropy()#
Returns the entropy of the distribution.
- enumerate_support(expand=True)#
Returns an array with shape len(support) x batch_shape containing all values in the support.
- property event_dim: int#
- Returns:
Number of dimensions of individual events.
- Return type:
int
- property event_shape: tuple[int, ...]#
Returns the shape of a single sample from the distribution without batching.
- Returns:
event shape of the distribution.
- Return type:
tuple
- expand(batch_shape)#
Returns a new
ExpandedDistribution
instance with batch dimensions expanded to batch_shape.- Parameters:
batch_shape (tuple) – batch shape to expand to.
- Returns:
an instance of ExpandedDistribution.
- Return type:
ExpandedDistribution
- expand_by(sample_shape)#
Expands a distribution by adding
sample_shape
to the left side of itsbatch_shape
. To expand internal dims ofself.batch_shape
from 1 to something larger, useexpand()
instead.- Parameters:
sample_shape (tuple) – The size of the iid batch to be drawn from the distribution.
- Returns:
An expanded version of this distribution.
- Return type:
ExpandedDistribution
- get_args()#
Get arguments of the distribution.
- Return type:
dict
- icdf(q)[source]#
The inverse cumulative distribution function of this distribution.
- Parameters:
q – quantile values, should belong to [0, 1].
- Returns:
the samples whose cdf values equals to q.
- classmethod infer_shapes(*args, **kwargs)#
Infers
batch_shape
andevent_shape
given shapes of args to__init__()
.Note
This assumes distribution shape depends only on the shapes of tensor inputs, not in the data contained in those inputs.
- Parameters:
*args – Positional args replacing each input arg with a tuple representing the sizes of each tensor input.
**kwargs – Keywords mapping name of input arg to tuple representing the sizes of each tensor input.
- Returns:
A pair
(batch_shape, event_shape)
of the shapes of a distribution that would be created with input args of the given shapes.- Return type:
tuple
- log_prob(*args, **kwargs)#
Evaluates the log probability density for a batch of samples given by value.
- Parameters:
value – A batch of samples from the distribution.
- Returns:
an array with shape value.shape[:-self.event_shape]
- Return type:
numpy.ndarray
- mask(mask)#
Masks a distribution by a boolean or boolean-valued array that is broadcastable to the distributions
Distribution.batch_shape
.- Parameters:
mask (bool or jnp.ndarray) – A boolean or boolean valued array (True includes a site, False excludes a site).
- Returns:
A masked copy of this distribution.
- Return type:
MaskedDistribution
Example:
- property mean: Array | ndarray | bool_ | number | bool | int | float | complex#
Mean of the distribution.
- sample(key, sample_shape=())[source]#
Returns a sample from the distribution having shape given by sample_shape + batch_shape + event_shape. Note that when sample_shape is non-empty, leading dimensions (of size sample_shape) of the returned sample will be filled with iid draws from the distribution instance.
- Parameters:
key (jax.random.PRNGKey) – the rng_key key to be used for the distribution.
sample_shape (tuple) – the sample shape for the distribution.
- Returns:
an array of shape sample_shape + batch_shape + event_shape
- Return type:
numpy.ndarray
- sample_with_intermediates(key, sample_shape=())#
Same as
sample
except that any intermediate computations are returned (useful for TransformedDistribution).- Parameters:
key (jax.random.PRNGKey) – the rng_key key to be used for the distribution.
sample_shape (tuple) – the sample shape for the distribution.
- Returns:
an array of shape sample_shape + batch_shape + event_shape
- Return type:
numpy.ndarray
- shape(sample_shape=())#
The tensor shape of samples from this distribution.
Samples are of shape:
d.shape(sample_shape) == sample_shape + d.batch_shape + d.event_shape
- Parameters:
sample_shape (tuple) – the size of the iid batch to be drawn from the distribution.
- Returns:
shape of samples.
- Return type:
tuple
- to_event(reinterpreted_batch_ndims=None)#
Interpret the rightmost reinterpreted_batch_ndims batch dimensions as dependent event dimensions.
- Parameters:
reinterpreted_batch_ndims – Number of rightmost batch dims to interpret as event dims.
- Returns:
An instance of Independent distribution.
- Return type:
numpyro.distributions.distribution.Independent
- validate_args(strict=True)#
Validate the arguments of the distribution.
- Parameters:
strict (
bool
) – Require strict validation, raising an error if the function is called inside jitted code.- Return type:
None
- property variance: Array | ndarray | bool_ | number | bool | int | float | complex#
Variance of the distribution.