Monday, February 23, 2015

Linear Solve in Python

http://matrixprogramming.com/2011/03/linear-solve-in-python-numpy-and-scipy

This is a great tutorial on Linear Solver approaches in Python.  In particular, I like the reference to the Cholesky Decomposition.  For those that aren't familiar, Cholesky Decomposition only works on symmetric positive definite matrices.  This is pretty common in the Statistics world, since those are the properties of a well defined Covariance Matrix.

When I write up my code, I'll make sure to write up a cool tutorial on how to do the Cholesky Decomposition in Python for inverting a Covariance Matrix.  I promise!

Sparse Matrices in Python

In one of my previous jobs, my colleague wrote a very neat Python module that leveraged Sparse Matrix approach as defined here in Wikipedia.

I've been meaning to write something up similar to that, because I needed to use something similar to that in my dissertation work.

Wait, that's right, I won't need to do something like that, because it's right here in SciPy.

http://docs.scipy.org/doc/scipy/reference/sparse.html

Ridge Regression and Cross Validation in scikit

My dissertation work, Ridge Restricted Maximum Likelihood (RREML) is an extension of Ridge Regression applied to parametric covariance structures.  In my dissertation we applied it to Spatial Statistics, but it would also apply to Time Series as well.

One of the things that I struggled with in my dissertation approach was choosing the appropriate ridge constant.  I never got around to the much more favorable Cross Validation approach, but I instead used a secondary likelihood approach to estimate the ridge constant.

As I'm writing my algorithm in Python, I'm definitely going to leverage the scikit Ridge Regression approach to apply it to my RREML model.

http://scikit-learn.org/stable/modules/linear_model.html#ridge-regression

Spatial Distances in Python with GeoPy

So as I'm redoing my dissertation work, one of the functions I used was to calculate the distance between two locations based upon their coordinates (latitude and longitude).  At the time, I was referencing and using what is commonly referred to as the Great Circle distance.  So in the middle of my re-write into Python I stumbled across:

GeoPy

They not only provide the Great Circle distance calculation in their module, they introduced me to the Vincenty Distance.  According to the module authors this is a more accurate approach for calculating the distance.

It looks like I have a new way to calculate my spatial distances, and even better, I don't have to program it up myself.  I'm loving this Python re-write process already.

Time Series Analysis in Python with statsmodels

Wow, what a phenomenal discussion on Time Series analysis in Python.  I was unaware of this statsmodels project, but now I'm psyched to find it.  First of all, let me link to the talk that I'm referring to in my title:

Time Series Analysis in Python with statsmodels

Of course, this lead me to tracking down these experts, to learn more about what they do and wow I'm quite impressed.  Here are links to their blogs:

Wes McKinney
Josef Perktold
Skipper Seabold

These three seem to be very involved in Scientific Computing in Python, check out their blogs and links to talks, etc.  I know I will.



Sunday, February 22, 2015

Navigating Python documentation in Emacs

I've been a bit frustrated with my ability to navigate Python documentation in Emacs.  I came across the pydoc command, which seems very useful.  Then I wondered how I could leverage this in emacs, maybe write a lisp function in my .emacs file?

Enter a simple google search for "emacs pydoc", and you come across this fine project by John Kitchin.  He has a summary of it here:


Now, I love my elpy setup, so I thought I'd propose adding this into it.  No promises from Jorgen, but he did say that at the very least it needs to be its own package.

John, of course is very busy, and I've always wanted to do something like this in Emacs, so I volunteered to take on this project.  So get ready to follow along on how I create a MELPA distributed Emacs package. Yay, this should be fun. :)

You can follow along on github:

https://github.com/statmobile/pydoc

Copying Git files/directories to a new project.

I had recently done something similar when forking off my dissertation work from a subversion repository to a Git repository and then separating out the R library completely.  Anyway, I'm in the process of trying to port someone's previous work into its own project as a soon to be MELPA installable Emacs package.

Long story short, I need to get this guy's file and I want to keep his history in tact.  So, without further ado, this fine gentleman has a quick way of doing that.  See his post here.

http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/

Tuesday, February 17, 2015

Web Interface for Python

An ongoing project I've been wanting propose to a certain very large government agency involves creating a front-end for Python algorithms.  The first question is what should the interface be:
  • GUI - Would be great, but would need to be developed for all OS's including Mobile in my vision.  How fancy do I get, do I use Tcl/Tk, or even Qt?  I'm starting to feel overwhelmed already with all the Python GUI frameworks.  
  • Web - This would be ideal, as long as it follows standard HTML standards, then one deployment should work for everyone with Internet access.  But how?  Django doesn't seem to be interactive enough for my needs and also seems a bit of an overkill with the ORM.  Flask seems to be too light.  Hmm, and then I got some advice from the author of http://pythonprogramming.net on Reddit.
He pointed me to two amazing projects, and I'm seriously thinking about diving back into this proposal.  He recommended I look into the following projects:

"Brython is designed to replace Javascript as the scripting language for the Web. As such, it is a Python 3 implementation (you can take it for a test drive through a web console), adapted to the HTML5 environment, that is to say with an interface to the DOM objects and events"
Trinket:
"Trinket lets you run and write code in any browser, on any device.
Trinkets work instantly, with no need to log in, download plugins, or install software.
Easily share or embed the code with your changes when you're done."


These look to be two amazing projects that I think I could leverage.  Here, check it out.

Trinket: Brython: