Python implementation of UFLDL tutorial code