SciPy - the embarrassing way to code
vetta.org
vetta.org
There was some good discussion about this last time this was posted, and also current discussion over on reddit.
http://news.ycombinator.com/item?id=182676 http://www.reddit.com/r/Python/comments/a2xzj/the_embarrassi...
The second implementation is about the same length and replaces all of the simplicity of the recursive solution with a bunch of five-dimensional arrays. Never before did I have to think as deeply about vectorized functions, array broadcasting, dimension matching, etc. The non-recursive version is about an order of magnitude faster, and what's better, using the numpy operators means nearly all of the processing is offloaded into low-level C routines, so the Python overhead is effectively nil. On the downside the code is extremely difficult to follow now... trying to visualize what's going on in 5 dimensions is a real pain.
trying to visualize what's going on in 5 dimensions is a real pain.
Yes, that's been my main problem with the programming style described in the linked post.As a nublet, I probably didn't end up saving much time over C++, but I could see that in the right hands, this tool would be a lifesaver
I'm referring to the analog of R's mvtnorm library.
Yes, you can use rpy2. Yes, you can roll your own dmvnorm (but be careful about the degenerate situations with zero eigenvalues that always arise in high dimensional problems with real data). It is significantly more of a pain to roll your own pmvnorm, because you are now talking about efficient computation of high dimensional integrals, which always seems to involve a trip to Numerical Recipes or the like (see the Genz and Miwa references when you do "?pmvnorm" in R).
Basically this is a huge thing to lack.
PS: yes, if you grep the codebase, you can find this: http://www.scipy.org/doc/api_docs/SciPy.stats.kde.gaussian_k...
But you need to write wrappers because it doesn't provide a basic interface to the multivariate gaussian density.
I could go on about other parts of scipy -- it has some advanced stuff but lacks a lot of basics...
One could argue that if you're going to call something "SciPy", it ought to cover all sorts of scientific computation...but, it is Open Source under a very open license. Contributing is very easy, and the team are very friendly to outsiders sending patches, and it's not hard to no longer be considered an "outsider". So, if you need it and SciPy doesn't provide it, why not develop it and contribute?
What I'm trying to say is that complaining about missing functions you need from an Open Source project just wastes your time and annoys the pig.
Scipy (and the whole Python numerical computation stack) has nontrivial competition out there and here's what it needs to do to compete...if its developers care about adoption, which most do.
Definitely not saying scipy == crap, just that for stats/machine learning (which is a big percentage of a lot of applications today) it is not mature.
1. A language with matrices as a central data structure and a rich variety of operations on them. Yup, SciPy is this, kinda, though not to the same extent as APL.
2. A language with an extremely strange syntax, apparently engineered for terseness on the smallest possible scale. Nope, SciPy is basically just a bunch of Python libraries, and the language syntax is still Python's.
(There's more to SciPy than the matrix operations, but that's what the original poster was mostly talking about and what might prompt comparisons with APL.)
I sheepishly told my advisor at the time what had happened, worried he would think me an idiot, but he was thrilled: "You solved the problem! That's what's important."
In other words rather than become embarrassed after realising a months work boiled down to just a few lines think about how much you learned to get to those few lines.
I am by no mean knowledgeable in those areas, but my understanding is that using specialized hardware/aggressively optimized code in numpy (or similar tools) would be very hard, though. One of the problem is that CUDA or multi-core optimized numpy would have a significant overhead (obviously of a totally different nature), and would be justified only for very large problems. Multi-code numpy was tried a few years ago by E. Jones, and the overhead was almost never worths it IIRC.
The current solution is to use those through libraries which implement linear algebra, etc... , which can be implemented on top of those architectures. There is obviously quite a bit of excitement around those technologies, and this was one of the most talked area at las scipy conference. Video are available: http://blog.enthought.com/?p=184. Some of them are related to those