#NEWLINE# @ blueprint . route ( '/visualize-lr' , methods = [ 'POST' ] ) #NEWLINE# def visualize_lr( ) : #NEWLINE# #INDENT# '\n    Returns a JSON object of data used to create the learning rate graph\n    ' #NEWLINE# policy = flask . request . form [ 'lr_policy' ] #NEWLINE# lrs = map ( float , flask . request . form [ 'learning_rate' ] . split ( ',' ) ) #NEWLINE# if ( policy == 'fixed' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'step' ) : #NEWLINE# #INDENT# step = float ( flask . request . form [ 'lr_step_size' ] ) #NEWLINE# gamma = float ( flask . request . form [ 'lr_step_gamma' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'multistep' ) : #NEWLINE# #INDENT# steps = [ float ( s ) for s in flask . request . form [ 'lr_multistep_values' ] . split ( ',' ) ] #NEWLINE# current_step = 0 #NEWLINE# gamma = float ( flask . request . form [ 'lr_multistep_gamma' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'exp' ) : #NEWLINE# #INDENT# gamma = float ( flask . request . form [ 'lr_exp_gamma' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'inv' ) : #NEWLINE# #INDENT# gamma = float ( flask . request . form [ 'lr_inv_gamma' ] ) #NEWLINE# power = float ( flask . request . form [ 'lr_inv_power' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'poly' ) : #NEWLINE# #INDENT# power = float ( flask . request . form [ 'lr_poly_power' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'sigmoid' ) : #NEWLINE# #INDENT# step = float ( flask . request . form [ 'lr_sigmoid_step' ] ) #NEWLINE# gamma = float ( flask . request . form [ 'lr_sigmoid_gamma' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise werkzeug . exceptions . BadRequest ( 'Invalid policy' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# datalist = [ ] #NEWLINE# for ( j , lr ) in enumerate ( lrs ) : #NEWLINE# #INDENT# data = [ ( 'Learning Rate %d' % j ) ] #NEWLINE# for i in xrange ( 101 ) : #NEWLINE# #INDENT# if ( policy == 'fixed' ) : #NEWLINE# #INDENT# data . append ( lr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'step' ) : #NEWLINE# #INDENT# data . append ( ( lr * math . pow ( gamma , math . floor ( ( float ( i ) / step ) ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i == 'multistep' ) : #NEWLINE# #INDENT# if ( ( current_step < len ( steps ) ) and ( i >= steps [ current_step ] ) ) : #NEWLINE# #INDENT# current_step += 1 #NEWLINE# #UNINDENT# data . append ( ( lr * math . pow ( gamma , current_step ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'exp' ) : #NEWLINE# #INDENT# data . append ( ( lr * math . pow ( gamma , i ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'inv' ) : #NEWLINE# #INDENT# data . append ( ( lr * math . pow ( ( 1.0 + ( gamma * i ) ) , ( - power ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'poly' ) : #NEWLINE# #INDENT# data . append ( ( lr * math . pow ( ( 1.0 - ( float ( i ) / 100 ) ) , power ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( policy == 'sigmoid' ) : #NEWLINE# #INDENT# data . append ( ( lr / ( 1.0 + math . exp ( ( gamma * ( i - step ) ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# datalist . append ( data ) #NEWLINE# #UNINDENT# return json . dumps ( { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'columns' : datalist , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } )