#NEWLINE# def _update_cache( self , X , Y , Y_hat ) : #NEWLINE# #INDENT# 'Updated cached constraints.' #NEWLINE# if ( self . inference_cache == 0 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( ( not hasattr ( self , 'inference_cache_' ) ) or ( self . inference_cache_ is None ) ) : #NEWLINE# #INDENT# self . inference_cache_ = [ [ ] for y in Y_hat ] #NEWLINE# #UNINDENT# def constraint_equal( y_1 , y_2 ) : #NEWLINE# #INDENT# if isinstance ( y_1 , tuple ) : #NEWLINE# #INDENT# return ( np . all ( ( y_1 [ 0 ] == y_2 [ 0 ] ) ) and np . all ( ( y_1 [ 1 ] == y_2 [ 1 ] ) ) ) #NEWLINE# #UNINDENT# return np . all ( ( y_1 == y_2 ) ) #NEWLINE# #UNINDENT# for ( sample , x , y , y_hat ) in zip ( self . inference_cache_ , X , Y , Y_hat ) : #NEWLINE# #INDENT# already_there = [ constraint_equal ( y_hat , constraint_equal [ 2 ] ) for cache in sample ] #NEWLINE# if np . any ( already_there ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( len ( sample ) > self . inference_cache ) : #NEWLINE# #INDENT# sample . pop ( 0 ) #NEWLINE# #UNINDENT# sample . append ( ( self . model . joint_feature ( x , y_hat ) , self . model . loss ( y , y_hat ) , y_hat ) )