我正在实现一个带整流线性单元的受限玻尔兹曼机。我还没有在任何地方找到一个简单的实现,所以想问一下是否有人会验证设计。
这是CD1的计算:
def propup(self, vis):
activation = numpy.dot(vis, self.W) + self.hbias
# ReLU activation of hidden units
return activation * (activation > 0)
def sample_h_given_v(self, v0_sample):
h1_mean = self.propup(v0_sample)
# Sampling from a rectified Normal distribution
h1_sample = numpy.maximum(0, h1_mean + numpy.random.normal(0, sigmoid(h1_mean)))
return [h1_mean, h1_sample]
def propdown(self, hid):
activation = numpy.dot(hid, self.W.T) + self.vbias
return sigmoid(activation)
def sample_v_given_h(self, h0_sample):
v1_mean = self.propdown(h0_sample)
v1_sample = self.numpy_rng.binomial(size=v1_mean.shape, n=1, p=v1_mean)
return [v1_mean, v1_sample]
这就是我计算梯度的方式:
def get_cost_updates(self, lr, decay, mom, l1_penalty, p_noise, epoch, persistent=None, k=1):
ph_mean, ph_sample = self.sample_h_given_v(input)
nv_means, nv_samples,nh_means, nh_samples = self.gibbs_hvh(ph_sample)
W_grad = numpy.dot(self.input.T, ph_mean) - numpy.dot(nv_samples.T, nh_means)
vbias_grad = numpy.mean(self.input - nv_samples, axis=0)
hbias_grad = numpy.mean(ph_mean - nh_means, axis=0)
我的问题是,如何将这些分层到 DBN 中?
目的是构建一个自动编码器,但我不知道如何处理可见单位也是第二层中的实数变量。