Implement vectorization to speed up training

http://ufldl.stanford.edu/wiki/index.php/Vectorization