def test_estimate_is_near_truth(self, nTrial=100):
   vopt = GSO.beta2v(self.truebeta)
   objfunc = lambda v: GSO.neglogp(v, self.G, self.logPiMat, self.alpha0, self.gamma)
   success = 0
   print vopt, '*optimal*'
   for trial in range(nTrial):
     v = GSO.estimate_v(self.G, self.logPiMat, self.alpha0, self.gamma, method='tnc')
     if np.all( np.abs(v - vopt) < .01 ):
       success += 1
     elif objfunc(v) < objfunc(vopt):
       success += 1
     else:
       print v
   print "%d/%d suceeded." % (success, nTrial)
   assert success == nTrial
  def test_truth_is_minimum_of_objfunc(self, nTrial=100):
    vopt = GSO.beta2v(self.truebeta)
    objfunc = lambda v: GSO.neglogp(v, self.G, self.logPiMat, self.alpha0, self.gamma)
    success = 0
    fopt = objfunc(vopt)
    print vopt, fopt, '**'

    for trial in range(nTrial):
      v = vopt + 0.01 * self.PRNG.rand(self.K)
      v = np.minimum(v, 1.0 - 1e-8)
      fv = objfunc(v)
      if fopt < fv:
        success += 1
      else:
        print v, fv
    assert success > 0.98 * nTrial
Ejemplo n.º 3
0
    def test_truth_is_minimum_of_objfunc(self, nTrial=100):
        vopt = GSO.beta2v(self.truebeta)
        objfunc = lambda v: GSO.neglogp(v, self.G, self.logPiMat, self.alpha0,
                                        self.gamma)
        success = 0
        fopt = objfunc(vopt)
        print vopt, fopt, '**'

        for trial in range(nTrial):
            v = vopt + 0.01 * self.PRNG.rand(self.K)
            v = np.minimum(v, 1.0 - 1e-8)
            fv = objfunc(v)
            if fopt < fv:
                success += 1
            else:
                print v, fv
        assert success > 0.98 * nTrial
Ejemplo n.º 4
0
 def test_estimate_is_near_truth(self, nTrial=100):
     vopt = GSO.beta2v(self.truebeta)
     objfunc = lambda v: GSO.neglogp(v, self.G, self.logPiMat, self.alpha0,
                                     self.gamma)
     success = 0
     print vopt, '*optimal*'
     for trial in range(nTrial):
         v = GSO.estimate_v(self.G,
                            self.logPiMat,
                            self.alpha0,
                            self.gamma,
                            method='tnc')
         if np.all(np.abs(v - vopt) < .01):
             success += 1
         elif objfunc(v) < objfunc(vopt):
             success += 1
         else:
             print v
     print "%d/%d suceeded." % (success, nTrial)
     assert success == nTrial