<s> import theano <EOL> import theano . tensor as T <EOL> import numpy as np <EOL> probabilities = T . vector ( ) <EOL> nb_samples = T . iscalar ( ) <EOL> rng = T . shared_randomstreams . RandomStreams ( <NUM_LIT> ) <EOL> def sample_from_pvect ( pvect ) : <EOL> """<STR_LIT>""" <EOL> onehot_sample = rng . multinomial ( n = <NUM_LIT:1> , pvals = pvect ) <EOL> sample = onehot_sample . argmax ( ) <EOL> return sample <EOL> def set_p_to_zero ( pvect , i ) : <EOL> """<STR_LIT>""" <EOL> new_pvect = T . set_subtensor ( pvect [ i ] , <NUM_LIT:0.> ) <EOL> new_pvect = new_pvect / new_pvect . sum ( ) <EOL> return new_pvect <EOL> def step ( p ) : <EOL> sample = sample_from_pvect ( p ) <EOL> new_p = set_p_to_zero ( p , sample ) <EOL> return new_p , sample <EOL> output , updates = theano . scan ( fn = step , <EOL> outputs_info = [ probabilities , None ] , <EOL> n_steps = nb_samples ) <EOL> modified_probabilities , samples = output <EOL> f = theano . function ( inputs = [ probabilities , nb_samples ] , <EOL> outputs = [ samples ] , <EOL> updates = updates ) <EOL> test_probs = np . asarray ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.1> ] , dtype = theano . config . floatX ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> print ( f ( test_probs , <NUM_LIT:2> ) ) </s>
