<s> import numpy as np <EOL> import cPickle as pickle <EOL> import matplotlib . pyplot as plt <EOL> plt . ion ( ) <EOL> fig_id = <NUM_LIT:0> <EOL> def GetFigId ( ) : <EOL> globals ( ) [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> return globals ( ) [ '<STR_LIT>' ] - <NUM_LIT:1> <EOL> def show_model_state ( model , step ) : <EOL> for i , node in enumerate ( model . node_list ) : <EOL> dims = int ( np . floor ( np . sqrt ( node . state . shape [ <NUM_LIT:0> ] ) ) ) <EOL> display_w ( node . sample . asarray ( ) , dims , <NUM_LIT:10> , <NUM_LIT:10> , i , title = node . name ) <EOL> def show ( mat , fig = <NUM_LIT:1> , title = '<STR_LIT>' ) : <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . imshow ( mat , interpolation = '<STR_LIT>' ) <EOL> plt . suptitle ( title ) <EOL> plt . colorbar ( ) <EOL> plt . draw ( ) <EOL> def scatter ( Y , s = <NUM_LIT:20> , c = '<STR_LIT:b>' , fig = <NUM_LIT:1> ) : <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . scatter ( Y [ : , <NUM_LIT:0> ] , Y [ : , <NUM_LIT:1> ] , s , c ) <EOL> plt . draw ( ) <EOL> def show_hist ( mat , fig ) : <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . hist ( mat . flatten ( ) , <NUM_LIT:100> ) <EOL> plt . draw ( ) <EOL> def show_stats ( edge , fig , title ) : <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . suptitle ( title ) <EOL> plt . hist ( edge . params [ '<STR_LIT>' ] . asarray ( ) . flatten ( ) , <NUM_LIT:100> ) <EOL> plt . draw ( ) <EOL> def display_hidden ( state , fig , title , log = False , prob = True ) : <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . suptitle ( title ) <EOL> plt . subplot ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> plt . hist ( state . mean ( axis = <NUM_LIT:1> ) , <NUM_LIT:100> ) <EOL> if prob : <EOL> plt . xlim ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . subplot ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> plt . hist ( state . flatten ( ) , <NUM_LIT:100> , log = log ) <EOL> if prob : <EOL> plt . xlim ( [ - <NUM_LIT:0.1> , <NUM_LIT> ] ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . subplot ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> plt . imshow ( state , cmap = plt . cm . gray , interpolation = '<STR_LIT>' , vmax = <NUM_LIT:1> , vmin = <NUM_LIT:0> ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . draw ( ) <EOL> def display_wsorted ( w , s , r , c , fig , vmax = None , vmin = None , dataset = '<STR_LIT>' , <EOL> title = '<STR_LIT>' ) : <EOL> if dataset == '<STR_LIT>' : <EOL> numvis = <NUM_LIT> <EOL> else : <EOL> numvis = w . shape [ <NUM_LIT:0> ] <EOL> numhid = w . shape [ <NUM_LIT:1> ] <EOL> sc = s <EOL> sr = numvis / s <EOL> padding = numhid - r * c <EOL> if isinstance ( w , np . ndarray ) : <EOL> w = w . T [ : , : sr * sc ] <EOL> else : <EOL> w = w . asarray ( ) . T [ : , : sr * sc ] <EOL> vh = w . reshape ( sr * numhid , sc ) <EOL> pvh = np . zeros ( ( sr , sc , r , c ) ) <EOL> pvh2 = np . zeros ( ( sr * r , sc * c ) ) <EOL> norm_list = [ ] <EOL> for i in range ( r ) : <EOL> for j in range ( c ) : <EOL> pvh [ : , : , i , j ] = vh [ ( i * c + j ) * sr : ( i * c + j + <NUM_LIT:1> ) * sr , : ] <EOL> norm = ( pvh [ : , : , i , j ] ** <NUM_LIT:2> ) . sum ( ) <EOL> norm_list . append ( ( norm , i , j ) ) <EOL> norm_list . sort ( reverse = True ) <EOL> index = <NUM_LIT:0> <EOL> for norm , i , j in norm_list : <EOL> ii = index / c <EOL> jj = index % c <EOL> pvh2 [ ii * sr : ( ii + <NUM_LIT:1> ) * sr , jj * sc : ( jj + <NUM_LIT:1> ) * sc ] = pvh [ : , : , i , j ] <EOL> index += <NUM_LIT:1> <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . suptitle ( title ) <EOL> plt . imshow ( pvh2 , cmap = plt . cm . gray , interpolation = '<STR_LIT>' , vmax = vmax , vmin = vmin ) <EOL> scale = <NUM_LIT:1> <EOL> xmax = sc * c <EOL> ymax = sr * r <EOL> color = '<STR_LIT:k>' <EOL> for x in range ( <NUM_LIT:0> , c ) : <EOL> plt . axvline ( x = x * sc / scale , ymin = <NUM_LIT:0> , ymax = ymax / scale , color = color ) <EOL> for y in range ( <NUM_LIT:0> , r ) : <EOL> plt . axhline ( y = y * sr / scale , xmin = <NUM_LIT:0> , xmax = xmax / scale , color = color ) <EOL> plt . draw ( ) <EOL> return pvh <EOL> def display_w ( w , s , r , c , fig , vmax = None , vmin = None , dataset = '<STR_LIT>' , title = '<STR_LIT>' ) : <EOL> if dataset == '<STR_LIT>' : <EOL> numvis = <NUM_LIT> <EOL> else : <EOL> numvis = w . shape [ <NUM_LIT:0> ] <EOL> numhid = w . shape [ <NUM_LIT:1> ] <EOL> sc = s <EOL> sr = numvis / s <EOL> if isinstance ( w , np . ndarray ) : <EOL> vh = w . T [ : , : sr * sc ] . reshape ( sr * numhid , sc ) <EOL> else : <EOL> vh = w . asarray ( ) . T [ : , : sr * sc ] . reshape ( sr * numhid , sc ) <EOL> pvh = np . zeros ( ( sr * r , sc * c ) ) <EOL> for i in range ( r ) : <EOL> for j in range ( c ) : <EOL> pvh [ i * sr : ( i + <NUM_LIT:1> ) * sr , j * sc : ( j + <NUM_LIT:1> ) * sc ] = vh [ ( i * c + j ) * sr : ( i * c + j + <NUM_LIT:1> ) * sr , : ] <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . title ( title ) <EOL> plt . imshow ( pvh , cmap = plt . cm . gray , interpolation = '<STR_LIT>' , vmax = vmax , vmin = vmin ) <EOL> scale = <NUM_LIT:1> <EOL> xmax = sc * c <EOL> ymax = sr * r <EOL> color = '<STR_LIT:k>' <EOL> if r > <NUM_LIT:1> : <EOL> for x in range ( <NUM_LIT:0> , c ) : <EOL> plt . axvline ( x = x * sc / scale , ymin = <NUM_LIT:0> , ymax = ymax / scale , color = color ) <EOL> if c > <NUM_LIT:1> : <EOL> for y in range ( <NUM_LIT:0> , r ) : <EOL> plt . axhline ( y = y * sr / scale , xmin = <NUM_LIT:0> , xmax = xmax / scale , color = color ) <EOL> plt . draw ( ) <EOL> return pvh <EOL> def display_convw2 ( w , s , r , c , fig , title = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> num_f , num_d = w . shape <EOL> assert s ** <NUM_LIT:2> * <NUM_LIT:3> == num_d <EOL> pvh = np . zeros ( ( s * r , s * c , <NUM_LIT:3> ) ) <EOL> for i in range ( r ) : <EOL> for j in range ( c ) : <EOL> pvh [ i * s : ( i + <NUM_LIT:1> ) * s , j * s : ( j + <NUM_LIT:1> ) * s , : ] = w [ i * c + j , : ] . reshape ( <NUM_LIT:3> , s , s ) . T <EOL> mx = pvh . max ( ) <EOL> mn = pvh . min ( ) <EOL> pvh = <NUM_LIT:255> * ( pvh - mn ) / ( mx - mn ) <EOL> pvh = pvh . astype ( '<STR_LIT>' ) <EOL> plt . figure ( fig ) <EOL> plt . suptitle ( title ) <EOL> plt . imshow ( pvh , interpolation = "<STR_LIT>" ) <EOL> scale = <NUM_LIT:1> <EOL> xmax = s * c <EOL> ymax = s * r <EOL> color = '<STR_LIT:k>' <EOL> for x in range ( <NUM_LIT:0> , c ) : <EOL> plt . axvline ( x = x * s / scale , ymin = <NUM_LIT:0> , ymax = ymax / scale , color = color ) <EOL> for y in range ( <NUM_LIT:0> , r ) : <EOL> plt . axhline ( y = y * s / scale , xmin = <NUM_LIT:0> , xmax = xmax / scale , color = color ) <EOL> plt . draw ( ) <EOL> return pvh <EOL> def display_convw ( w , s , r , c , fig , vmax = None , vmin = None , dataset = '<STR_LIT>' , title = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> numhid = w . shape [ <NUM_LIT:0> ] <EOL> size_x = s <EOL> size_y = s <EOL> num_channels = w . shape [ <NUM_LIT:1> ] / ( size_x * size_y ) <EOL> assert num_channels == <NUM_LIT:3> <EOL> assert w . shape [ <NUM_LIT:1> ] % size_x * size_y == <NUM_LIT:0> <EOL> if isinstance ( w , np . ndarray ) : <EOL> vh = w . reshape ( size_x * numhid * num_channels , size_y ) <EOL> else : <EOL> vh = w . asarray ( ) . reshape ( size_x * numhid * num_channels , size_y ) <EOL> pvh = np . zeros ( ( size_x * r , size_y * c , num_channels ) ) <EOL> for i in range ( r ) : <EOL> for j in range ( c ) : <EOL> for ch in range ( num_channels ) : <EOL> pvh [ i * size_x : ( i + <NUM_LIT:1> ) * size_x , j * size_y : ( j + <NUM_LIT:1> ) * size_y , ch ] = vh [ ( num_channels * ( i * c + j ) + ch ) * size_x : ( num_channels * ( i * c + j ) + ch + <NUM_LIT:1> ) * size_x , : ] <EOL> plt . figure ( fig ) <EOL> plt . clf ( ) <EOL> plt . title ( title ) <EOL> plt . imshow ( pvh , vmax = vmax , vmin = vmin ) <EOL> scale = <NUM_LIT:1> <EOL> xmax = size_x * c <EOL> ymax = size_y * r <EOL> color = '<STR_LIT:k>' <EOL> for x in range ( <NUM_LIT:0> , c ) : <EOL> plt . axvline ( x = x * size_x / scale , ymin = <NUM_LIT:0> , ymax = ymax / scale , color = color ) <EOL> for y in range ( <NUM_LIT:0> , r ) : <EOL> plt . axhline ( y = y * size_y / scale , xmin = <NUM_LIT:0> , xmax = xmax / scale , color = color ) <EOL> plt . draw ( ) <EOL> return pvh </s>
