• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python numx.zeros函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _train

    def _train(self, x, y):
        """
        :param x: Array of different input observations.
        :type x: numpy.ndarray

        :param y: Array of size (x.shape[0], output_dim) that contains the 
            observed output to the input x's.
        :type y: numpy.ndarray
        """
        # initialize internal vars if necessary
        if self._xTx is None:
            if self.with_bias:
                x_size = self._input_dim + 1
            else:
                x_size = self._input_dim
            self._xTx = numx.zeros((x_size, x_size), self._dtype)
            self._xTy = numx.zeros((x_size, self._output_dim), self._dtype)

        if self.with_bias:
            x = self._add_constant(x)

        # update internal variables
        self._xTx += mult(x.T, x)
        self._xTy += mult(x.T, y)
        self._tlen += x.shape[0]
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:25,代码来源:regression_nodes.py


示例2: _init_internals

 def _init_internals(self):
     input_dim = self.input_dim
     self._mean = numx.zeros((input_dim,), dtype='d')
     self._var = numx.zeros((input_dim,), dtype='d')
     self._tlen = 0
     self._diff2 = numx.zeros((input_dim,), dtype='d')
     self._initialized = 1
开发者ID:beniamino38,项目名称:mdp-toolkit,代码行数:7,代码来源:misc_nodes.py


示例3: _execute

    def _execute(self, x):
        degree = self._degree
        dim = self.input_dim
        n = x.shape[1]

        # preallocate memory
        dexp = numx.zeros((self.output_dim, x.shape[0]), dtype=self.dtype)
        # copy monomials of degree 1
        dexp[0:n, :] = x.T

        k = n
        prec_end = 0
        next_lens = numx.ones((dim+1, ))
        next_lens[0] = 0
        for i in range(2, degree+1):
            prec_start = prec_end
            prec_end += nmonomials(i-1, dim)
            prec = dexp[prec_start:prec_end, :]

            lens = next_lens[:-1].cumsum(axis=0)
            next_lens = numx.zeros((dim+1, ))
            for j in range(dim):
                factor = prec[lens[j]:, :]
                len_ = factor.shape[0]
                dexp[k:k+len_, :] = x[:, j] * factor
                next_lens[j+1] = len_
                k = k+len_

        return dexp.T
开发者ID:OpenGov,项目名称:mdp-toolkit,代码行数:29,代码来源:expansion_nodes.py


示例4: __init__

 def __init__(self, n, d, real_dtype="d", integer_dtype="l"):
     """Initializes an object of type 'OneDimensionalHitParade'.
     
     :param n: Number of maxima and minima to remember.
     :type n: int
     
     :param d: Minimum gap between two hits.
     :type d: int
     
     :param real_dtype: Datatype of sequence items
     :type real_dtype: numpy.dtype or str
     
     :param integer_dtype: Datatype of sequence indices
     :type integer_dtype: numpy.dtype or str
     """
     self.n = int(n)
     self.d = int(d)
     self.iM = numx.zeros((n, ), dtype=integer_dtype)
     self.im = numx.zeros((n, ), dtype=integer_dtype)
     
     real_dtype = numx.dtype(real_dtype)
     if real_dtype in mdp.utils.get_dtypes('AllInteger'):
         max_num = numx.iinfo(real_dtype).max
         min_num = numx.iinfo(real_dtype).min
     else:
         max_num = numx.finfo(real_dtype).max
         min_num = numx.finfo(real_dtype).min
     self.M = numx.array([min_num]*n, dtype=real_dtype)
     self.m = numx.array([max_num]*n, dtype=real_dtype)
     
     self.lM = 0
     self.lm = 0
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:32,代码来源:misc_nodes.py


示例5: test_mixed_dict

 def test_mixed_dict(self):
     """Test msg being a dict containing an array."""
     rescont = MessageResultContainer()
     msg1 = {
         "f": 2,
         "a": np.zeros((10,3), 'int'),
         "b": "aaa",
         "c": 1,
     }
     msg2 = {
         "a": np.ones((15,3), 'int'),
         "b": "bbb",
         "c": 3,
         "d": 1,
     }
     rescont.add_message(msg1)
     rescont.add_message(msg2)
     combined_msg = rescont.get_message()
     a = np.zeros((25,3), 'int')
     a[10:] = 1
     reference_msg = {"a": a, "c": 4, "b": "aaabbb", "d": 1, "f": 2}
     assert np.all(reference_msg["a"] == reference_msg["a"])
     combined_msg.pop("a")
     reference_msg.pop("a")
     assert combined_msg == reference_msg
开发者ID:mdp-toolkit,项目名称:mdp-toolkit,代码行数:25,代码来源:test_biflow.py


示例6: __init__

    def __init__(self, n, d, real_dtype="d", integer_dtype="l"):
        """
        Input arguments:
        n -- Number of maxima and minima to remember
        d -- Minimum gap between two hits

        real_dtype -- dtype of sequence items
        integer_dtype -- dtype of sequence indices
        Note: be careful with dtypes!
        """
        self.n = int(n)
        self.d = int(d)
        self.iM = numx.zeros((n, ), dtype=integer_dtype)
        self.im = numx.zeros((n, ), dtype=integer_dtype)
        
        real_dtype = numx.dtype(real_dtype)
        if real_dtype in mdp.utils.get_dtypes('AllInteger'):
            max_num = numx.iinfo(real_dtype).max
            min_num = numx.iinfo(real_dtype).min
        else:
            max_num = numx.finfo(real_dtype).max
            min_num = numx.finfo(real_dtype).min
        self.M = numx.array([min_num]*n, dtype=real_dtype)
        self.m = numx.array([max_num]*n, dtype=real_dtype)
        
        self.lM = 0
        self.lm = 0
开发者ID:beniamino38,项目名称:mdp-toolkit,代码行数:27,代码来源:misc_nodes.py


示例7: test_incompatible_arrays

 def test_incompatible_arrays(self):
     """Test with incompatible arrays."""
     rescont = MessageResultContainer()
     msgs = [{"a":  np.zeros((10,3))}, {"a":  np.zeros((10,4))}]
     for msg in msgs:
         rescont.add_message(msg)
     pytest.raises(ValueError, rescont.get_message)
开发者ID:mdp-toolkit,项目名称:mdp-toolkit,代码行数:7,代码来源:test_biflow.py


示例8: output_sizes

 def output_sizes(self, n):
     """Return the individual output sizes of each expansion function
     when the input has lenght n."""
     sizes = numx.zeros(len(self.funcs))
     x = numx.zeros((1,n))
     for i, func in enumerate(self.funcs):
         outx = func(x)
         sizes[i] = outx.shape[1]
     return sizes
开发者ID:OpenGov,项目名称:mdp-toolkit,代码行数:9,代码来源:expansion_nodes.py


示例9: _get_rnd_permutation

 def _get_rnd_permutation(self, dim):
     # return a random permut matrix with the right dimensions and type
     zero = numx.zeros((dim, dim), dtype=self.dtype)
     row = numx_rand.permutation(dim)
     for col in range(dim):
         zero[row[col], col] = 1.
     return zero
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:7,代码来源:isfa_nodes.py


示例10: output_sizes

 def output_sizes(self, n):
     """Return the individual output sizes of each expansion function
     when the input has lenght n.
     
     :param n: Input dimension,
     :type: int
     
     :return: The individual output sizes of each expansion function.
     :rtype: list
     """
     sizes = numx.zeros(len(self.funcs), dtype=numx.int64)
     x = numx.zeros((1,n))
     for i, func in enumerate(self.funcs):
         outx = func(x)
         sizes[i] = outx.shape[1]
     return sizes
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:16,代码来源:expansion_nodes.py


示例11: _execute

    def _execute(self, x):
        assert x.shape[0] == 1

        if self.sliding_wnd == None:
            self._init_sliding_window()

        gap = self.gap
        rows = self.sliding_wnd.shape[0]
        cols = self.output_dim
        n = self.input_dim

        new_row = numx.zeros(cols, dtype=self.dtype)
        new_row[:n] = x

        # Slide
        if self.slide:
            self.sliding_wnd[:-1, :] = self.sliding_wnd[1:, :]

        # Delay
        if self.cur_idx-gap >= 0:
            new_row[n:] = self.sliding_wnd[self.cur_idx-gap, :-n]

        # Add new row to matrix
        self.sliding_wnd[self.cur_idx, :] = new_row

        if self.cur_idx < rows-1:
            self.cur_idx = self.cur_idx+1 
        else:
            self.slide = True

        return new_row[numx.newaxis,:]
开发者ID:beniamino38,项目名称:mdp-toolkit,代码行数:31,代码来源:misc_nodes.py


示例12: get_quadratic_form

    def get_quadratic_form(self, nr):
        """
        Return the matrix H, the vector f and the constant c of the
        quadratic form 1/2 x'Hx + f'x + c that defines the output
        of the component 'nr' of the SFA node.
        """
        if self.sf is None:
            self._if_training_stop_training()

        sf = self.sf[:, nr]
        c = -mult(self.avg, sf)
        n = self.input_dim
        f = sf[:n]
        h = numx.zeros((n, n), dtype=self.dtype)
        k = n
        for i in range(n):
            for j in range(n):
                if j > i:
                    h[i, j] = sf[k]
                    k = k+1
                elif j == i:
                    h[i, j] = 2*sf[k]
                    k = k+1
                else:
                    h[i, j] = h[j, i]

        return QuadraticForm(h, f, c, dtype=self.dtype)
开发者ID:Debilski,项目名称:mdp-toolkit,代码行数:27,代码来源:sfa_nodes.py


示例13: _sample_v

    def _sample_v(self, h, sample_l=False, concatenate=True):
        # returns  P(v=1|h,W,b), a sample from it, P(l=1|h,W,b),
        # and a sample from it

        ldim, vdim = self._labels_dim, self._visible_dim

        # activation
        a = self.bv + mult(h, self.w.T)
        av, al = a[:, :vdim], a[:, vdim:]

        # ## visible units: logistic activation
        probs_v = old_div(1.,(1. + exp(-av)))
        v = (probs_v > random(probs_v.shape)).astype('d')

        # ## label units: softmax activation
        # subtract maximum to regularize exponent
        exponent = al - rrep(al.max(axis=1), ldim)
        probs_l = exp(exponent)
        probs_l /= rrep(probs_l.sum(axis=1), ldim)

        if sample_l:
            # ?? todo: I'm sure this can be optimized
            l = numx.zeros((h.shape[0], ldim))
            for t in range(h.shape[0]):
                l[t, :] = mdp.numx_rand.multinomial(1, probs_l[t, :])
        else:
            l = probs_l.copy()

        if concatenate:
            probs = numx.concatenate((probs_v, probs_l), axis=1)
            x = numx.concatenate((v, l), axis=1)
            return probs, x
        else:
            return probs_v, probs_l, v, l
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:34,代码来源:rbm_nodes.py


示例14: _execute

    def _execute(self, x):
        #----------------------------------------------------
        # similar algorithm to that within self.stop_training()
        #  refer there for notes & comments on code
        #----------------------------------------------------
        N = self.data.shape[0]
        Nx = x.shape[0]
        W = numx.zeros((Nx, N), dtype=self.dtype)

        k, r = self.k, self.r
        d_out = self.output_dim
        Q_diag_idx = numx.arange(k)

        for row in range(Nx):
            #find nearest neighbors of x in M
            M_xi = self.data-x[row]
            nbrs = numx.argsort( (M_xi**2).sum(1) )[:k]
            M_xi = M_xi[nbrs]

            #find corrected covariance matrix Q
            Q = mult(M_xi, M_xi.T)
            if r is None and k > d_out:
                sig2 = (svd(M_xi, compute_uv=0))**2
                r = numx.sum(sig2[d_out:])
                Q[Q_diag_idx, Q_diag_idx] += r
            if r is not None:
                Q[Q_diag_idx, Q_diag_idx] += r

            #solve for weights
            w = self._refcast(numx_linalg.solve(Q , numx.ones(k)))
            w /= w.sum()
            W[row, nbrs] = w

        #multiply weights by result of SVD from training
        return numx.dot(W, self.training_projection)
开发者ID:Debilski,项目名称:mdp-toolkit,代码行数:35,代码来源:lle_nodes.py


示例15: _update_mean

 def _update_mean(self, x, label):
     """Update the mean with data for a single label."""
     if label not in self.label_means:
         self.label_means[label] = numx.zeros(self.input_dim)
         self.n_label_samples[label] = 0
     # TODO: use smarter summing to avoid rounding errors
     self.label_means[label] += numx.sum(x, axis=0)
     self.n_label_samples[label] += len(x)
开发者ID:pmolfese,项目名称:afni,代码行数:8,代码来源:classifier_nodes.py


示例16: _get_contrast

 def _get_contrast(self, covs, bica_bsfa = None):
     if bica_bsfa is None:
         bica_bsfa = self._bica_bsfa
     # return current value of the contrast
     R = self.output_dim
     ncovs = covs.ncovs
     covs = covs.covs
     icaweights = self.icaweights
     sfaweights = self.sfaweights
     # unpack the bsfa and bica coefficients
     bica, bsfa = bica_bsfa
     sfa = numx.zeros((ncovs, ), dtype=self.dtype)
     ica = numx.zeros((ncovs, ), dtype=self.dtype)
     for t in range(ncovs):
         sq_corr =  covs[:R, :R, t]*covs[:R, :R, t]
         sfa[t] = sq_corr.trace()
         ica[t] = 2*_triu(sq_corr, 1).ravel().sum()
     return (bsfa*sfaweights*sfa).sum(), (bica*icaweights*ica).sum()
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:18,代码来源:isfa_nodes.py


示例17: test_execute_routing

 def test_execute_routing(self):
     """Test the standard routing for messages."""
     sboard = BiSwitchboard(input_dim=3, connections=[2,0,1])
     x = n.array([[1,2,3],[4,5,6]])
     msg = {
         "string": "blabla",
         "list": [1,2],
         "data": x.copy(),  # should be mapped by switchboard
         "data2": n.zeros(3),  # should not be modified
         "data3": n.zeros((3,4)),  # should not be modified
     }
     y, out_msg = sboard.execute(x, msg)
     reference_y = n.array([[3,1,2],[6,4,5]])
     assert (y == reference_y).all()
     assert out_msg["string"] == msg["string"]
     assert out_msg["list"] == msg["list"]
     assert n.all(out_msg["data"] == reference_y)
     assert out_msg["data2"].shape == (3,)
     assert out_msg["data3"].shape == (3,4)
开发者ID:Debilski,项目名称:mdp-toolkit,代码行数:19,代码来源:test_bihinet.py


示例18: _mgs

def _mgs(a):
    m, n = a.shape
    v = a.copy()
    r = numx.zeros((n, n))
    for i in range(n):
        r[i, i] = numx_linalg.norm(v[:, i])
        v[:, i] = v[:, i]/r[i, i]
        for j in range(i+1, n):
            r[i, j] = mult(v[:, i], v[:, j])
            v[:, j] = v[:, j] - r[i, j]*v[:, i]
    # q is v
    return v, r
开发者ID:Debilski,项目名称:mdp-toolkit,代码行数:12,代码来源:lle_nodes.py


示例19: test_inverse_message_routing

 def test_inverse_message_routing(self):
     """Test the inverse routing for messages."""
     sboard = BiSwitchboard(input_dim=3, connections=[2,0,1])
     x = n.array([[1,2,3],[4,5,6]])
     msg = {
         "string": "blabla",
         "method": "inverse",
         "list": [1,2],
         "data": x,  # should be mapped by switchboard
         "data2": n.zeros(3),  # should not be modified
         "data3": n.zeros((3,4)),  # should not be modified
         "target": "test"
     }
     y, out_msg, target = sboard.execute(None, msg)
     assert y is None
     assert target == "test"
     reference_y = n.array([[2,3,1],[5,6,4]])
     assert out_msg["string"] == msg["string"]
     assert out_msg["list"] == msg["list"]
     assert (out_msg["data"] == reference_y).all()
     assert out_msg["data2"].shape == (3,)
     assert out_msg["data3"].shape == (3,4)
开发者ID:Debilski,项目名称:mdp-toolkit,代码行数:22,代码来源:test_bihinet.py


示例20: _mgs

def _mgs(a):
    """Modified Gram-Schmidt."""
    m, n = a.shape
    v = a.copy()
    r = numx.zeros((n, n))
    for i in range(n):
        r[i, i] = numx_linalg.norm(v[:, i])
        v[:, i] = old_div(v[:, i],r[i, i])
        for j in range(i+1, n):
            r[i, j] = mult(v[:, i], v[:, j])
            v[:, j] = v[:, j] - r[i, j]*v[:, i]
    # q is v
    return v, r
开发者ID:AlbertoEsc,项目名称:mdp-toolkit,代码行数:13,代码来源:lle_nodes.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.mult函数代码示例发布时间:2022-05-27
下一篇:
Python mdp.getStates函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap