python sgd meaning code example
Example: sgd in python
>>> import tensorflow as tf
>>> # Create needed objects
>>> sgd = tf.keras.optimizers.SGD(learning_rate=0.1, momentum=0.9)
>>> var = tf.Variable(2.5)
>>> cost = lambda: 2 + var ** 2
>>> # Perform optimization
>>> for _ in range(100):
... sgd.minimize(cost, var_list=[var])
>>> # Extract results
>>> var.numpy()
-0.007128528
>>> cost().numpy()
2.0000508