#NEWLINE# def __init__( self , input = None , target = None , regularize = True ) : #NEWLINE# #INDENT# super ( RegressionLayer , self ) . __init__ ( ) #NEWLINE# self . regularize = regularize #NEWLINE# if ( not input ) : #NEWLINE# #INDENT# input = T . matrix ( 'input' ) #NEWLINE# #UNINDENT# if ( not target ) : #NEWLINE# #INDENT# target = T . matrix ( 'target' ) #NEWLINE# #UNINDENT# self . stepsize = T . scalar ( ) #NEWLINE# self . w = T . matrix ( ) #NEWLINE# self . b = T . vector ( ) #NEWLINE# self . activation = ( T . dot ( input , self . w ) + self . b ) #NEWLINE# self . prediction = self . build_prediction ( ) #NEWLINE# self . classification_cost = self . build_classification_cost ( target ) #NEWLINE# self . regularization = self . build_regularization ( ) #NEWLINE# self . cost = self . classification_cost #NEWLINE# if self . regularize : #NEWLINE# #INDENT# self . cost = ( self . cost + self . regularization ) #NEWLINE# #UNINDENT# ( self . grad_w , self . grad_b , grad_act ) = T . grad ( self . cost , [ self . w , self . b , self . prediction ] ) #NEWLINE# print ( 'grads' , self . grad_w , self . grad_b ) #NEWLINE# self . update = M . Method ( [ input , target ] , [ self . cost , self . grad_w , self . grad_b , grad_act ] , updates = { #NEWLINE# #INDENT# self . w : ( self . w - ( self . stepsize * regularize . grad_w ) ) , #NEWLINE# self . b : ( self . b - ( self . stepsize * self . grad_b ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . apply = M . Method ( input , self . prediction )