<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> import autograd . numpy as np <EOL> from autograd import grad <EOL> from autograd . util import quick_grad_check <EOL> from builtins import range <EOL> def sigmoid ( x ) : <EOL> return <NUM_LIT:0.5> * ( np . tanh ( x ) + <NUM_LIT:1> ) <EOL> def logistic_predictions ( weights , inputs ) : <EOL> return sigmoid ( np . dot ( inputs , weights ) ) <EOL> def training_loss ( weights ) : <EOL> preds = logistic_predictions ( weights , inputs ) <EOL> label_probabilities = preds * targets + ( <NUM_LIT:1> - preds ) * ( <NUM_LIT:1> - targets ) <EOL> return - np . sum ( np . log ( label_probabilities ) ) <EOL> inputs = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ] , <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> targets = np . array ( [ True , True , False , True ] ) <EOL> training_gradient_fun = grad ( training_loss ) <EOL> weights = np . array ( [ <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ] ) <EOL> quick_grad_check ( training_loss , weights ) <EOL> print ( "<STR_LIT>" , training_loss ( weights ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> weights -= training_gradient_fun ( weights ) * <NUM_LIT> <EOL> print ( "<STR_LIT>" , training_loss ( weights ) ) </s>
