Ejemplo n.º 1
0
    def test_fit(self):
        torch.manual_seed(42)
        m = OCE(lambda x: 1 - torch.exp(-x))

        self.train_oce(m)

        x = torch.randn(10000)

        result = m(x)
        expect = torch.log(EntropicLoss()(x))

        assert torch.isclose(result, expect, rtol=1e-02)
Ejemplo n.º 2
0
 def test_repr(self):
     loss = EntropicLoss()
     assert repr(loss) == "EntropicLoss()"
     loss = EntropicLoss(a=10.0)
     assert repr(loss) == "EntropicLoss(a=10.0)"
Ejemplo n.º 3
0
 def test_shape(self):
     loss = EntropicLoss()
     self.assert_shape(loss)
Ejemplo n.º 4
0
 def test_error_a(self):
     with pytest.raises(ValueError):
         EntropicLoss(0)
     with pytest.raises(ValueError):
         EntropicLoss(-1)
Ejemplo n.º 5
0
 def test_value(self, n_paths, a):
     value = 1.0
     loss = EntropicLoss(a)
     result = loss(torch.full((n_paths, ), value))
     expect = torch.exp(-a * torch.tensor(value))
     assert torch.isclose(result, expect)
Ejemplo n.º 6
0
 def test_cash(self, n_paths, a):
     loss = EntropicLoss(a)
     self.assert_cash(loss, torch.randn(n_paths))
Ejemplo n.º 7
0
 def test_convex(self, n_paths, risk, a):
     loss = EntropicLoss(risk)
     x1 = torch.randn(n_paths)
     x2 = torch.randn(n_paths)
     self.assert_convex(loss, x1, x2, a)
Ejemplo n.º 8
0
 def test_nonincreasing(self, n_paths, risk, a):
     loss = EntropicLoss(risk)
     self.assert_nonincreasing(loss, torch.randn(n_paths), a)