Esempio n. 1
0
    def test_lognormal_mul_div_pow(self):
        a = random.expovariate(1 / 10)

        # Multiplication by constant
        Ymul = self.Y * a
        self.assertEqual(Ymul.mu, self.Y.mu + np.log(a))
        self.assertEqual(np.log(Ymul.sigma), np.log(self.Y.sigma))

        # Division by Constant
        Ydiv = self.Y / a
        self.assertEqual(Ydiv.mu, self.Y.mu - np.log(a))
        self.assertEqual(np.log(Ydiv.sigma), np.log(self.Y.sigma))

        # Multiplication by another LogNormal
        Y2 = rvpy.LogNormal(-10 + 20 * random.random(), 10 * random.random())
        Z = self.Y * Y2
        self.assertIsInstance(Z, rvpy.LogNormal)
        self.assertEqual(Z.mu, self.Y.mu + Y2.mu)
        self.assertEqual(Z.sigma, self.Y.sigma + Y2.sigma)

        # Inversion
        Yinv = 1 / self.Y
        self.assertIsInstance(Yinv, rvpy.LogNormal)
        self.assertEqual(Yinv.mu, -self.Y.mu)
        self.assertEqual(Yinv.sigma, self.Y.sigma)
Esempio n. 2
0
    def test_pow(self):
        X = rvpy.StandardNormal()
        Y = rvpy.pow(X, 2)

        self.assertIsInstance(X, rvpy.StandardNormal)
        self.assertIsInstance(Y, rvpy.ChiSq)

        Z = rvpy.LogNormal()
        W = rvpy.pow(Z, .321)

        self.assertIsInstance(Z, rvpy.LogNormal)
        self.assertIsInstance(W, rvpy.LogNormal)
Esempio n. 3
0
 def test_lognormal_conversion(self):
     with self.assertRaises(AssertionError):
         rvpy.LogNormal(0, 0)
     with self.assertRaises(AssertionError):
         rvpy.LogNormal(0, -1)
     with self.assertRaises(TypeError):
         rvpy.LogNormal() + rvpy.LogNormal()
     with self.assertRaises(TypeError):
         rvpy.LogNormal()**0
     with self.assertRaises(TypeError):
         rvpy.LogNormal() * 0
Esempio n. 4
0
    def test_log(self):
        X = rvpy.LogNormal()
        Y = rvpy.log(X)

        self.assertIsInstance(X, rvpy.LogNormal)
        self.assertIsInstance(Y, rvpy.Normal)
Esempio n. 5
0
    def test_sqrt(self):
        X = rvpy.LogNormal()
        Y = rvpy.sqrt(X)

        self.assertIsInstance(X, rvpy.LogNormal)
        self.assertIsInstance(Y, rvpy.LogNormal)
Esempio n. 6
0
 def setUp(self):
     self.X = rvpy.LogNormal()
     self.Y = rvpy.LogNormal(-10 + 20 * random.random(),
                             10 * random.random())