<s> import numpy as np <EOL> import os <EOL> import theano <EOL> import theano . tensor as T <EOL> import time <EOL> logit = lambda u : T . log ( u / ( <NUM_LIT:1.> - u ) ) <EOL> logit_np = lambda u : np . log ( u / ( <NUM_LIT:1.> - u ) ) . astype ( theano . config . floatX ) <EOL> def get_norms ( model , gradients ) : <EOL> """<STR_LIT>""" <EOL> norms = [ ] <EOL> grad_norms = [ ] <EOL> for param_name , param in model . params . iteritems ( ) : <EOL> norm = T . sqrt ( T . sum ( T . square ( param ) ) ) / T . prod ( param . shape . astype ( theano . config . floatX ) ) <EOL> norm . name = '<STR_LIT>' + param_name <EOL> norms . append ( norm ) <EOL> grad = gradients [ param ] <EOL> grad_norm = T . sqrt ( T . sum ( T . square ( grad ) ) ) / T . prod ( grad . shape . astype ( theano . config . floatX ) ) <EOL> grad_norm . name = '<STR_LIT>' + param_name <EOL> grad_norms . append ( grad_norm ) <EOL> return norms , grad_norms <EOL> def create_log_dir ( args , model_id ) : <EOL> model_id += args . suffix + time . strftime ( '<STR_LIT>' ) <EOL> model_dir = os . path . join ( os . path . expanduser ( args . output_dir ) , model_id ) <EOL> os . makedirs ( model_dir ) <EOL> return model_dir </s>
