Besides that, use subtensor and batched_dot can further vectorize things.

A = T.batched_dot(A[::2], A[1::2]) # if len(A)|1 == 0



This should work well as long as len(A) contains only small prime factors

On Wednesday, February 15, 2017 at 9:02:34 PM UTC+8, Kiuhnm Mnhuik wrote:
>
> I don't know how Theano works internally, so this might not work.
> First compute A[0] = A[0] x A[1]; A[1] = A[2] x A[3]; A[2] = A[4] x A[5]; 
> etc...
> Then repeat until you have just one matrix. If N is a power of 2 it's 
> easier...
>
> 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