#NEWLINE# def variable_batch_size_comparison( data ) : #NEWLINE# #INDENT# batch_sizes = [ i . astype ( int ) for i in np . linspace ( ( data . shape [ 0 ] // 10 ) , data . shape [ 0 ] , num = 10 ) ] #NEWLINE# for n_components in [ i . astype ( int ) for i in np . linspace ( ( data . shape [ 1 ] // 10 ) , data . shape [ 1 ] , num = 4 ) ] : #NEWLINE# #INDENT# all_times = defaultdict ( list ) #NEWLINE# all_errors = defaultdict ( list ) #NEWLINE# pca = PCA ( n_components = n_components ) #NEWLINE# rpca = RandomizedPCA ( n_components = n_components , random_state = 1999 ) #NEWLINE# results_dict = { k : benchmark ( est , batch_size ) for ( k , est ) in [ ( 'pca' , pca ) , ( 'rpca' , rpca ) ] } #NEWLINE# all_times [ 'pca' ] . extend ( ( [ results_dict [ 'pca' ] [ 'time' ] ] * len ( batch_sizes ) ) ) #NEWLINE# all_errors [ 'pca' ] . extend ( ( [ results_dict [ 'pca' ] [ 'error' ] ] * len ( batch_sizes ) ) ) #NEWLINE# all_times [ 'rpca' ] . extend ( ( [ results_dict [ 'rpca' ] [ 'time' ] ] * len ( batch_sizes ) ) ) #NEWLINE# all_errors [ 'rpca' ] . extend ( ( [ results_dict [ 'rpca' ] [ 'error' ] ] * len ( batch_sizes ) ) ) #NEWLINE# for batch_size in batch_sizes : #NEWLINE# #INDENT# ipca = IncrementalPCA ( n_components = n_components , batch_size = batch_size ) #NEWLINE# results_dict = { k : benchmark ( est , data ) for ( k , est ) in [ ( 'ipca' , ipca ) ] } #NEWLINE# all_times [ 'ipca' ] . append ( results_dict [ 'ipca' ] [ 'time' ] ) #NEWLINE# all_errors [ 'ipca' ] . append ( results_dict [ 'ipca' ] [ 'error' ] ) #NEWLINE# #UNINDENT# plot_batch_times ( all_times , n_components , batch_sizes , data ) #NEWLINE# plot_batch_errors ( all_errors , n_components , batch_sizes , data )