ich möchte über die 1. dimension mehrerer mehrdim. arrays mit der theano scan function iterieren :
Mein example code ist:
[codebox=python file=Unbenannt.txt]import numpy as np
import theano
import theano.tensor as T
N = 100
M = 50
D = 2
EPhiTPhi = np.zeros((M,M))
MU = T.matrix("MU")
SIGMA_trf = T.matrix("SIGMA_trf")
Z_n_W = T.matrix("Z_n_W")
MU_S_hat_plus = T.matrix("MU_S_hat_plus")
def EPhiTPhi_loop(EPhiTPhi, MU, SIGMA_trf, Z_n_W, MU_S_hat_plus):
EPhiTPhi = EPhiTPhi + Z_n_W * (T.exp(-0.5 * (MU_S_hat_plus**2 * SIGMA_trf[:, :, None]).sum(2)) * T.cos((MU_S_hat_plus * MU[:, :, None]).sum(2))
EPhiTPhi_out, _ = theano.scan(EPhiTPhi_loop,
outputs_info = EPhiTPhi,
sequences = [MU, SIGMA_trf, Z_n_W],
non_sequences = [MU_S_hat_plus])
OUT = theano.function(inputs=[MU, SIGMA_trf, Z_n_W], outputs=EPhiTPhi_out)
MU = np.zeros((N,D))
SIGMA_trf = np.zeros((N,D))
Z_n_W = np.zeros((N,M,M))
MU_S_hat_minus = np.zeros((M,M,D)) [/code]
Soweit so gut.
Ich erhalte aber hier schon den Fehler:
Code: Alles auswählen
runfile('C:/Users/flo9fe/untitled1.py', wdir='C:/Users/flo9fe')
Traceback (most recent call last):
File "<ipython-input-1-3dd424f4749a>", line 1, in <module>
runfile('C:/Users/flo9fe/untitled1.py', wdir='C:/Users/flo9fe')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/flo9fe/untitled1.py", line 22, in <module>
non_sequences = [MU_S_hat_minus, MU_S_hat_plus])
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 "C:/Users/flo9fe/untitled1.py", line 16, in EPhiTPhi_loop
EPhiTPhi = EPhiTPhi + Z_n_W * (T.exp(-0.5 * (MU_S_hat_minus**2 * SIGMA_trf[:, :, None]).sum(2)) * T.cos((MU_S_hat_minus * MU[:, :, None]).sum(2)) + T.exp(-0.5 * (MU_S_hat_plus**2 * SIGMA_trf[:, :, None]).sum(2)) * T.cos((MU_S_hat_plus * MU[:, :, 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 159, in __init__
(i, j, len(input_broadcastable)))
ValueError: new_order[1] is 1, but the input only has 1 axes.