[SciPy-user] Simple combinatorics with Numpy
Mico Filós
elmico.filos at gmail.com
Wed Oct 22 06:57:11 EDT 2008
Thanks a lot for your answers.
The functions in sample.py do perfectly the job.
The motivation for this unordered sampling with replacement was perhaps a
little unclear in my first post. I need to count the different ways that a mean
sample of size 3 can occur. The probability of a given value for the sample
mean depends on how many *ordered* samples give rise to that given value. For
instance,
{1,1,1} = [(1,1,1)] -> 1
{1,1,3} = [(1,1,3), (1,3,1), (3,1,1)] -> 5/3
{1,3,5} = [(1,3,5), (3,1,5), (1,5,3), (5,1,3), (5,3,1), (3,5,1)] -> 8/3
{1,3,3} = [(1,3,3), (3,1,3), (3,3,1)] -> 7/3
{3,3,3} = [(3,3,3)] -> 3 ...
where {} and () denote the unordered and ordered samples, respectively. The
number of different orderings associated with a particular sample is given by a
multinomial distribution: if there are 3 places and 4 different numbers
repeated k1, k2, k3, k4 times, there are c = 3!/(k1!k2!k3!k4!) ordered samples.
Of course, I could also have proceeded the brute force way, enumerating all 3^4
ordered samples, computing their average, and counting the number of times each
different value occurs.
Sorry for being so wordy.
More information about the SciPy-User
mailing list