#NEWLINE# def scalable_frobenius_norm_discrepancy( X , U , s , V ) : #NEWLINE# #INDENT# if ( ( X . shape [ 0 ] * batch_size . shape [ 1 ] ) < MAX_MEMORY ) : #NEWLINE# #INDENT# A = ( X - U . dot ( np . diag ( s ) . dot ( V ) ) ) #NEWLINE# return norm_diff ( A , norm = 'fro' ) #NEWLINE# #UNINDENT# print ( '... computing fro norm by batches...' ) #NEWLINE# batch_size = 1000 #NEWLINE# Vhat = np . diag ( s ) . dot ( V ) #NEWLINE# cum_norm = 0.0 #NEWLINE# for batch in gen_batches ( X . shape [ 0 ] , batch_size ) : #NEWLINE# #INDENT# M = ( X [ batch , : ] - U [ batch , : ] . dot ( Vhat ) ) #NEWLINE# cum_norm += norm_diff ( M , norm = 'fro' , msg = False ) #NEWLINE# #UNINDENT# return np . sqrt ( cum_norm )