optimized the sparse autoencoder cost and gradient computations