paddlets.models.forecasting.dl.distributions.likelihood
- class Likelihood(mode: str = 'distribution')[source]
Bases:
ABCAbstract class for a distributional regression model.
- Parameters
mode (str) – The default value is “distribution” for probability distributional regression, for quantile regression, set “quantiles”.
- abstract output_to_params(model_output: Tensor) Tensor[source]
Rescale model output to distribution params, to be implemented in subclasses.
- Parameters
model_output (paddle.Tensor) – The output of model.
- Returns
The distribution parameters respect to subclass’ distribution.
- Return type
paddle.Tensor
- abstract params_to_distr(distr_params: Tensor) Distribution[source]
Construct a distribution class by distribution parameters, to be implemented in subclasses.
- Parameters
distr_params (paddle.Tensor) – The parameters of distribution.
- Returns
The distribution instance defined in paddle.
- Return type
Distribution
- sample(model_output: Tensor, num_samples: int = 1) Tensor[source]
Samples a prediction from the model output:
1> output to distribution parameters;
2> distribution parameters to distribution;
3> sample by distribution
- Parameters
model_output (paddle.Tensor) – The output of model.
num_samples (int) – The number of samples to be sampled.
- Returns
The samples of distribution.
- Return type
paddle.Tensor
- abstract get_mean(distr_params: Tensor) Tensor[source]
Compute mean by distribution params, to be implemented in subclasses.
- Parameters
distr_params – The params of distribution.
- Returns
The mean of distribution.
- Return type
paddle.Tensor
- abstract property num_params: int
Returns the number of parameters that define the probability distribution for one single target value.
- Returns
The number of parameters.
- Return type
int
- loss(distr_params: Tensor, target: Tensor) Tensor[source]
Compute NLL loss by predicted distrbution parameters and ground truth target.
This is the basic way to compute the NLL loss. It can be overwritten by likelihood for which paddle proposes a numerically better NLL loss.
- Parameters
distr_params – The parameters of distribution.
target – The ground truth of the sample.
- Returns
The loss computed by distribution parameters and ground truth.
- Return type
paddle.Tensor
- class GaussianLikelihood[source]
Bases:
LikelihoodUnivariate Gaussian distribution.
- output_to_params(model_output: Tensor) Tensor[source]
Use softplus to rescale sigma parameter as it should be positive.
- Parameters
model_output (paddle.Tensor) – The output of model.
- Returns
The Gaussian distribution parameters(mu and sigma).
- Return type
paddle.Tensor
- params_to_distr(distr_params: Tensor) Distribution[source]
Construct Normal instance by parameters: mu and sigma.
- Parameters
distr_params (paddle.Tensor) – Tensor of mu and sigma.
- Returns
The Gaussian instance defined in paddle.
- Return type
Distribution
- get_mean(distr_params: Tensor) Tensor[source]
Return mean of the distribution.
- Parameters
distr_params – Tensor of parameters mu and sigma.
- Returns
Mean of Gaussian distribution.
- Return type
paddle.Tensor
- property num_params: int
For Gaussian, the number of parameters is 2.
- Returns
The number of parameters of Gaussian distribution.
- Return type
int