Esempio n. 1
0
    def test_normal(self):
        from jittor import init
        n = 10000
        r = 0.155
        a = init.gauss([n], "float32", 1, 3)
        data = a.data

        assert (np.abs((data < (1 - 3)).mean() - r) < 0.1)
        assert (np.abs((data < (1)).mean() - 0.5) < 0.1)
        assert (np.abs((data < (1 + 3)).mean() - (1 - r)) < 0.1)

        np_res = np.random.normal(1, 0.1, (100, 100))
        jt_res = jt.normal(1., 0.1, (100, 100))
        assert (np.abs(np_res.mean() - jt_res.data.mean()) < 0.1)
        assert (np.abs(np_res.std() - jt_res.data.std()) < 0.1)

        np_res = torch.normal(torch.arange(1., 10000.), 1)
        jt_res = jt.normal(jt.arange(1, 10000), 1)
        assert (np.abs(np_res.mean() - jt_res.data.mean()) < 0.1)
        assert (np.abs(np_res.std() - jt_res.data.std()) < 1)

        np_res = np.random.randn(100, 100)
        jt_res = jt.randn(100, 100)
        assert (np.abs(np_res.mean() - jt_res.data.mean()) < 0.1)
        assert (np.abs(np_res.std() - jt_res.data.std()) < 0.1)

        np_res = np.random.rand(100, 100)
        jt_res = jt.rand(100, 100)
        assert (np.abs(np_res.mean() - jt_res.data.mean()) < 0.1)
        assert (np.abs(np_res.std() - jt_res.data.std()) < 0.1)
Esempio n. 2
0
 def sample(self, sample_shape=None):
     return jt.normal(jt.array(self.mu),
                      jt.array(self.sigma),
                      size=sample_shape)
Esempio n. 3
0
def normal(var, mean, std):
    if var is not None:
        var.assign(jt.normal(mean, std, size=var.size))
Esempio n. 4
0
 def sample(self, sample_shape):
     return jt.normal(self.mu, self.sigma, sample_shape)