first commit. working, but not at all pretty.
verson 2.0: added cross validation for picking regularization constant. minor updates and bug fixes also.