예제 #1
0
 def test_estimate(self):
     print 'Testing parameter estimation for p-generalized normal distribution'
     sys.stdout.flush()
     for k in range(5):
         print '\t--> test case ' + str(k)
         dat = io.loadmat(self.matpath + '/TestPGeneralizedNormal' +
                          str(k) + '.mat',
                          struct_as_record=True)
         trueparam = {'s': 2 * dat['s'], 'p': dat['p'], 'n': dat['n']}
         p = Distributions.LpGeneralizedNormal({'n': dat['n']})
         dat = Data(dat['X'])
         p.estimate(dat)
         for ke in trueparam.keys():
             self.assertFalse( np.abs(trueparam[ke] -  p.param[ke]) > self.TolParam[ke],\
                 'Estimated parameter ' + ke + ' deviates by more than ' + str(self.TolParam[ke]) + '!')
예제 #2
0
 def test_loglik(self):
     print 'Testing log-likelihood of p-generalized normal distribution'
     print __file__
     sys.stdout.flush()
     for k in range(5):
         print '\t--> test case ' + str(k)
         dat = io.loadmat(self.matpath + '/TestPGeneralizedNormal' +
                          str(k) + '.mat',
                          struct_as_record=True)
         truell = dat['ll']
         p = Distributions.LpGeneralizedNormal({
             's': 2 * dat['s'],
             'p': dat['p'],
             'n': dat['n']
         })
         dat = Data(dat['X'])
         ll = p.loglik(dat)
         for i in range(ll.shape[0]):
             self.assertFalse( np.any(np.abs(ll[i]-np.squeeze(truell[0,i])) > self.Tol),\
                 'Log-likelihood for p-generalized normal deviates from test case')
예제 #3
0
    def test_RadialFactorization(self):
        print "Testing Radial Factorization ..."
        sys.stdout.flush()
        p = np.random.rand() + 1.0
        n = 5
        psource = Distributions.LpSphericallySymmetric({
            'n':
            n,
            'p':
            p,
            'rp':
            Distributions.Gamma({
                'u': 2.0 * np.random.rand() + 1.0,
                's': 5.0 * np.random.rand() + 1.0
            })
        })
        ptarget = Distributions.LpGeneralizedNormal({
            'n':
            n,
            'p':
            p,
            's': (special.gamma(1.0 / p) / special.gamma(3.0 / p))**(p / 2.0)
        })

        F = NonlinearTransformFactory.RadialFactorization(psource)

        dat = psource.sample(10000)
        ld = F.logDetJacobian(dat)
        ld = np.mean(np.abs(ld)) / dat.size(0) / np.log(2)

        all_source = psource.all(dat)
        all_target = ptarget.all(F * dat)

        tol = 1e-2
        prot = {}
        prot['message'] = 'Difference in logdet correted ALL >  ' + str(tol)
        prot["1/n/log(2) * <|det J|> "] = ld
        prot["ALL(TARGET)"] = all_target
        prot["ALL(SOURCE)"] = all_source
        prot[
            "ALL(TARGET) + 1/n/log(2) * <|det J|> - ALL(SOURCE)"] = all_target + ld - all_source