rbm.py 文件源码

python
阅读 87 收藏 0 点赞 0 评论 0

项目:weather-modelling 作者: flipdazed 项目源码 文件源码
def getPseudoLikelihoodCost(self, updates):
        """Stochastic approximation to the pseudo-likelihood"""

        # index of bit i in expression p(x_i | x_{\i})
        bit_i_idx = theano.shared(value=0, name='bit_i_idx')

        # binarize the inputs image by rounding to nearest integer
        xi = T.round(self.inputs)

        # calculate free energy for the given bit configuration
        fe_xi = self.freeEnergy(xi)

        # flip bit x_i of matrix xi and preserve all other bits x_{\i}
        # Equivalent to xi[:,bit_i_idx] = 1-xi[:, bit_i_idx], but assigns
        # the result to xi_flip, instead of working in place on xi.
        xi_flip = T.set_subtensor(xi[:, bit_i_idx], 1 - xi[:, bit_i_idx])

        # calculate free energy with bit flipped
        fe_xi_flip = self.freeEnergy(xi_flip)

        # equivalent to e^(-FE(x_i)) / (e^(-FE(x_i)) + e^(-FE(x_{\i})))
        cost = T.mean(self.n_visible * T.log(activation(fe_xi_flip - fe_xi)))

        # increment bit_i_idx % number as part of updates
        updates[bit_i_idx] = (bit_i_idx + 1) % self.n_visible
        return cost
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号