tft_torch.loss module¶
Implements the relevant loss function for training the model as well as the metrics for evaluating and monitoring the model.
- tft_torch.loss.compute_quantile_loss_instance_wise(outputs: torch.Tensor, targets: torch.Tensor, desired_quantiles: torch.Tensor) → torch.Tensor¶
This function compute the quantile loss separately for each sample,time-step,quantile.
- Parameters
outputs (torch.Tensor) – The outputs of the model [num_samples x num_horizons x num_quantiles].
targets (torch.Tensor) – The observed target for each horizon [num_samples x num_horizons].
desired_quantiles (torch.Tensor) – A tensor representing the desired quantiles, of shape (num_quantiles,)
- Returns
losses_array – a tensor [num_samples x num_horizons x num_quantiles] containing the quantile loss for each sample,time-step and quantile.
- Return type
torch.Tensor
- tft_torch.loss.get_quantiles_loss_and_q_risk(outputs: torch.Tensor, targets: torch.Tensor, desired_quantiles: torch.Tensor) → Tuple[torch.Tensor, ...]¶
This function computes quantile loss and q-risk metric.
- Parameters
outputs (torch.Tensor) – The outputs of the model [num_samples x num_horizons x num_quantiles].
targets (torch.Tensor) – The observed target for each horizon [num_samples x num_horizons].
desired_quantiles (torch.Tensor) – a tensor representing the desired quantiles, of shape (num_quantiles,).
- Returns
q_loss (torch.Tensor) – a scalar representing the quantile loss across all samples,horizons and quantiles.
q_risk (torch.Tensor) – a tensor (shape=(num_quantiles,)) with q-risk metric for each quantile separately.
losses_array (torch.Tensor) – a tensor [num_samples x num_horizons x num_quantiles] containing the quantile loss for each sample,time-step and quantile.