On 13 Sep 2006, at 1:01 AM, python-list-request at python.org wrote:Date: 12 Sep 2006 20:17:47 -0700

From: Paul Rubin <http://phr.cx at NOSPAM.invalid>

Subject: Re: Random Drawing Simulation -- performance issue

To: python-list at python.org

"Travis E. Oliphant" <oliphant.travis at ieee.org> writes:

I need to simulate scenarios like the following: "You have a deck of

3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,

replace it, and repeat N times."

Thinking about the problem as drawing sample froms a discrete

distribution defined by the population might help.

Is there some important reason you want to do this as a simulation?

And is the real problem more complicated? If you draw from the

distribution 100,000 times with replacement and sum the results, per

the Central Limit Theorem you'll get something very close to a normal

distribution whose parameters you can determine analytically. There

is probably also some statistics formula to find the precise error.

So you can replace the 100,000 draws with a single draw.

The real problem is not substantially more complicated. (The real

code is, because it's embedded in a bunch of other stuff, but that's

not the point.)

I guess the essential reason that I want to do it as a simulation,

and not as a statistics formula, is that I'd like the code to be

readable (and modifiable) by a programmer who doesn't have a

statistics background. I could dredge up enough of my college stats

to do as you suggest (although I might not enjoy it), but I don't

think I want to make that a requirement.

On the other hand (quote somewhat snipped):

Date: Tue, 12 Sep 2006 22:46:04 -0500

From: Robert Kern <robert.kern at gmail.com>

Subject: Re: Random Drawing Simulation -- performance issue

To: python-list at python.org

Along the lines of what you're trying to get at, the problem that

the OP is

describing is one of sampling from a multinomial distribution.

numpy has a function that will do the sampling for you:

In [4]: numpy.random.multinomial?

Docstring:

Multinomial distribution.

multinomial(n, pvals, size=None) -> random values

pvals is a sequence of probabilities that should sum to 1

(however, the

last element is always assumed to account for the remaining

probability

as long as sum(pvals[:-1]) <= 1).

Here, I'm torn. I do want the code to be accessible to non-stats

people, but this just might do the trick. Must ponder.

Thanks, everyone, for your helpful suggestions!

B.

--

Brendon Towle, PhD

Cognitive Scientist

+1-412-690-2442x127

Carnegie Learning, Inc.

The Cognitive Tutor Company ?

Helping over 375,000 students in 1000 school districts succeed in math.

From http Wed Sep 13 15:49:44 2006

From: http (Paul Rubin)

Date: 13 Sep 2006 06:49:44 -0700

Subject: Help me use my Dual Core CPU!

References: <1158063943.007271.86000@m73g2000cwd.googlegroups.com>

<45071c6d$0$576$ed2619ec@ptn-nntp-reader03.plus.net>

<1158128695.301849.148210@p79g2000cwp.googlegroups.com>

<7x8xkol0n9.fsf@ruckus.brouhaha.com>

<1158132381.716706.243040@e63g2000cwd.googlegroups.com>

<mailman.14.1158140507.10491.python-list@python.org>

<7xbqpk5bnc.fsf@ruckus.brouhaha.com>

<mailman.17.1158145066.10491.python-list@python.org>

<7xodtkt48l.fsf@ruckus.brouhaha.com>

<mailman.25.1158154691.10491.python-list@python.org>

Message-ID: <7xr6yf3mh3.fsf@ruckus.brouhaha.com>

Robin Becker <robin at reportlab.com> writes:

Wow! Yes, it seems to be real ("Clovertown" 4-core cpu). See:

http://www.tgdaily.com/2006/03/07/idf_keynotes_welcome_to_intel_3-point-0/There's even a version that goes out to 32 cores ("Dunnington") on the

drawing boards.

We better get rid of that GIL soon ;-)