def generateIBP(customers, alpha=10, reducedprop=1.0):
 _lambda = (alpha * sum((1.0 / array(list(range(1, (customers + 1)))))))
 alpha /= reducedprop
 maxdishes = (int((_lambda + (sqrt(_lambda) * 2))) + 1)
 res = zeros((customers, maxdishes), dtype=bool)
 stickprops = beta(alpha, 1, maxdishes)
 currentstick = 1.0
 dishesskipped = 0
 for (i, nu) in enumerate(stickprops):
  currentstick *= nu
  dishestaken = (rand(customers) < (currentstick * reducedprop))
  if (sum(dishestaken) > 0):
   res[:, (i - dishesskipped)] = dishestaken
  else:
   dishesskipped += 1
 return res[:, :(maxdishes - dishesskipped)]

def generateIBP ( customers , alpha = 10 , reducedprop = 1.0 ) : _lambda = ( alpha * sum ( ( 1.0 / array ( list ( range ( 1 , ( customers + 1 ) ) ) ) ) ) ) alpha /= reducedprop maxdishes = ( int ( ( _lambda + ( sqrt ( _lambda ) * 2 ) ) ) + 1 ) res = zeros ( ( customers , maxdishes ) , dtype = bool ) stickprops = beta ( alpha , 1 , maxdishes ) currentstick = 1.0 dishesskipped = 0 for ( i , nu ) in enumerate ( stickprops ) : currentstick *= nu dishestaken = ( rand ( customers ) < ( currentstick * reducedprop ) ) if ( sum ( dishestaken ) > 0 ) : res [ : , ( i - dishesskipped ) ] = dishestaken else : dishesskipped += 1 return res [ : , : ( maxdishes - dishesskipped ) ]
simple implementation of the indian buffet process .