Distributions¶
Custom distribution implementations and utilities for distributional regression. These extend PyTorch distributions with specialized functionality for DRN models.
Histogram Distributions¶
Histogram¶
drn.distributions.histogram.Histogram
¶
Bases: Distribution
This class represents a histogram distribution. Basically, the distribution is a composite of uniform distributions over the bins.
Attributes¶
mean
property
¶
Calculate the mean of the distribution. Returns: the mean (shape: (batch_shape,))
Functions¶
__init__(cutpoints, prob_masses)
¶
Args: regions: the bin boundaries (shape: (K+1,)) prob_masses: the probability for landing in each regions (shape: (n, K))
cdf(value)
¶
Calculate the cumulative distribution function for the given values.
cdf_at_cutpoints()
¶
Calculate the cumulative distribution function at each cutpoint.
cdf_same_eval(value)
¶
Calculate the cumulative distribution function for the same value across the batch.
icdf(p, l=None, u=None, max_iter=1000, tolerance=1e-07)
¶
Calculate the inverse CDF (quantiles) using shared binary search implementation.
log_prob(value)
¶
Calculate the log probability densities of values
.
prob(value)
¶
Calculate the probability densities of values
.
quantiles(percentiles, l=None, u=None, max_iter=1000, tolerance=1e-07)
¶
Calculate the quantile values for the given percentiles (cumulative probabilities * 100).
Extended Histogram¶
drn.distributions.extended_histogram.ExtendedHistogram
¶
Bases: Distribution
This class represents a splicing of a supplied distribution with a histogram distribution. The histogram part is defined by K regions with boundaries -infty < c_0 < c_1 < ... < c_K < infty. The final density before c_0 & after c_K is the same as the original distribution. The density between c_k & c_{k+1} is defined by the histogram distribution.
Attributes¶
mean
property
¶
Calculate the mean of the distribution. Returns: the mean (shape: (batch_shape,))
Functions¶
__init__(baseline, cutpoints, pmf, baseline_probs=None)
¶
Args: baseline: the original distribution cutpoints: the bin boundaries (shape: (K+1,)) pmf: the refined (cond.) probability for landing in each region (shape: (n, K)) baseline_probs: the baseline's probability for landing in each region (shape: (n, K))
baseline_prob_between_cutpoints()
¶
Calculate the baseline probability vector
cdf(value)
¶
Calculate the cumulative distribution function for the given values.
cdf_at_cutpoints()
¶
Calculate the cumulative distribution function at each cutpoint.
icdf(p, l=None, u=None, max_iter=1000, tolerance=1e-07)
¶
Calculate the inverse CDF (quantiles) using shared binary search implementation.
prob(value)
¶
Calculate the probability densities of values
.
quantiles(percentiles, l=None, u=None, max_iter=1000, tolerance=1e-07)
¶
Calculate the quantile values for the given percentiles (cumulative probabilities * 100).
real_adjustments()
¶
Calculate the real adjustment factors a_k's
Specialized Distributions¶
Inverse Gaussian¶
drn.distributions.inverse_gaussian.InverseGaussian
¶
Bases: Distribution
Parameter Estimation¶
Gamma Parameter Conversion¶
drn.distributions.estimation.gamma_convert_parameters(mu, phi)
¶
Our models predict the mean of the gamma distribution, but we need the shape and rate parameters. This function converts the mean and dispersion parameter into the shape and rate parameters. Args: mu: the predicted means for the gamma distributions (shape: (n,)) phi: the dispersion parameter Returns: alpha: the shape parameter (shape: (n,)) beta: the rate parameter (shape: (n,))
Dispersion Estimation¶
drn.distributions.estimation.estimate_dispersion(distribution, mu, y, p)
¶
Estimate the dispersion parameter for different distributions.
Parameters: distribution (str): The type of distribution ("gamma", "gaussian", "inversegaussian", "lognormal"). mu (torch.Tensor): The predicted mean values. y (torch.Tensor): The observed target values. p (int): The number of model parameters.
Returns: torch.Tensor: The estimated dispersion parameter.