`TypeError:不支持的操作数类型*:' NoneType'并且'漂浮'

时间:2018-01-05 10:52:15

标签: python numpy

我想学习一个代码,我想运行这段代码,

def __init__( self, input=None, input_history=None, n_visible=7,
                 n_hidden=500, delay=6, A=None, B=None, W=None, hbias=None,
                 vbias=None, numpy_rng=None):

        self.n_visible = n_visible
        self.n_hidden = n_hidden
        self.delay = delay

        if numpy_rng is None:

            numpy_rng = numpy.random.RandomState(1234)

        if W is None:

            W = np.asarray(0.01 * numpy_rng.randn(n_visible,
                                                          n_hidden))

        if A is None:
            A = np.asarray(0.01 * numpy_rng.randn(n_visible * delay,
                                                           n_visible))

        if B is None:
            B = np.asarray(0.01 * numpy_rng.randn(n_visible * delay,
                                                           n_hidden))

        if hbias is None:

            hbias = numpy.zeros(n_hidden)

        if vbias is None:

            vbias = numpy.zeros(n_visible)


        self.input = input     
        self.input_history = input_history
        self.W = W
        self.A = A
        self.B = B
        self.hbias = hbias
        self.vbias = vbias

        self.numpy_rng = numpy_rng


def propup(self, vis, v_history):

            pre_sigmoid_activation = numpy.dot(vis, self.W) + \
                                     numpy.dot(v_history, self.B) + self.hbias
            return sigmoid(pre_sigmoid_activation)

但是收到错误消息

  

`TypeError:不支持的操作数类型*:' NoneType'并且'浮动'

如果有人能够解释这个的意图:' NoneType'并且'漂浮'我是否必须更改数据? 但是早些时候我在执行此代码时没有发现任何错误

def propup(self, vis):
    pre_sigmoid_activation = numpy.dot(vis, self.W) + self.hbias
    return sigmoid(pre_sigmoid_activation)

我不确定此代码是否导致上述问题?

def get_cost_updates(self, lr=0.1, k=1):

        ph_mean, ph_sample = \
                        self.sample_h_given_v(self.input, self.input_history)


        chain_start = ph_sample

        for step in range(k):
           if step == 0:
             nv_means, nv_samples,\
             nh_means, nh_samples = self.gibbs_hvh(chain_start)
           else:
             nv_means, nv_samples,\
             nh_means, nh_samples = self.gibbs_hvh(nh_samples)

        self.W += lr * (numpy.dot(self.input.T, ph_mean)
                    - numpy.dot(nv_samples.T, nh_means))
        self.vbias += lr * numpy.mean(self.input - nv_samples, self.input_history, axis=0)
        self.hbias += lr * numpy.mean(ph_mean - nh_means, self.input_history, axis=0)

        monitoring_cost = numpy.mean(numpy.square(self.input - nv_means))

        return monitoring_cost

1 个答案:

答案 0 :(得分:-1)

在函数声明结束时使用冒号(:)。这是基本的语法错误。

def propup(self,vis,v_history):

pre_sigmoid_activation = numpy.dot(vis,self.W)+ \                                      numpy.dot(v_history,self.B)+ self.hbias             返回sigmoid(pre_sigmoid_activation)