implement the train_model() according to the paper