当前位置: 首页>>代码示例>>Python>>正文


Python moves.xrange函数代码示例

本文整理汇总了Python中theano.compat.six.moves.xrange函数的典型用法代码示例。如果您正苦于以下问题:Python xrange函数的具体用法?Python xrange怎么用?Python xrange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xrange函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_padding

def check_padding(axes):

    padding = 3
    ddata = DummyDataset()
    topo = ddata.get_topological_view()

    wf_cls = WindowAndFlip

    wf = wf_cls(window_shape=(5, 5), randomize=[ddata],
                pad_randomized=padding)
    wf.setup(None, None, None)
    new_topo = ddata.get_topological_view()
    assert_equal(topo.shape, new_topo.shape)
    saw_padding = dict([((direction, amount), False) for direction, amount
                        in itertools.product(['l', 'b', 'r', 't'],
                                             xrange(padding))])
    iters = 0
    while not all(saw_padding.values()) and iters < 50:
        for image in new_topo.swapaxes(0, 3):
            for i in xrange(padding):
                if (image[:i] == 0).all():
                    saw_padding['t', i] = True
                if (image[-i:] == 0).all():
                    saw_padding['b', i] = True
                if (image[:, -i:] == 0).all():
                    saw_padding['r', i] = True
                if (image[:, :i] == 0).all():
                    saw_padding['l', i] = True
        wf.on_monitor(None, None, None)
        new_topo = ddata.get_topological_view()
        iters += 1
开发者ID:123fengye741,项目名称:pylearn2,代码行数:31,代码来源:test_window_flip.py

示例2: test_mean_H_given_V

    def test_mean_H_given_V(self):
        tol = 1e-6

        # P(h_1 | v) / P(h_2 | v) = a
        # => exp(-E(v, h_1)) / exp(-E(v,h_2)) = a
        # => exp(E(v,h_2)-E(v,h_1)) = a
        # E(v,h_2) - E(v,h_1) = log(a)
        # also log P(h_1 | v) - log P(h_2) = log(a)

        rng = N.random.RandomState([1, 2, 3])

        m = 5

        Vv = as_floatX(N.zeros((m, self.nv)) + rng.randn(self.nv))

        Hv = as_floatX(rng.randn(m, self.nh) > 0.)

        log_Pv = self.log_P_H_given_V_func(Hv, Vv)

        Ev = self.E_func(Vv, Hv)

        for i in xrange(m):
            for j in xrange(i + 1, m):
                log_a = log_Pv[i] - log_Pv[j]
                e = Ev[j] - Ev[i]

                assert abs(e-log_a) < tol
开发者ID:123fengye741,项目名称:pylearn2,代码行数:27,代码来源:test_rbm_energy.py

示例3: outer

 def outer(self, Y, Y_hat):
     if self._requires_reshape:
         if self._requires_unmask:
             try:
                 Y, Y_mask = Y
                 Y_hat, Y_hat_mask = Y_hat
             except:
                 log.warning("Lost the mask when wrapping cost. This "
                             "can happen if this function is called "
                             "from within another wrapped function. "
                             "Most likely this won't cause any problem")
                 return cost(self, Y, Y_hat)
         input_shape = ([Y.shape[0] * Y.shape[1]] +
                        [Y.shape[i] for i in xrange(2, Y.ndim)])
         reshaped_Y = Y.reshape(input_shape)
         if isinstance(Y_hat, tuple):
             input_shape = ([[Y_hat[j].shape[0] * Y_hat[j].shape[1]] +
                             [Y_hat[j].shape[i]
                             for i in xrange(2, Y_hat[j].ndim)]
                             for j in xrange(len(Y_hat))])
             reshaped_Y_hat = []
             for i in xrange(len(Y_hat)):
                 reshaped_Y_hat.append(Y_hat[i].reshape(input_shape[i]))
             reshaped_Y_hat = tuple(reshaped_Y_hat)
         else:
             reshaped_Y_hat = Y_hat.reshape(input_shape)
         # Here we need to take the indices of only the unmasked data
         if self._requires_unmask:
             return cost(self, reshaped_Y[Y_mask.flatten().nonzero()],
                         reshaped_Y_hat[Y_mask.flatten().nonzero()])
         return cost(self, reshaped_Y, reshaped_Y_hat)
     else:  # Not RNN-friendly, but not requiring reshape
         return cost(self, Y, Y_hat)
开发者ID:MarCnu,项目名称:pylearn2,代码行数:33,代码来源:mlp_hook.py


注:本文中的theano.compat.six.moves.xrange函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。