def test_stochasatic_pool_samples():
 batch = 1
 channel = 1
 pool_shape = (2, 2)
 pool_stride = (2, 2)
 image_shape = (2, 2)
 rng = numpy.random.RandomState(12345)
 data = rng.uniform(0, 10, size=(batch, channel, image_shape[0], image_shape[1])).astype('float32')
 x = theano.tensor.tensor4()
 s_max = stochastic_max_pool_bc01(x, pool_shape, pool_stride, image_shape)
 f = theano.function([x], s_max)
 samples = []
 for i in xrange(300):
  samples.append(numpy.asarray(f(data))[(0, 0, 0, 0)])
 counts = Counter(samples)
 data = data.reshape(numpy.prod(image_shape))
 data.sort()
 data = data[::(-1)]
 for i in range((len(data) - 1)):
  assert (counts[data[i]] >= counts[data[(i + 1)]])

def test_stochasatic_pool_samples ( ) : batch = 1 channel = 1 pool_shape = ( 2 , 2 ) pool_stride = ( 2 , 2 ) image_shape = ( 2 , 2 ) rng = numpy . random . RandomState ( 12345 ) data = rng . uniform ( 0 , 10 , size = ( batch , channel , image_shape [ 0 ] , image_shape [ 1 ] ) ) . astype ( 'float32' ) x = theano . tensor . tensor4 ( ) s_max = stochastic_max_pool_bc01 ( x , pool_shape , pool_stride , image_shape ) f = theano . function ( [ x ] , s_max ) samples = [ ] for i in xrange ( 300 ) : samples . append ( numpy . asarray ( f ( data ) ) [ ( 0 , 0 , 0 , 0 ) ] ) counts = Counter ( samples ) data = data . reshape ( numpy . prod ( image_shape ) ) data . sort ( ) data = data [ : : ( - 1 ) ] for i in range ( ( len ( data ) - 1 ) ) : assert ( counts [ data [ i ] ] >= counts [ data [ ( i + 1 ) ] ] )
check if the order of frequency of samples from stochastic max pool are same as the order of input values .