def descent(data,theta,batchSize,stopType,stopType,thresh,alpha):
init_time = time.time()
i=0
k=0
X,y = shuffleData(data)
grad = np.zeros(theta.shape)
costs = [cost(X,y,theta)]
while True:
grad = gradient(X[k:k+batchSize],y[k:k+batchSize],theta)
k +=batchSize
if k >=n:
k=0
X,y = shuffleData(Data)
theta = theta - alpha*grad
costs.append(cost(X,y,theta))
i +=1
if stopType == STOP_ITER: value=i
elif stopType == STOP_COST: value=costs
elif stopType == STOP_GRAD: value = grad
if stopCriterion(stopType,value,thresh): break
return theta,i-1,costs,grad,time.time()-init_time