嘿,我对整个RBM熵/能量训练有点陌生,在理解方面遇到了一些困难,并试图弄清楚是否值得付出努力去理解。
不能用标准的梯度下降算法很容易地训练 RBM 吗?当前的方式是否更快?
这是我的意思的一些示例 Theano 代码:
def rbm(inputs, shape, cost=0, last_cost=1):
X = T.vector() # input
W = theano.shared(np.zeros(shape)) # weights
b = theano.shared(np.zeros( shape[1] )) # bias to hidden
B = theano.shared(np.zeros( shape[0] )) # bias to reconstruction
H = sigmoid(T.dot(X, W) + b) # hidden activation
Y = T.dot(H, W.T) + B # reconstruction
L = ((X - Y) ** 2).mean() # loss function
G = T.grad(L, W), T.grad(L, b), T.grad(L, B) # gradients
a = .1 # learning rate
U = [(W, W - a*G[0]), (b, b - a*G[1]), (B, B - a*G[2])] # shared updates
train = theano.function([X], L, updates=U) # training function
while abs(last_cost-cost) > 0.01:
last_cost, cost = cost, 0
for input in inputs: cost += train(input)
return W.get_value(), b.get_value()
是的,这段代码非常粗糙。