#NEWLINE# def __call__( self , y , pred , sample_weight = None ) : #NEWLINE# #INDENT# pred = pred . ravel ( ) #NEWLINE# diff = ( y - pred ) #NEWLINE# gamma = self . gamma #NEWLINE# if ( gamma is None ) : #NEWLINE# #INDENT# if ( sample_weight is None ) : #NEWLINE# #INDENT# gamma = stats . scoreatpercentile ( np . abs ( diff ) , ( self . alpha * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# gamma = _weighted_percentile ( np . abs ( diff ) , loss , ( self . alpha * 100 ) ) #NEWLINE# #UNINDENT# #UNINDENT# gamma_mask = ( np . abs ( diff ) <= gamma ) #NEWLINE# if ( sample_weight is None ) : #NEWLINE# #INDENT# sq_loss = np . sum ( ( 0.5 * ( diff [ gamma_mask ] ** 2.0 ) ) ) #NEWLINE# lin_loss = np . sum ( ( gamma * ( np . abs ( diff [ ( ~ gamma_mask ) ] ) - ( gamma / 2.0 ) ) ) ) #NEWLINE# loss = ( ( sq_loss + lin_loss ) / y . shape [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sq_loss = np . sum ( ( ( 0.5 * sample_weight [ gamma_mask ] ) * ( diff [ gamma_mask ] ** 2.0 ) ) ) #NEWLINE# lin_loss = np . sum ( ( ( gamma * sample_weight [ ( ~ gamma_mask ) ] ) * ( np . abs ( diff [ ( ~ gamma_mask ) ] ) - ( gamma / 2.0 ) ) ) ) #NEWLINE# loss = ( ( sq_loss + lin_loss ) / sample_weight . sum ( ) ) #NEWLINE# #UNINDENT# return loss