无成本函数,类型错误:未知参数类型:<class'努比·恩达雷'>

2024-05-23 19:50:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的,只是学习而已。我有一个python中的ANN,我正在Theano中实现作为学习过程。我在用Spyder。在

然后Theano抛出一个错误:TypeError:Unknown parameter type:class'努比·恩达雷'

我不知道错误在哪里。是在成本函数中还是在梯度下降中?这其中的典型原因是什么?在

这是我的代码:

X = T.dmatrix()
y = T.dmatrix()

X_input = np.genfromtxt('X.csv',delimiter=',') #5000x195
y_input = np.genfromtxt('y.csv',delimiter=',')  #5000x75

input_layer_size, hidden_layer_size_1, hidden_layer_size_2, y_size = 195, 15, 15, 75

theta1 = theano.shared(np.array(np.random.rand(hidden_layer_size_1, (input_layer_size+1)), dtype=theano.config.floatX))
theta2 = theano.shared(np.array(np.random.rand(hidden_layer_size_2, (hidden_layer_size_1+1)), dtype=theano.config.floatX))
theta3 = theano.shared(np.array(np.random.rand(y_size, hidden_layer_size_2+1), dtype=theano.config.floatX))

def computeCost(X, y, w1, w2, w3):
    m = X.shape[0]
    b = T.ones((m,1))
    a_1 = T.concatenate([b, X], axis=1)
    z_2 = T.dot(a_1, T.transpose(w1))
    a_2 = T.nnet.nnet.sigmoid(z_2)
    a_2 = T.concatenate([b, a_2], axis=1)
    z_3 = T.dot(a_2, T.transpose(w2))
    a_3 = T.nnet.nnet.sigmoid(z_3)
    a_3 = T.concatenate([b, a_3], axis=1)
    z_4 = T.dot(a_3, T.transpose(w3))
    h   = T.nnet.nnet.sigmoid(z_4)
    cost = T.sum(-y * T.log(h) - (1-y) * T.log(1-h))/m
    return cost

fc = computeCost(X, y, theta1, theta2, theta3)

def grad_desc(cost, theta):
    alpha = 0.1 #learning rate
    return theta - (alpha * T.grad(cost, wrt=theta))

cost = theano.function(inputs=[X_input, y_input], outputs=fc, updates=[
        (theta1, grad_desc(fc, theta1)),
        (theta2, grad_desc(fc, theta2)),
        (theta3, grad_desc(fc, theta3))])

我的上一个代码生成了此错误:

^{pr2}$

Tags: layerinputsize错误nptheanodeschidden
1条回答
网友
1楼 · 发布于 2024-05-23 19:50:36

在您的theano.function中,您的输入是numpy数组(X\u输入和y\u输入)。您希望输入是符号变量,例如:

cost = theano.function(inputs=[X, y], outputs=fc, updates=[

这将创建一个可以用numpy数组调用的函数来执行实际计算,如:

^{pr2}$

相关问题 更多 >