def gen_data(min_length=MIN_LENGTH, max_length=MAX_LENGTH, n_batch=N_BATCH):
 X = np.concatenate([np.random.uniform(size=(n_batch, max_length, 1)), np.zeros((n_batch, max_length, 1))], axis=(-1))
 mask = np.zeros((n_batch, max_length))
 y = np.zeros((n_batch,))
 for n in range(n_batch):
  length = np.random.randint(min_length, max_length)
  mask[n, :length] = 1
  X[n, length:, 0] = 0
  X[(n, np.random.randint((length / 10)), 1)] = 1
  X[(n, np.random.randint((length / 2), length), 1)] = 1
  y[n] = np.sum((X[n, :, 0] * X[n, :, 1]))
 X -= X.reshape((-1), 2).mean(axis=0)
 y -= y.mean()
 return (X.astype(theano.config.floatX), y.astype(theano.config.floatX), mask.astype(theano.config.floatX))

def gen_data ( min_length = MIN_LENGTH , max_length = MAX_LENGTH , n_batch = N_BATCH ) : X = np . concatenate ( [ np . random . uniform ( size = ( n_batch , max_length , 1 ) ) , np . zeros ( ( n_batch , max_length , 1 ) ) ] , axis = ( - 1 ) ) mask = np . zeros ( ( n_batch , max_length ) ) y = np . zeros ( ( n_batch , ) ) for n in range ( n_batch ) : length = np . random . randint ( min_length , max_length ) mask [ n , : length ] = 1 X [ n , length : , 0 ] = 0 X [ ( n , np . random . randint ( ( length / 10 ) ) , 1 ) ] = 1 X [ ( n , np . random . randint ( ( length / 2 ) , length ) , 1 ) ] = 1 y [ n ] = np . sum ( ( X [ n , : , 0 ] * X [ n , : , 1 ] ) ) X -= X . reshape ( ( - 1 ) , 2 ) . mean ( axis = 0 ) y -= y . mean ( ) return ( X . astype ( theano . config . floatX ) , y . astype ( theano . config . floatX ) , mask . astype ( theano . config . floatX ) )
this function produces a semi-redundant batch of training samples from the location p in the provided string .