#NEWLINE# @ no_debug_mode #NEWLINE# def check_sample_correctishness_c01b( f ) : #NEWLINE# #INDENT# batch_size = 5 #NEWLINE# rows = 32 #NEWLINE# cols = 30 #NEWLINE# channels = 3 #NEWLINE# pool_rows = 2 #NEWLINE# pool_cols = 3 #NEWLINE# rng = np . random . RandomState ( [ 2012 , 9 , 26 ] ) #NEWLINE# zv = ( ( rng . randn ( channels , rows , cols , batch_size ) . astype ( config . floatX ) * 2.0 ) - 3.0 ) #NEWLINE# top_down_v = rng . randn ( channels , ( rows / pool_rows ) , ( cols / pool_cols ) , batch_size ) . astype ( config . floatX ) #NEWLINE# z_th = T . TensorType ( broadcastable = ( False , False , False , False ) , dtype = config . floatX ) ( ) #NEWLINE# z_th . name = 'z_th' #NEWLINE# z_th . tag . test_value = zv #NEWLINE# top_down_th = T . TensorType ( broadcastable = ( False , False , False , False ) , dtype = config . floatX ) ( ) #NEWLINE# top_down_th . name = 'top_down_th' #NEWLINE# top_down_th . tag . test_value = top_down_v #NEWLINE# theano_rng = MRG_RandomStreams ( rng . randint ( 2147462579 ) ) #NEWLINE# ( p_th , h_th , p_sth , h_sth ) = f ( z_th , ( pool_rows , pool_cols ) , top_down_th , theano_rng ) #NEWLINE# prob_func = function ( [ z_th , top_down_th ] , [ p_th , h_th ] ) #NEWLINE# ( pv , hv ) = prob_func ( zv , top_down_v ) #NEWLINE# sample_func = function ( [ z_th , top_down_th ] , [ p_sth , h_sth ] ) #NEWLINE# acc_p = ( 0.0 * pv ) #NEWLINE# acc_h = ( 0.0 * hv ) #NEWLINE# buckets = 10 #NEWLINE# bucket_width = ( 1.0 / float ( buckets ) ) #NEWLINE# for i in xrange ( buckets ) : #NEWLINE# #INDENT# lower_lim = ( i * bucket_width ) #NEWLINE# upper_lim = ( ( i + 1 ) * bucket_width ) #NEWLINE# assert np . any ( ( ( pv >= lower_lim ) * ( pv < upper_lim ) ) ) #NEWLINE# assert np . any ( ( ( hv >= lower_lim ) * ( hv < upper_lim ) ) ) #NEWLINE# #UNINDENT# assert ( upper_lim == 1.0 ) #NEWLINE# for i in xrange ( 10000 ) : #NEWLINE# #INDENT# ( ps , hs ) = sample_func ( zv , top_down_v ) #NEWLINE# assert ( ps . shape == pv . shape ) #NEWLINE# assert ( hs . shape == hv . shape ) #NEWLINE# acc_p += ps #NEWLINE# acc_h += hs #NEWLINE# #UNINDENT# est_p = ( acc_p / float ( ( i + 1 ) ) ) #NEWLINE# est_h = ( acc_h / float ( ( i + 1 ) ) ) #NEWLINE# pd = np . abs ( ( est_p - pv ) ) #NEWLINE# hd = np . abs ( ( est_h - hv ) ) #NEWLINE# assert ( max ( pd . max ( ) , hd . max ( ) ) < 0.17 ) #NEWLINE# assert np . all ( ( ( ps == 0 ) + ( ps == 1 ) ) ) #NEWLINE# assert np . all ( ( ( hs == 0 ) + ( hs == 1 ) ) ) #NEWLINE# for k in xrange ( batch_size ) : #NEWLINE# #INDENT# for i in xrange ( ps . shape [ 1 ] ) : #NEWLINE# #INDENT# for j in xrange ( ps . shape [ 2 ] ) : #NEWLINE# #INDENT# for l in xrange ( channels ) : #NEWLINE# #INDENT# p = ps [ ( l , i , j , k ) ] #NEWLINE# h = hs [ l , ( i * pool_rows ) : ( ( i + 1 ) * pool_rows ) , ( j * pool_cols ) : ( ( j + 1 ) * pool_cols ) , k ] #NEWLINE# assert ( h . shape == ( pool_rows , pool_cols ) ) #NEWLINE# assert ( p == h . max ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# ' If you made it to here, it\'s correctish\n     (cant tell if samples are perfectly "correct") '