Derive or write the mathematical formulation for Logistic Regression and explain how gradient descent updates its weights.