Change the BGD to linear BGD, and seprated the code