#NEWLINE# def bench_b( power_list ) : #NEWLINE# #INDENT# ( n_samples , n_features ) = ( 1000 , 10000 ) #NEWLINE# data_params = { #NEWLINE# #INDENT# 'n_samples' : n_samples , #NEWLINE# 'n_features' : n_features , #NEWLINE# 'tail_strength' : 0.7 , #NEWLINE# 'random_state' : random_state , #NEWLINE# #UNINDENT# } #NEWLINE# dataset_name = ( 'low rank matrix %d x %d' % ( n_samples , n_features ) ) #NEWLINE# ranks = [ 10 , 50 , 100 ] #NEWLINE# if enable_spectral_norm : #NEWLINE# #INDENT# all_spectral = defaultdict ( list ) #NEWLINE# #UNINDENT# all_frobenius = defaultdict ( list ) #NEWLINE# for rank in ranks : #NEWLINE# #INDENT# X = make_low_rank_matrix ( effective_rank = rank , ** data_params ) #NEWLINE# if enable_spectral_norm : #NEWLINE# #INDENT# X_spectral_norm = norm_diff ( X , norm = 2 , msg = False ) #NEWLINE# #UNINDENT# X_fro_norm = norm_diff ( X , norm = 'fro' , msg = False ) #NEWLINE# for n_comp in [ np . int ( ( rank / 2 ) ) , rank , ( rank * 2 ) ] : #NEWLINE# #INDENT# label = ( 'rank=%d, n_comp=%d' % ( rank , n_comp ) ) #NEWLINE# print ( label ) #NEWLINE# for pi in power_list : #NEWLINE# #INDENT# ( U , s , V , _ ) = svd_timing ( X , n_comp , n_iter = pi , n_oversamples = 2 , power_iteration_normalizer = 'LU' ) #NEWLINE# if enable_spectral_norm : #NEWLINE# #INDENT# A = U . dot ( np . diag ( s ) . dot ( V ) ) #NEWLINE# all_spectral [ label ] . append ( ( norm_diff ( ( X - A ) , norm = 2 ) / X_spectral_norm ) ) #NEWLINE# #UNINDENT# f = scalable_frobenius_norm_discrepancy ( X , U , s , V ) #NEWLINE# all_frobenius [ label ] . append ( ( f / X_fro_norm ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if enable_spectral_norm : #NEWLINE# #INDENT# title = ( '%s: spectral norm diff vs n power iteration' % dataset_name ) #NEWLINE# plot_power_iter_vs_s ( power_iter , all_spectral , title ) #NEWLINE# #UNINDENT# title = ( '%s: frobenius norm diff vs n power iteration' % dataset_name ) #NEWLINE# plot_power_iter_vs_s ( power_iter , all_frobenius , title )