[SciPy-User] Semi-OT: weekend puzzle enumerating number of balls in bins

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Jan 13 11:38:37 EST 2014


On Mon, Jan 13, 2014 at 8:47 AM,  <josef.pktd at gmail.com> wrote:
> On Mon, Jan 13, 2014 at 1:46 AM, Alan G Isaac <alan.isaac at gmail.com> wrote:
>> I think this does what you want.
>> (BSD license.)
>> Note I left out argument error checking
>> for presentational clarity.
>>
>> Alan
>>
>>
>> def exact_partitions(n, nbins):
>>    result = []
>>    if nbins == 1:
>>      result.append([n])
>>    else:
>>      for n1 in range(n+1):
>>        for part in exact_partitions(n-n1,nbins-1):
>>          result.append([n1]+part)
>>    return result
>>
>> def all_partitions(n, nbins):
>>    result = []
>>    for n1 in range(n+1):
>>      result += exact_partitions(n1, nbins)
>>    return result
>
>
> Thanks Oleksandr, Alan
> Those look like what I need and I can try later today.

To report back

for nobs = 10 rr = 7 which is the example in the journal article:
Alan's is 80 times faster than my itertools version.
Oleksandr's is twice as fast as Alans

The result is the same in all three versions, based on the statistics
I need to calculate.

Thanks again.

Will end up in statsmodels as soon as I have figured out what the
typos are (in my code or in the journal articles).

Josef


>
> Thanks to all others
> The count is useful to see how large the problems is, but for the
> actual calculations I need to be able to calculate the test statistic,
> mean and variances and so on for the full cases.
>
> For small cases we can use the exact distribution.
> For medim cases we can use permutation resampling.
> For large cases we can use the normal approximation.
>
> However, I also need the exact distribution to figure out what the
> typos in the journal article or in my code for the normal
> approximation are.
>
> Thanks.
>
> Josef
>
>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list