BTW, be careful that

for k in range(0, K-1):


loops from 0 to K-2. Also, you can drop the first term when it's 0.

On Wednesday, February 15, 2017 at 12:33:40 PM UTC+1, albit...@gmail.com 
wrote:
>
> Hi, 
>
> *Goal *
>   In the context of a learning algorithm, I want to calculate the 
> product:  
>
>                                 B = A[K-1] x A[K-1] x .... A[0], 
>    
> where each A[k] is a (sparse, if it helps to know) matrix of size N*N and 
> "x" denotes the theano.dot() product . 
>
> *Question *
>  * How can I do that for fairly large matrices, say each A[k] is *100x100* 
> ? *
>
> *Things I've tried (t is theano and tt is theano.tensor):*
>
>    - *For loop*
>
> B = tt.eye(n=self.N, m=N)for k in range(0, K-1):
>      B = t.dot(A[k], B)
>
> *Pro*: simple, works fine for N = 10
> *Con*: If N >> (say N = 100), I get this error: 
>   File "/usr/local/lib/python2.7/dist-packages/theano/gof/graph.py", line 
> 392, in __init__self.auto_name = 'auto_' + str(next(self.__count__))
> RuntimeError: maximum recursion depth exceeded while getting the str of an 
> object
>
>
>    - *Theano scan or reduce*
>    
>    results, _ = t.scan(fn=lambda k, tmp: tt.dot(A[k], tmp),
>                              outputs_info=tt.eye(n=N, m=N),
>                              sequences=[tt.arange(K, dtype='int64')])
>    B = results[-1]
>    
>    
>
> *Pro*: works even for large matrices
> *Con*: Epoch become incredibly slow (200,000 seconds instead of 500~1,000)
>
>
>
> Any help or advice would be much appreciated. 
>
> Thanks
> Oussama
>
>
>

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to