0
我写了一个简单的神经网络来学习AND门。我想知道为什么我从来没有成本的降低,预测总是0.5:Theano学习与门
import numpy as np
import theano
import theano.tensor as T
inputs = [[0,0], [1,1], [0,1], [1,0]]
outputs = [[0], [1], [0], [0]]
x = theano.shared(value=np.asarray(inputs), name='x')
y = theano.shared(value=np.asarray(outputs), name='y')
alpha = 0.1
w_array = np.asarray(np.random.uniform(low=-1, high=1, size=(2, 1)), dtype=theano.config.floatX)
w = theano.shared(value=w_array, name='w', borrow=True)
output = T.nnet.sigmoid(T.dot(x, w))
cost = T.sum((y - output) ** 2)
updates = [(w, w - alpha * T.grad(cost, w))]
train = theano.function(inputs=[], outputs=[], updates=updates)
test = theano.function(inputs=[], outputs=[output])
calc_cost = theano.function(inputs=[], outputs=[cost])
for i in range(60000):
if (i+1) % 10000 == 0:
print(i+1)
print(calc_cost())
train()
print(test())
输出始终是相同的:
10000
[array(1.0)]
20000
[array(1.0)]
30000
[array(1.0)]
40000
[array(1.0)]
50000
[array(1.0)]
60000
[array(1.0)]
[array([[ 0.5],
[ 0.5],
[ 0.5],
[ 0.5]])]
它似乎总是预测0.5无论输入因学习
期间费用不偏离1。如果我切换输出,[[0], [1], [1], [1]]
学习或门,我得到了正确的预测,并正确地降低成本
为什么不改变标签时相同的模型工作,学习或门?我认为这也会有一个负面倾斜的分隔符,不会越过原点? – Simon
如果您认为正在使用分离器会给出正确的“负值”,或门分离器可能会跨越原点。它不会是最好的,但足够体面使用。 – lejlot