Approximate Message Passing with Consistent Parameter Estimation and Applications to Sparse Learning