add train algorithm code