axtreme.distributions.icdf¶
Helper for finding inverse cdf for function that do not have an icdf method.
Functions
|
Calculated the inverse CDF for each distribution in a batch. |
|
Calculates inverse CDF values for distributions which do not have a icdf function. |
- axtreme.distributions.icdf.icdf(dist: Distribution, q: Tensor, max_acceptable_error: float, opt_bounds: Tensor) Tensor ¶
Calculated the inverse CDF for each distribution in a batch.
This method is useful when the distrbution does not have an icdf method. In this case the CDF can be run repeatidly until we find the x where cdf(`x) == quantile`. We use optimisation to make this search effecient.
- Parameters:
dist – (*batch_shape,) mixture distribution producing events of event_shape samples
q – quantile to find the inverse cdf of. Must be boardcastable up to (*batch_shape,). Must not have more dimensions than *batch_shape (only 1 q can be passed to each of the distributions in the batch.)
opt_bounds – (2,`*batch`). The lower and lower x bounds withing which the q can be found. If unknown, set to a very large range. opt_bounds.shape[1:] must be broadcastable to dist.batch_shape.
max_acceptable_error – return values must be within icdf(q +/- max_acceptable_error)
- Returns:
Tensor of shape (dist.batch_shape) of the icdf(x) results.
- axtreme.distributions.icdf.icdf_1d(dist: Distribution, quantile: float, max_acceptable_error: float, bounds: tuple[float, float]) Tensor ¶
Calculates inverse CDF values for distributions which do not have a icdf function.
Some distributions do not have an inverse CDF function. In this case the CDF can be run repeatidly until we find the x where cdf(`x) == quantile`. We use optimisation to make this search effecient. This function only supports distribution with 1d input and output.
- Parameters:
dist –
This expects a Distribution like object. The specific methods and attributes required are:
methods: cdf(), and potentially log_prob() depending on the optimiser used.
Attributes: None.
quantile – The quantile for which to find the corresponding x value.
max_acceptable_error – return values must be within icdf(q +/- max_acceptable_error)
bounds – The bounds to serach for the root in
- Returns:
A tensor of shape (1,) of the x value corresponding to the quantile.
- Details:
- There are a number of way numerical issues can effect this results:
Case 1: Function output (dist.cdf) is not precise enough to support max_acceptable_error.
Case 2: Function internals are not precise enough to support max_acceptable_error (e.g they introduce numeric error).
Case 3: Optimiation input (x), is not accurate enough to support step sizes need to achieve max_acceptable_error.
Case 4: The optimisation process does not find a suitable result.
Case 5: The output datatype truncation is not precise enough, failing max_acceptable_error after truncation.