Esempio n. 1
0
void randirmult(double *pp, int *aa, int len, int m)

{
/**
 compound dirichlet - Multinomial
*/
     double *x ;

    if (len==0) return ;
    if (len==1) {
      aa[0] = m ;
      return ;
    }
    ZALLOC(x, len, double) ;  
    randirichlet(x, pp, len) ;
    ranmultinom(aa, m, x, len) ;
    free(x) ;
}
Esempio n. 2
0
void ranmultinom(int *samp, int n, double *p, int len) 
// multinomial sample p is prob dist  n samples returned
// work is O(len^2) which is silly 
{
  int x ;
  double *pp ;

  if (len==0) return ;   
  ivzero(samp, len) ;
  if (n<=0) return ;

   if (len==1)  { 
    samp[0] = n ;
    return ;
   }

   ZALLOC(pp, len, double) ;
   copyarr(p, pp, len) ;
   bal1(pp, len) ;

   samp[0] = x = ranbinom(n, pp[0]) ;
   ranmultinom(samp+1, n-x, p+1, len-1) ;
   free(pp) ;
}