Ottimizzatori

Introduzione a TensorFlow in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Come trovare un minimo

L'immagine mostra il Grand Canyon.

1 Fonte: U.S. National Park Service
Introduzione a TensorFlow in Python

Come trovare un minimo

L'immagine mostra il Grand Canyon.

1 Fonte: U.S. National Park Service
Introduzione a TensorFlow in Python

Come trovare un minimo

L'immagine mostra il Grand Canyon.

1 Fonte: U.S. National Park Service
Introduzione a TensorFlow in Python

La figura mostra il percorso di apprendimento degli ottimizzatori SGD, RMSprop e Adam per un problema semplice.

Introduzione a TensorFlow in Python

L'ottimizzatore gradient descent

  • Ottimizzatore Stochastic gradient descent (SGD)

    • tf.keras.optimizers.SGD()
    • learning_rate
  • Semplice e facile da interpretare

Introduzione a TensorFlow in Python

L'ottimizzatore RMSprop

  • Ottimizzatore Root mean squared (RMS) propagation

    • Applica tassi di apprendimento diversi a ciascuna feature
    • tf.keras.optimizers.RMSprop()
    • learning_rate
    • momentum
    • decay
  • Consente al momentum di crescere e decadere

Introduzione a TensorFlow in Python

L'ottimizzatore Adam

  • Ottimizzatore Adaptive moment (Adam)

    • tf.keras.optimizers.Adam()
    • learning_rate
    • beta1
  • Funziona bene con i valori predefiniti

Introduzione a TensorFlow in Python

Un esempio completo

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])
Introduzione a TensorFlow in Python

Esercitiamoci!

Introduzione a TensorFlow in Python

Preparing Video For Download...