#NEWLINE# def _check_bad_constraint( self , violation , djoint_feature_mean , loss , old_constraints , break_on_bad , tol = None ) : #NEWLINE# #INDENT# violation_difference = ( violation - self . last_slack_ ) #NEWLINE# if ( self . verbose > 1 ) : #NEWLINE# #INDENT# print ( ( 'New violation: %f difference to last: %f' % ( violation , violation_difference ) ) ) #NEWLINE# #UNINDENT# if ( ( violation_difference < 0 ) and ( violation > 0 ) and break_on_bad ) : #NEWLINE# #INDENT# raise ValueError ( 'Bad inference: new violation is smaller than old.' ) #NEWLINE# #UNINDENT# if ( tol is None ) : #NEWLINE# #INDENT# tol = self . tol #NEWLINE# #UNINDENT# if ( violation_difference < tol ) : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( 'new constraint too weak.' ) #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# equals = [ True for ( djoint_feature_ , loss_ ) in old_constraints if ( np . all ( ( djoint_feature_ == djoint_feature_mean ) ) and ( loss == loss_ ) ) ] #NEWLINE# if np . any ( equals ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# if self . check_constraints : #NEWLINE# #INDENT# for con in old_constraints : #NEWLINE# #INDENT# violation_tmp = max ( ( con [ 1 ] - np . dot ( equals . w , con [ 0 ] ) ) , 0 ) #NEWLINE# if ( self . verbose > 5 ) : #NEWLINE# #INDENT# print ( ( 'violation old constraint: %f' % violation_tmp ) ) #NEWLINE# #UNINDENT# if ( ( violation - violation_tmp ) < ( - 1e-05 ) ) : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# print ( ( 'bad inference: %f' % ( violation_tmp - violation ) ) ) #NEWLINE# #UNINDENT# if break_on_bad : #NEWLINE# #INDENT# raise ValueError ( 'Bad inference: new violation is weaker than previous constraint.' ) #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return False