sgd in python

Solutions on MaxInterview for sgd in python by the best coders in the world

showing results for - "sgd in python"
Christiane
17 Sep 2016
1>>> import tensorflow as tf
2
3>>> # Create needed objects
4>>> sgd = tf.keras.optimizers.SGD(learning_rate=0.1, momentum=0.9)
5>>> var = tf.Variable(2.5)
6>>> cost = lambda: 2 + var ** 2
7
8>>> # Perform optimization
9>>> for _ in range(100):
10...     sgd.minimize(cost, var_list=[var])
11
12>>> # Extract results
13>>> var.numpy()
14-0.007128528
15>>> cost().numpy()
162.0000508
17