MCPcopy
hub / github.com/microsoft/qlib / numpy_normalised_quantile_loss

Function numpy_normalised_quantile_loss

examples/benchmarks/TFT/libs/utils.py:86–108  ·  view source on GitHub ↗

Computes normalised quantile loss for numpy arrays. Uses the q-Risk metric as defined in the "Training Procedure" section of the main TFT paper. Args: y: Targets y_pred: Predictions quantile: Quantile to use for loss calculations (between 0 & 1) Returns

(y, y_pred, quantile)

Source from the content-addressed store, hash-verified

84
85
86def numpy_normalised_quantile_loss(y, y_pred, quantile):
87 """Computes normalised quantile loss for numpy arrays.
88
89 Uses the q-Risk metric as defined in the "Training Procedure" section of the
90 main TFT paper.
91
92 Args:
93 y: Targets
94 y_pred: Predictions
95 quantile: Quantile to use for loss calculations (between 0 & 1)
96
97 Returns:
98 Float for normalised quantile loss.
99 """
100 prediction_underflow = y - y_pred
101 weighted_errors = quantile * np.maximum(prediction_underflow, 0.0) + (1.0 - quantile) * np.maximum(
102 -prediction_underflow, 0.0
103 )
104
105 quantile_loss = weighted_errors.mean()
106 normaliser = y.abs().mean()
107
108 return 2 * quantile_loss / normaliser
109
110
111# OS related functions.

Callers

nothing calls this directly

Calls 2

meanMethod · 0.45
absMethod · 0.45

Tested by

no test coverage detected