def test_truth_is_minimum_of_objfunc(self, nTrial=2):
    vopt = HBO.beta2v(self.truebeta)
    objfunc = lambda v: HBO.objectiveFunc(v, self.alpha, self.gamma, self.G, self.sumLogPi)
    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
    def test_truth_is_minimum_of_objfunc(self, nTrial=2):
        vopt = HBO.beta2v(self.truebeta)
        objfunc = lambda v: HBO.objectiveFunc(v, self.alpha, self.gamma, self.
                                              G, self.sumLogPi)
        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
  def test_estimate_is_near_truth(self, nTrial=2):
    vopt = HBO.beta2v(self.truebeta)
    objfunc = lambda v: HBO.objectiveFunc(v, self.alpha, self.gamma, self.G, self.sumLogPi)
    success = 0
    print vopt, '*optimal*'

    for trial in range(nTrial):
      initV = np.random.rand(self.K)
      v = HBO.estimate_v(self.gamma, self.alpha, self.G, self.K, self.sumLogPi, initV )
      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_estimate_is_near_truth(self, nTrial=2):
        vopt = HBO.beta2v(self.truebeta)
        objfunc = lambda v: HBO.objectiveFunc(v, self.alpha, self.gamma, self.
                                              G, self.sumLogPi)
        success = 0
        print vopt, '*optimal*'

        for trial in range(nTrial):
            initV = np.random.rand(self.K)
            v = HBO.estimate_v(self.gamma, self.alpha, self.G, self.K,
                               self.sumLogPi, initV)
            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