#NEWLINE# def load_binary( D1 , D2 , reduce = False ) : #NEWLINE# #INDENT# path = os . path . realpath ( __file__ ) #NEWLINE# file_path = os . path . abspath ( os . path . join ( path , '../usps_resampled.mat' ) ) #NEWLINE# data = loadmat ( file_path ) #NEWLINE# x = data [ 'train_patterns' ] . T #NEWLINE# y = data [ 'train_labels' ] . T #NEWLINE# xx = data [ 'test_patterns' ] . T #NEWLINE# yy = data [ 'test_labels' ] . T #NEWLINE# D1_list = [ ] #NEWLINE# D2_list = [ ] #NEWLINE# ( n , D ) = x . shape #NEWLINE# for i in range ( n ) : #NEWLINE# #INDENT# if ( y [ ( i , D1 ) ] == 1 ) : #NEWLINE# #INDENT# D1_list . append ( i ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( y [ ( i , D2 ) ] == 1 ) : #NEWLINE# #INDENT# D2_list . append ( i ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( reduce == True ) : #NEWLINE# #INDENT# D1_list = D1_list [ : 100 ] #NEWLINE# D2_list = D2_list [ : 100 ] #NEWLINE# #UNINDENT# n1 = len ( D1_list ) #NEWLINE# n2 = len ( D2_list ) #NEWLINE# x_binary = np . concatenate ( ( x [ D1_list , : ] , x [ D2_list , : ] ) ) #NEWLINE# y_binary = np . concatenate ( ( np . ones ( ( n1 , 1 ) ) , ( - np . ones ( ( n2 , 1 ) ) ) ) ) #NEWLINE# return ( x_binary , y_binary )