Monte Carlo probability calculation in Python

Paul Moore p.f.moore at gmail.com
Mon Feb 9 16:57:34 EST 2015


On Friday, 6 February 2015 23:49:51 UTC, Steven D'Aprano  wrote:
> > Just a quick status update, in case you're interested. With relatively
> > little work (considering I started not knowing much about numpy) I managed
> > to put together solutions for a couple of my friend's problems which ran
> > in basically the same time as his custom C code. Very impressive!
> 
> Very nice! Care to share the code?

Will do. I'll have to do some tidying up (at the moment, it's in an IPython notebook on my PC, full of chunks of code trying various approaches) but I'll post it in a few days.

The C++ code isn't postable, unfortunately, as it's not open source. Also, it's not *quite* custom C++, but rather an expression you feed into his program that does this type of calculation. The program's built specifically for doing this type of problem, and runs an expression tree in a tight C++ loop (there's a small virtual function call overhead, but that's about it). More accurately, I guess, it's a custom C++ application for solving this class of problem. But regardless, I'd expected Python to only manage to be "good enough", not to equal the C++ application, so I'm still impressed!

But it's a nice problem as an introduction to numpy - hard enough to be worth the effort, and it *needs* the performance numpy gives. But simple enough that solving it is achievable.

Paul



More information about the Python-list mailing list