def test_run_birth_move_can_create_necessary_comps(self): ''' Can we start with one comp and recover the 3 true ones? Of course, depending on the random init we maybe cannot, but we should be able to a significant fraction of the time. ''' birthArgs = dict(Kfresh=5, freshInitName='randexamples', freshAlgName='VB', nFreshLap=50) nSuccess = 0 nTrial = 10 for trial in range(nTrial): PRNG = np.random.RandomState(trial) newModel, newSS, MInfo = BirthMove.run_birth_move(self.oneModel, self.Data, self.oneSS, randstate=PRNG, **birthArgs) print newSS.N newSS = self._run_LearnAlg_iterations(newModel, self.Data, nIter=10) # after refining, we better have true comps! topCompIDs = np.argsort(newSS.N)[::-1] foundMatch = np.zeros(3) for kk in topCompIDs[:3]: estMu = newModel.obsModel.get_mean_for_comp(kk) print estMu for jj in range(3): trueMu = self.Mu[jj,:] if np.max(trueMu - estMu) < 0.5: foundMatch[jj] = 1 print ' ' if np.all(foundMatch): nSuccess += 1 assert nSuccess/float(nTrial) > 0.5
def test_run_birth_move_produces_viable_model(self): ''' Verify that the output of run_birth_move can be used to create a valid model that can do all necessary subroutines like calc_local_params, etc. ''' PRNG = np.random.RandomState(12345) birthArgs = dict(Kfresh=10, freshInitName='randexamples', freshAlgName='VB', nFreshLap=50) newModel, newSS, MInfo = BirthMove.run_birth_move(self.oneModel, self.Data, self.oneSS, randstate=PRNG, **birthArgs) # Try newModel out with some quick calculations assert newModel.obsModel.K > self.oneModel.obsModel.K LP = newModel.calc_local_params(self.Data) SS = newModel.get_global_suff_stats(self.Data, LP) assert SS.K == newModel.obsModel.K
def test_run_birth_move_can_create_necessary_comps(self): ''' Can we start with one comp and recover the 3 true ones? Of course, depending on the random init we maybe cannot, but we should be able to a significant fraction of the time. ''' birthArgs = dict(Kfresh=5, freshInitName='randexamples', freshAlgName='VB', nFreshLap=50) nSuccess = 0 nTrial = 10 for trial in range(nTrial): PRNG = np.random.RandomState(trial) newModel, newSS, MInfo = BirthMove.run_birth_move(self.oneModel, self.Data, self.oneSS, randstate=PRNG, **birthArgs) print newSS.N newSS = self._run_LearnAlg_iterations(newModel, self.Data, nIter=10) # after refining, we better have true comps! topCompIDs = np.argsort(newSS.N)[::-1] foundMatch = np.zeros(3) for kk in topCompIDs[:3]: estMu = newModel.obsModel.get_mean_for_comp(kk) print estMu for jj in range(3): trueMu = self.Mu[jj, :] if np.max(trueMu - estMu) < 0.5: foundMatch[jj] = 1 print ' ' if np.all(foundMatch): nSuccess += 1 assert nSuccess / float(nTrial) > 0.5