## pygsl-discuss

 [pygsl-discuss] sampling from multinomial distribution efficiently From: per freem - 2009-10-14 04:29:10 ```hi all, i have a series of probability vector that i'd like to feed into multinomial to get an array of vector outcomes back. for example, given: p = array([[ 0.9 , 0.05, 0.05], [ 0.05, 0.05, 0.9 ]]) i'd like to call multinomial like this: multinomial(1, p) to get a vector of multinomial samplers, each using the nth list in 'p'. something like: array([[1, 0, 0], [0, 0 1]]) in this case. is this possible? it seems like 'multinomial' takes only a one dimensional array. i could write this as a "for" loop of course but i prefer a vectorized version since speed is crucial for me here. the 'multinomial' function from scipy does not support this, it seems. is there a way to do this in pygsl? thanks very much. ```
 Re: [pygsl-discuss] sampling from multinomial distribution efficiently From: Pierre SCHNIZER - 2009-10-14 08:09:25 ```Dear Per, I guess you know that you can run the sampler (unfortunately not changing the parameters k, and phi) adding an additonal variable (like all rng methods and pdf functions): >>> r = pygsl.rng.rng() >>> k = 1 >>> phi = (.9, .05) >>> r.multinomial(phi, k, 10) array([[1, 0]]) I should have implemented the parameters phi and k as arrays in the first place (accepting the additional twist for the novice). For these functions a C loop is roughly 100 - 1000 times faster than a python loop I will have a look what it would mean to change the code to iterate internally. Sincerely yours Pierre > hi all, > > i have a series of probability vector that i'd like to feed into > multinomial to get an array of vector outcomes back. for example, > given: > > p = array([[ 0.9 , 0.05, 0.05], > [ 0.05, 0.05, 0.9 ]]) > > i'd like to call multinomial like this: > > multinomial(1, p) > > to get a vector of multinomial samplers, each using the nth list in > 'p'. something like: > > array([[1, 0, 0], [0, 0 1]]) in this case. is this possible? it seems > like 'multinomial' takes only a one dimensional array. i could write > this as a "for" loop of course but i prefer a vectorized version since > speed is crucial for me here. the 'multinomial' function from scipy > does not support this, it seems. is there a way to do this in pygsl? > > thanks very much. > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > pygsl-discuss mailing list > pygsl-discuss@... > https://lists.sourceforge.net/lists/listinfo/pygsl-discuss > -- +---------------------------------------------------------------------+ Pierre Schnizer GSI Helmholtzzentrum für Schwerionenforschung GmbH Planckstraße 1 D-64291 Darmstadt http://www.gsi.de Gesellschaft mit beschränkter Haftung Sitz der Gesellschaft: Darmstadt Handelsregister: Amtsgericht Darmstadt, HRB 1528 Geschäftsführer: Professor Dr. Horst Stöcker Vorsitzende des Aufsichtsrates: Dr. Beatrix Vierkorn-Rudolph Stellvertreter: Ministerialdirigent Dr. Rolf Bernhardt +---------------------------------------------------------------------+ ```