Add train/test and fix a bug in compute_dw