I did not test this, because I don't have data or code for one_step, but it
would be something like:
def loop_over_examples(x):
# hidden and outputs of the entire sequence
[h_vals, o_vals], inner_updates = theano.scan(fn=one_step,
sequences = dict(input = x, taps=[0]),
outputs_info = [h0, None], # corresponds to return type of
one_step
non_sequences = [W_ih, W_hh, b_h, W_ho, b_o]
)
return o_vals, inner_updates
O_vals, updates = theano.scan(fn = loop_over_examples,
sequences = dict(input = V, taps=[0]),
outputs_info = None
)
f = theano.function(inputs=[V], outputs=O_vals, updates=updates)
On Tue, Oct 11, 2016, Arzoo wrote:
> Hi Pascal,
>
> I am trying to use nested scans in theano and getting Missing Input Error.
> It looks like in the document
> http://christianherta.de/lehre/dataScience/machineLearning/neuralNetworks/recurrentNeuralNetworks.php
> they ignore the updates from the inner scan as well as the outer scan.
> But if I do something smiliar, it return the Missing Input Error again.
>
> I was wondering if you could elaborate on your solution above.
> Maybe with an example from the documentation :
>
> def loop_over_examples(x):
> # hidden and outputs of the entire sequence
> [h_vals, o_vals], _ = theano.scan(fn=one_step,
> sequences = dict(input = x, taps=[0]),
> outputs_info = [h0, None], # corresponds to return type of
> one_step
> non_sequences = [W_ih, W_hh, b_h, W_ho, b_o]
> )
> return o_vals# return y_vals
>
>
> O_vals, _ = theano.scan(fn = loop_over_examples,
> sequences = dict(input = V, taps=[0]),
> outputs_info = None
> )
> f = theano.function(inputs=[V], outputs=O_vals)
>
>
> How are the updates passed from the inner scan to outer scan?
>
> Thanks
> Arzoo
>
>
>
> On Thursday, September 29, 2016 at 10:16:38 PM UTC-4, Pascal Lamblin wrote:
> >
> > On Fri, Sep 30, 2016, 杨培 wrote:
> > > Thanks。
> > > As your answer。 The problem is I ignore the update dictionary returned
> > by
> > > theano scan。
> > > Here,I have a new question。
> > > In my program,this code is in another scan loop, and I have used the
> > update
> > > dictionary for the outter scan loop。
> > > So,how I can past the update dictionary of RandomStream to theano
> > function
> > > method。
> >
> > In the step function of the outer loop, return the updates dictionary
> > coming from the inner scan.
> > Then, pass the updates dictionary coming from the outer scan to
> > theano.function.
> >
> > >
> > > 2016-09-30 5:57 GMT+08:00 Pascal Lamblin <[email protected]
> > <javascript:>>:
> > >
> > > > Also, never ignore the updates returned by theano.scan!
> > > > In other words, always do:
> > > >
> > > > result, updates = theano.scan(...)
> > > > f = theano.function(..., updates=updates)
> > > >
> > > > and never:
> > > >
> > > > result, _ = theano.scan(...)
> > > >
> > > > 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] <javascript:>.
> > > > > For more options, visit https://groups.google.com/d/optout.
> > > >
> > > >
> > > > --
> > > > Pascal
> > > >
> > > > --
> > > >
> > > > ---
> > > > You received this message because you are subscribed to a topic in the
> > > > Google Groups "theano-users" group.
> > > > To unsubscribe from this topic, visit https://groups.google.com/d/
> > > > topic/theano-users/InLNaYdIxak/unsubscribe.
> > > > To unsubscribe from this group and all its topics, send an email to
> > > > [email protected] <javascript:>.
> > > > For more options, visit https://groups.google.com/d/optout.
> > > >
> > >
> > > --
> > >
> > > ---
> > > 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] <javascript:>.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > Pascal
> >
--
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.