Exemple #1
0
void Restaurant::updateSeatingForDpp(void) {

	for (int idx=0; idx<numPatrons; idx++)
		{
		// get a pointer to the element and its current table
		Patron *p = patrons[idx];
		Table *tablePtr = p->getTable();

		// remove the element from the table
		tablePtr->removePatronFromTable(p);
		if (tablePtr->getNumPatrons() == 0)
			deleteTable(tablePtr);
		
		// calculate the likelihood when the element is seated at all possible tables
		vector<double> probs;
		for (int i=0; i<getNumTables(); i++)
			{
			Table *tp = getTable(i);
			probs.push_back( tp->lnLikelihood(p) + log(tp->getNumPatrons()) );
			}
		probs.push_back( p->getLnLikelihoodalone() + log(concentrationParm) );
		normalizeVector( probs );

		// pick a table for reassignment
		int whichTable = multinomialRv(probs);
			
		// add the element to that table
		if (whichTable < getNumTables())
			{
			tablePtr = getTable(whichTable);
			tablePtr->addPatronToTable(p);
			}
		else
			{
			tablePtr = new Table(this, ranPtr, observationsPtr, observationsPtr->getNumUniqueAlleles(), lnFactorial);
			addTableToRestaurant( tablePtr );
			tablePtr->addPatronToTable(p);
			}
		}
}