Example #1
0
def test_zero_div():
    mae = MeanAbsoluteError()
    with pytest.raises(
            NotComputableError,
            match=
            r"MeanAbsoluteError must have at least one example before it can be computed"
    ):
        mae.compute()
def test_compute():
    mae = MeanAbsoluteError()

    y_pred = torch.Tensor([[2.0], [-2.0]])
    y = torch.zeros(2)
    mae.update((y_pred, y))
    assert mae.compute() == 2.0

    mae.reset()
    y_pred = torch.Tensor([[3.0], [-3.0]])
    y = torch.zeros(2)
    mae.update((y_pred, y))
    assert mae.compute() == 3.0
Example #3
0
def test_zero_div():
    mae = MeanAbsoluteError()
    with pytest.raises(NotComputableError):
        mae.compute()