Тео градиентного спуска и функция стоимости вопроса - PullRequest
0 голосов
/ 23 сентября 2019

Я получаю 'ValueError: Несоответствие входного размера.'для моей имплантации с градиентным спуском.

Я попытался транспонировать вход с помощью np.transpose, но размер остался неизменным.

import theano
from theano import tensor as T
import numpy as np
import math 
import cmath 
global W
l=1

def inputvector(theta,phi,zeta):
    global xreal,ximag
    xreal=np.asarray([math.cos(2*theta-phi)*math.cos(phi), math.cos(2*theta-phi)*math.sin(phi)*math.cos(zeta), math.cos(2*theta-phi)*math.sin(phi)*math.sin(zeta)])
    ximag=np.asarray([-math.sin(2*theta-phi)*math.sin(phi), math.sin(2*theta-phi)*math.cos(phi)*math.cos(zeta), math.sin(2*theta-phi)*math.cos(phi)*math.sin(zeta)])   
    return xreal,ximag


def weights(w11r,w12r,w13r,w21r,w22r,w23r,w31r,w32r,w33r,w11i,w12i,w13i,w21i,w22i,w23i,w31i,w32i,w33i):
    global W
    W = theano.shared(np.asarray([w11r, w12r, w13r,w21r,w22r,w23r,w31r,w32r,w33r,w11i,w12i,w13i,w21i,w22i,w23i,w31i,w32i,w33i]), 'W')
    return W

xreal=T.dvector('xreal')
ximag=T.dvector('ximag')
weights(np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1),np.random.rand(1))

cost=T.mean(T.sqr(np.dot(W[0:3],xreal)-np.dot(W[9:12],ximag)))

gradients = theano.tensor.grad(cost, [W])
W_updated = W - (0.1 * gradients[0])
updates = [(W, W_updated)]
train=theano.function(inputs=[xreal,ximag],outputs=cost,updates=updates,allow_input_downcast=True)
for i in range(100):
    inputvector(np.random.rand(1),np.random.rand(1),np.random.rand(1))
    train(xreal,ximag)
    print (W.get_value())

Я не вижу причин, по которым размеры входных данныхдолжен не согласиться.И я не думаю, что у меня даже есть 4 входа для начала.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...