Shortcuts

Tweedie Deviance Score

Module Interface

class torchmetrics.TweedieDevianceScore(power=0.0, compute_on_step=None, **kwargs)[source]

Computes the Tweedie Deviance Score between targets and predictions:

deviance\_score(\hat{y},y) =
\begin{cases}
(\hat{y} - y)^2, & \text{for }power=0\\
2 * (y * log(\frac{y}{\hat{y}}) + \hat{y} - y),  & \text{for }power=1\\
2 * (log(\frac{\hat{y}}{y}) + \frac{y}{\hat{y}} - 1),  & \text{for }power=2\\
2 * (\frac{(max(y,0))^{2}}{(1 - power)(2 - power)} - \frac{y(\hat{y})^{1 - power}}{1 - power} + \frac{(\hat{y})
    ^{2 - power}}{2 - power}), & \text{otherwise}
\end{cases}

where y is a tensor of targets values, and \hat{y} is a tensor of predictions.

Forward accepts

  • preds (float tensor): (N,...)

  • targets (float tensor): (N,...)

Parameters
  • power (float) –

    • power < 0 : Extreme stable distribution. (Requires: preds > 0.)

    • power = 0 : Normal distribution. (Requires: targets and preds can be any real numbers.)

    • power = 1 : Poisson distribution. (Requires: targets >= 0 and y_pred > 0.)

    • 1 < p < 2 : Compound Poisson distribution. (Requires: targets >= 0 and preds > 0.)

    • power = 2 : Gamma distribution. (Requires: targets > 0 and preds > 0.)

    • power = 3 : Inverse Gaussian distribution. (Requires: targets > 0 and preds > 0.)

    • otherwise : Positive stable distribution. (Requires: targets > 0 and preds > 0.)

  • compute_on_step (Optional[bool]) –

    Forward only calls update() and returns None if this is set to False.

    Deprecated since version v0.8: Argument has no use anymore and will be removed v0.9.

  • kwargs (Dict[str, Any]) – Additional keyword arguments, see Advanced metric settings for more info.

Example

>>> from torchmetrics import TweedieDevianceScore
>>> targets = torch.tensor([1.0, 2.0, 3.0, 4.0])
>>> preds = torch.tensor([4.0, 3.0, 2.0, 1.0])
>>> deviance_score = TweedieDevianceScore(power=2)
>>> deviance_score(preds, targets)
tensor(1.2083)

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Override this method to compute the final metric value from state variables synchronized across the distributed backend.

Return type

Tensor

update(preds, targets)[source]

Update metric states with predictions and targets.

Parameters
  • preds (Tensor) – Predicted tensor with shape (N,d)

  • targets (Tensor) – Ground truth tensor with shape (N,d)

Return type

None

Functional Interface

torchmetrics.functional.tweedie_deviance_score(preds, targets, power=0.0)[source]

Computes the Tweedie Deviance Score between targets and predictions:

deviance\_score(\hat{y},y) =
\begin{cases}
(\hat{y} - y)^2, & \text{for }power=0\\
2 * (y * log(\frac{y}{\hat{y}}) + \hat{y} - y),  & \text{for }power=1\\
2 * (log(\frac{\hat{y}}{y}) + \frac{y}{\hat{y}} - 1),  & \text{for }power=2\\
2 * (\frac{(max(y,0))^{2}}{(1 - power)(2 - power)} - \frac{y(\hat{y})^{1 - power}}{1 - power} + \frac{(\hat{y})
    ^{2 - power}}{2 - power}), & \text{otherwise}
\end{cases}

where y is a tensor of targets values, and \hat{y} is a tensor of predictions.

Parameters
  • preds (Tensor) – Predicted tensor with shape (N,...)

  • targets (Tensor) – Ground truth tensor with shape (N,...)

  • power (float) –

    • power < 0 : Extreme stable distribution. (Requires: preds > 0.)

    • power = 0 : Normal distribution. (Requires: targets and preds can be any real numbers.)

    • power = 1 : Poisson distribution. (Requires: targets >= 0 and y_pred > 0.)

    • 1 < p < 2 : Compound Poisson distribution. (Requires: targets >= 0 and preds > 0.)

    • power = 2 : Gamma distribution. (Requires: targets > 0 and preds > 0.)

    • power = 3 : Inverse Gaussian distribution. (Requires: targets > 0 and preds > 0.)

    • otherwise : Positive stable distribution. (Requires: targets > 0 and preds > 0.)

Example

>>> from torchmetrics.functional import tweedie_deviance_score
>>> targets = torch.tensor([1.0, 2.0, 3.0, 4.0])
>>> preds = torch.tensor([4.0, 3.0, 2.0, 1.0])
>>> tweedie_deviance_score(preds, targets, power=2)
tensor(1.2083)
Return type

Tensor

Read the Docs v: v0.8.1
Versions
latest
stable
v0.8.1
v0.8.0
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.2
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.1
v0.4.0
v0.3.2
v0.3.1
v0.3.0
v0.2.0
v0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.