Optimizers

Introduction to TensorFlow in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

How to find a minimum

The image shows the Grand Canyon.

1 Source: U.S. National Park Service
Introduction to TensorFlow in Python

How to find a minimum

The image shows the Grand Canyon.

1 Source: U.S. National Park Service
Introduction to TensorFlow in Python

How to find a minimum

The image shows the Grand Canyon.

1 Source: U.S. National Park Service
Introduction to TensorFlow in Python

The figure shows the learning path of the SGD, RMS prop, and Adam optimizers for a simple problem.

Introduction to TensorFlow in Python

The gradient descent optimizer

  • Stochastic gradient descent (SGD) optimizer

    • tf.keras.optimizers.SGD()
    • learning_rate
  • Simple and easy to interpret

Introduction to TensorFlow in Python

The RMS prop optimizer

  • Root mean squared (RMS) propagation optimizer

    • Applies different learning rates to each feature
    • tf.keras.optimizers.RMSprop()
    • learning_rate
    • momentum
    • decay
  • Allows for momentum to both build and decay

Introduction to TensorFlow in Python

The adam optimizer

  • Adaptive moment (adam) optimizer

    • tf.keras.optimizers.Adam()
    • learning_rate
    • beta1
  • Performs well with default parameter values

Introduction to TensorFlow in Python

A complete example

import tensorflow as tf

# Define the model function
def model(bias, weights, features = borrower_features):
    product = tf.matmul(features, weights)
    return tf.keras.activations.sigmoid(product+bias)
# Compute the predicted values and loss
def loss_function(bias, weights, targets = default, features = borrower_features):
    predictions = model(bias, weights)
    return tf.keras.losses.binary_crossentropy(targets, predictions)
# Minimize the loss function with RMS propagation
opt = tf.keras.optimizers.RMSprop(learning_rate=0.01, momentum=0.9)
opt.minimize(lambda: loss_function(bias, weights), var_list=[bias, weights])
Introduction to TensorFlow in Python

Let's practice!

Introduction to TensorFlow in Python

Preparing Video For Download...