Skip to content

Commit f5cb516

Browse files
[skipci] [Doctest] added contrib regression (FractionalBias, FractionalAbsoluteError, CanberraMetric, GeometricMeanAbsoluteError) (pytorch#2323)
* added doctest for contrib regression metrics * removed Engine definition and variable name changes * added import of contrib.regression Co-authored-by: Sylvain Desroziers <[email protected]>
1 parent ecfff55 commit f5cb516

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def run(self):
339339
from ignite.handlers import *
340340
from ignite.metrics import *
341341
from ignite.utils import *
342+
from ignite.contrib.metrics.regression import *
342343
343344
from ignite.contrib.metrics import *
344345

ignite/contrib/metrics/regression/canberra_metric.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ class CanberraMetric(_BaseRegression):
3737
.. _`Botchkarev 2018`:
3838
https://arxiv.org/ftp/arxiv/papers/1809/1809.03006.pdf
3939
40+
.. testcode::
41+
42+
metric = CanberraMetric()
43+
metric.attach(default_evaluator, 'canberra')
44+
y_pred = torch.Tensor([[3.8], [9.9], [-5.4], [2.1]])
45+
y_true = y_pred * 1.5
46+
state = default_evaluator.run([[y_pred, y_true]])
47+
print(state.metrics['canberra'])
48+
49+
.. testoutput::
50+
51+
0.8000...
4052
.. versionchanged:: 0.4.3
4153
4254
- Fixed implementation: ``abs`` in denominator.

ignite/contrib/metrics/regression/fractional_absolute_error.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ class FractionalAbsoluteError(_BaseRegression):
3434
metric's device to be the same as your ``update`` arguments ensures the ``update`` method is
3535
non-blocking. By default, CPU.
3636
37+
.. testcode::
38+
39+
metric = FractionalAbsoluteError()
40+
metric.attach(default_evaluator, 'fractional_abs_error')
41+
y_pred = torch.Tensor([[3.8], [9.9], [-5.4], [2.1]])
42+
y_true = y_pred * 0.8
43+
state = default_evaluator.run([[y_pred, y_true]])
44+
print(state.metrics['fractional_abs_error'])
45+
46+
.. testoutput::
47+
48+
0.2222...
3749
.. versionchanged:: 0.4.5
3850
- Works with DDP.
3951
"""

ignite/contrib/metrics/regression/fractional_bias.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ class FractionalBias(_BaseRegression):
3434
metric's device to be the same as your ``update`` arguments ensures the ``update`` method is
3535
non-blocking. By default, CPU.
3636
37+
.. testcode::
38+
39+
metric = FractionalBias()
40+
metric.attach(default_evaluator, 'fractional_bias')
41+
y_pred = torch.Tensor([[3.8], [9.9], [5.4], [2.1]])
42+
y_true = y_pred * 1.5
43+
state = default_evaluator.run([[y_pred, y_true]])
44+
print(state.metrics['fractional_bias'])
45+
46+
.. testoutput::
47+
48+
0.4000...
49+
3750
.. versionchanged:: 0.4.5
3851
- Works with DDP.
3952
"""

ignite/contrib/metrics/regression/geometric_mean_absolute_error.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ class GeometricMeanAbsoluteError(_BaseRegression):
3434
metric's device to be the same as your ``update`` arguments ensures the ``update`` method is
3535
non-blocking. By default, CPU.
3636
37+
.. testcode::
38+
39+
metric = GeometricMeanAbsoluteError()
40+
metric.attach(default_evaluator, 'gmae')
41+
y_pred = torch.Tensor([[3.8], [9.9], [-5.4], [2.1]])
42+
y_true = y_pred * 1.5
43+
state = default_evaluator.run([[y_pred, y_true]])
44+
print(state.metrics['gmae'])
45+
46+
.. testoutput::
47+
48+
2.2723...
3749
.. versionchanged:: 0.4.5
3850
- Works with DDP.
3951
"""

0 commit comments

Comments
 (0)