Sunday, March 29, 2015

Remove all old linux kernels, headers and modules for Debian based systems

This has come up often for me with my linux machines, so I'll just blog a blog on the topic.  I came across two useful posts:

RemoveOldKernels

Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules

The former is useful, but it only removes the kernels.  I want to remove all headers, etc. associated with them.  So, before I run the command from the latter blog post, I just want to confirm what I'm going to remove, as should you, with the following code (note, not as root just to be even more cautious):
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
 Perfect, now I can just run the one-liner from that latter blog post:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Boom, I just got rid of over 3 GB's of old linux kernels on my system.

Monday, March 16, 2015

Python String Format Cookbook

As I'm tutoring someone through their introductory Computer Science course, I keep finding myself getting caught up in the Python 3 string formatting.  His assignments seem to focus a lot on how to print out various formats, and I'm still stuck in handling how they worked in Python 2.7.  I keep googling, and googling, and I often just find myself coming back to this reference.

Python String Format Cookbook

I'm just putting this up so that I can keep going back to this reference as I still adjust from Python 2 to Python 3.

EDIT: Just saw this cool writeup on Reddit: PyFormat.info

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