Two quick points: - It is better not to create a new RandomStreams() object each time, either re-use the same one, or use different seeds for different RandomStreams instances - The issue in the first example is that the output of the step function should always have the same shape. It has nothing to do with random numbers.
The following should work: rng = RandomStreams() def step(i): sample = rng.binomial(size=(i,)) return sample.mean() And the following would fail: def step(i): return tensor.zeros(shape=(i,)) On Thu, Sep 29, 2016, 杨培 wrote: > When I use theano loop with RandomStream to generate random number, > theano compile fail with “MissingInput”。 > > I Google this problem, and I found : > > - a issue(https://github.com/Theano/Theano/issues/3437)。This issue said > we cannot use RandomStream with symbolic shape in scan。 > > But I also found : > > - a documentation int Theano > > (http://deeplearning.net/software/theano/library/scan.html#using-shared-variables-gibbs-sampling),the > > code in the documentation use RandomStream with symbolic shape in scan。 > > So,how to use theano scan with RandomStream。Thanks for your help > > here is my code。this code compile failed > > > - import theano; > - from theano import tensor as T; > - import numpy as np; > - > - from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams; > - > - x=T.ivector(); > - > - def step(i): > - sample=RandomStreams().binomial(size=(i,)); > - return sample; > - > - result,_=theano.scan(fn=step,outputs_info=None, > - sequences=[x]); > - > - f=theano.function([x],result); > - > - x_val=np.array([1,2,3],dtype='int32'); > - print f(x_val); > > > this code work fine > > - import theano; > - from theano import tensor as T; > - import numpy as np; > - > - from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams; > - > - x=T.ivector(); > - len=x.shape[0]; > - > - def step(i): > - len_=len; > - sample=RandomStreams().binomial(size=(len_,)); > - return sample; > - > - result,_=theano.scan(fn=step,outputs_info=None, > - sequences=[x]); > - > - f=theano.function([x],result); > - > > > - x_val=np.array([1,2,3],dtype='int32'); > - print f(x_val); > > > > > > -- > > --- > You received this message because you are subscribed to the Google Groups > "theano-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- Pascal -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
