Hi, does your code still serve the same purpose as that from your previous 
post (https://groups.google.com/forum/#!topic/theano-users/gSZLwu8UrO0)?

On Wednesday, 12 April 2017 13:04:30 UTC+2, [email protected] wrote:
>
> Hello,
>
> I try to loop with the scan function from theano.
> I have a working example:
>
>
>    1. import numpy as np
>    2. import theano
>    3. import theano.tensor as T 
>    4.  
>    5. N = 100
>    6. M = 50
>    7. D = 2
>    8. EPhiTPhi = np.zeros((M,M))
>    9. Z_n_W = T.dtensor3("Z_n_W")   
>    10. MU_S_hat_minus = T.dtensor3("MU_S_hat_minus") 
>    11.              
>    12. def EPhiTPhi_loop(EPhiTPhi, Z_n_W, MU_S_hat_minus):
>    13.    EPhiTPhi = EPhiTPhi + Z_n_W * (T.exp(-0.5 * (MU_S_hat_minus**2).
>    sum(2)));  
>    14.    return EPhiTPhi
>    15. 
>    16. EPhiTPhi_out, _ = theano.scan(EPhiTPhi_loop,
>    17.                        outputs_info = EPhiTPhi,
>    18.                        sequences = [Z_n_W],
>    19.                        non_sequences = [MU_S_hat_minus])
>    20. 
>    21. OUT = theano.function(inputs=[Z_n_W, MU_S_hat_minus], outputs = 
>    EPhiTPhi_out)
>    22. 
>    23.  
>    24. Z_n_W = np.ones((N,M,M))     
>    25. MU_S_hat_minus = np.zeros((M,M,D))    
>    26. #EPhiTPhi = EPhiTPhi.astype(np.float32)
>    27. #Z_n_W = Z_n_W.astype(np.float32)
>    28. #MU_S_hat_minus = MU_S_hat_minus.astype(np.float32)
>    29. 
>    30. LIST = {'Z_n_W': Z_n_W, 'MU_S_hat_minus': MU_S_hat_minus}
>    31. 
>    32. TEST = OUT(**LIST)
>    
>
> When I try to extend it with one additional sequence variable of size 
> (N,D), SIGMA_trf, I expect to hand over to EPhiTPhi_loop a vector with 
> size(1,D).
> When i want to make a calculation, where i have to blow up this vector to 
> SIGMA_trf[None, None, :], I get an error.
> Her first the extenden code.
>
>
>    1. import numpy as np
>    2. import theano
>    3. import theano.tensor as T 
>    4.  
>    5. N = 100
>    6. M = 50
>    7. D = 2
>    8. EPhiTPhi = np.zeros((M,M))
>    9. SIGMA_trf = T.dmatrix("SIGMA_trf")  
>    10. Z_n_W = T.dtensor3("Z_n_W")   
>    11. MU_S_hat_minus = T.dtensor3("MU_S_hat_minus") 
>    12. 
>    13.              
>    14. def EPhiTPhi_loop(EPhiTPhi, SIGMA_trf, Z_n_W, MU_S_hat_minus):
>    15.    EPhiTPhi = EPhiTPhi + Z_n_W * (T.exp(-0.5 * (MU_S_hat_minus**2 * 
>    SIGMA_trf[None, None, :]).sum(2)));  
>    16.    return EPhiTPhi
>    17. 
>    18. EPhiTPhi_out, _ = theano.scan(EPhiTPhi_loop,
>    19.                        outputs_info = EPhiTPhi,
>    20.                        sequences = [SIGMA_trf, Z_n_W],
>    21.                        non_sequences = [MU_S_hat_minus])
>    22. 
>    23. OUT = theano.function(inputs=[SIGMA_trf, Z_n_W, MU_S_hat_minus], 
>    outputs = EPhiTPhi_out)
>    24. 
>    25. SIGMA_trf = np.zeros((N,D))    
>    26. Z_n_W = np.ones((N,M,M))     
>    27. MU_S_hat_minus = np.zeros((M,M,D))    
>    28. #EPhiTPhi = EPhiTPhi.astype(np.float32)
>    29. #Z_n_W = Z_n_W.astype(np.float32)
>    30. #MU_S_hat_minus = MU_S_hat_minus.astype(np.float32)
>    31. 
>    
>    32.  
>    33. LIST = {'SIGMA_trf': SIGMA_trf, 'Z_n_W': Z_n_W, 'MU_S_hat_minus': 
>    MU_S_hat_minus}
>    34. 
>    35. TEST = OUT(**LIST)
>    
>
> The error is:
>
> Traceback (most recent call last):
>
>   File "<ipython-input-1-dd8e5b5e726c>", line 22, in <module>
>     non_sequences = [MU_S_hat_minus])
>
>   File 
> "C:\ProgramData\Anaconda3\lib\site-packages\theano\scan_module\scan.py", 
> line 773, in scan
>     condition, outputs, updates = scan_utils.get_updates_and_outputs(fn(*
> args))
>
>   File "<ipython-input-1-dd8e5b5e726c>", line 15, in EPhiTPhi_loop
>     EPhiTPhi = EPhiTPhi + Z_n_W * (T.exp(-0.5 * (MU_S_hat_minus**2 * 
> SIGMA_trf[None, None, :]).sum(2)));
>
>   File "C:\ProgramData\Anaconda3\lib\site-packages\theano\tensor\var.py", 
> line 560, in __getitem__
>     view = self.dimshuffle(pattern)
>
>   File "C:\ProgramData\Anaconda3\lib\site-packages\theano\tensor\var.py", 
> line 355, in dimshuffle
>     pattern)
>
>   File 
> "C:\ProgramData\Anaconda3\lib\site-packages\theano\tensor\elemwise.py", 
> line 177, in __init__
>     (input_broadcastable, new_order))
>
> ValueError: ('You cannot drop a non-broadcastable dimension.', ((False, 
> False), ('x', 'x', 0)))
>
>
> Thanks for your help.
>

-- 

--- 
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.

Reply via email to