當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.tile方法代碼示例

本文整理匯總了Python中autograd.numpy.tile方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.tile方法的具體用法?Python numpy.tile怎麽用?Python numpy.tile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在autograd.numpy的用法示例。


在下文中一共展示了numpy.tile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: jacobian_and_value

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def jacobian_and_value(fun, x):
    """
    Makes a function that returns both the Jacobian and value of a function.

    Assumes that the function `fun` broadcasts along the first dimension of the
    input being differentiated with respect to such that a batch of outputs can
    be computed concurrently for a batch of inputs.
    """
    val = fun(x)
    v_vspace = vspace(val)
    x_vspace = vspace(x)
    x_rep = np.tile(x, (v_vspace.size,) + (1,) * x_vspace.ndim)
    vjp_rep, _ = make_vjp(fun, x_rep)
    jacobian_shape = v_vspace.shape + x_vspace.shape
    basis_vectors = np.array([b for b in v_vspace.standard_basis()])
    jacobian = vjp_rep(basis_vectors)
    return np.reshape(jacobian, jacobian_shape), val 
開發者ID:matt-graham,項目名稱:mici,代碼行數:19,代碼來源:autograd_wrapper.py

示例2: hessian_grad_and_value

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def hessian_grad_and_value(fun, x):
    """
    Makes a function that returns the Hessian, gradient & value of a function.

    Assumes that the function `fun` broadcasts along the first dimension of the
    input being differentiated with respect to such that a batch of outputs can
    be computed concurrently for a batch of inputs.
    """
    def grad_fun(x):
        vjp, val = make_vjp(fun, x)
        return vjp(vspace(val).ones()), val
    x_vspace = vspace(x)
    x_rep = np.tile(x, (x_vspace.size,) + (1,) * x_vspace.ndim)
    vjp_grad, (grad, val) = make_vjp(lambda x: atuple(grad_fun(x)), x_rep)
    hessian_shape = x_vspace.shape + x_vspace.shape
    basis_vectors = np.array([b for b in x_vspace.standard_basis()])
    hessian = vjp_grad((basis_vectors, vspace(val).zeros()))
    return np.reshape(hessian, hessian_shape), grad[0], val[0] 
開發者ID:matt-graham,項目名稱:mici,代碼行數:20,代碼來源:autograd_wrapper.py

示例3: outer_rows

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def outer_rows(X, Y):
    """
    Compute the outer product of each row in X, and Y.

    X: n x dx numpy array
    Y: n x dy numpy array

    Return an n x dx x dy numpy array.
    """

    # Matlab way to do this. According to Jonathan Huggins, this is not
    # efficient. Use einsum instead. See below.
    #n, dx = X.shape
    #dy = Y.shape[1]
    #X_col_rep = X[:, np.tile(range(dx), (dy, 1)).T.reshape(-1) ]
    #Y_tile = np.tile(Y, (1, dx))
    #Z = X_col_rep*Y_tile
    #return np.reshape(Z, (n, dx, dy))
    return np.einsum('ij,ik->ijk', X, Y) 
開發者ID:wittawatj,項目名稱:kernel-gof,代碼行數:21,代碼來源:util.py

示例4: gradXY_sum

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def gradXY_sum(self, X, Y):
        r"""
        Compute \sum_{i=1}^d \frac{\partial^2 k(x, Y)}{\partial x_i \partial y_i}
        evaluated at each x_i in X, and y_i in Y.

        X: nx x d numpy array.
        Y: ny x d numpy array.

        Return a nx x ny numpy array of the derivatives.
        """
        gamma = 1/X.shape[1] if self.gamma is None else self.gamma

        if self.degree == 1:  # optimization, other expression is valid too
            return np.tile(gamma, (X.shape[0], X.shape[1]))

        dot = np.dot(X, Y.T)
        inside = gamma * dot + self.coef0
        to_dminus2 = inside ** (self.degree - 2)
        to_dminus1 = to_dminus2 * inside
        return (
            (self.degree * (self.degree-1) * gamma**2) * to_dminus2 * dot
            + (X.shape[1] * gamma * self.degree) * to_dminus1
        ) 
開發者ID:wittawatj,項目名稱:kernel-gof,代碼行數:25,代碼來源:kernel.py

示例5: _set_precision_prior

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def _set_precision_prior(self, precision_prior):
        if precision_prior is None:
            self._precision_prior_ = \
            np.zeros((self.n_components, self.n_features, self.n_features))
        else:
            precision_prior = np.asarray(precision_prior)
            if len(precision_prior) == 1:
                self._precision_prior_ = np.tile(precision_prior,
                (self.n_components, self.n_features, self.n_features))
            elif \
            (precision_prior.reshape(self.n_unique, self.n_features, self.n_features)).shape \
            == (self.n_unique, self.n_features, self.n_features):
                self._precision_prior_ = \
                np.zeros((self.n_components, self.n_features, self.n_features))
                for u in range(self.n_unique):
                    for t in range(self.n_chain):
                        self._precision_prior_[u*(self.n_chain)+t] = precision_prior[u].copy()
            else:
                raise ValueError("cannot match shape of precision_prior") 
開發者ID:mackelab,項目名稱:autohmm,代碼行數:21,代碼來源:tm.py

示例6: _set_startprob

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def _set_startprob(self, startprob):
        if startprob is None:
            startprob = np.tile(1.0 / self.n_components, self.n_components)
        else:
            startprob = np.asarray(startprob, dtype=np.float)

            normalize(startprob)

            if len(startprob) != self.n_components:
                if len(startprob) == self.n_unique:
                    startprob_split = np.copy(startprob) / (1.0+self.n_tied)
                    startprob = np.zeros(self.n_components)
                    for u in range(self.n_unique):
                        for t in range(self.n_chain):
                            startprob[u*(self.n_chain)+t] = \
                                startprob_split[u].copy()
                else:
                    raise ValueError("cannot match shape of startprob")

        if not np.allclose(np.sum(startprob), 1.0):
            raise ValueError('startprob must sum to 1.0')

        self._log_startprob = np.log(np.asarray(startprob).copy()) 
開發者ID:mackelab,項目名稱:autohmm,代碼行數:25,代碼來源:tm.py

示例7: _set_transmat

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def _set_transmat(self, transmat_val):
        if transmat_val is None:
            transmat = np.tile(1.0 / self.n_components,
                               (self.n_components, self.n_components))
        else:
            transmat_val[np.isnan(transmat_val)] = 0.0
            normalize(transmat_val, axis=1)

            if (np.asarray(transmat_val).shape == (self.n_components,
                                                   self.n_components)):
                transmat = np.copy(transmat_val)
            elif transmat_val.shape[0] == self.n_unique:
                transmat = self._ntied_transmat(transmat_val)
            else:
                raise ValueError("cannot match shape of transmat")

        if not np.all(np.allclose(np.sum(transmat, axis=1), 1.0)):
            raise ValueError('Rows of transmat must sum to 1.0')
        self._log_transmat = np.log(np.asarray(transmat).copy())
        underflow_idx = np.isnan(self._log_transmat)
        self._log_transmat[underflow_idx] = NEGINF 
開發者ID:mackelab,項目名稱:autohmm,代碼行數:23,代碼來源:tm.py

示例8: _calc_pareto_front

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def _calc_pareto_front(self, ref_dirs, *args, **kwargs):
        F = super()._calc_pareto_front(ref_dirs, *args, **kwargs)
        a = anp.sqrt(anp.sum(F ** 2, 1) - 3 / 4 * anp.max(F ** 2, axis=1))
        a = anp.expand_dims(a, axis=1)
        a = anp.tile(a, [1, ref_dirs.shape[1]])
        F = F / a

        return F 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:10,代碼來源:cdtlz.py

示例9: generic_sphere

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def generic_sphere(ref_dirs):
    return ref_dirs / anp.tile(anp.linalg.norm(ref_dirs, axis=1)[:, None], (1, ref_dirs.shape[1])) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:4,代碼來源:dtlz.py

示例10: b

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def b(self, value):
        assert value.shape == (self.num_states,)
        self.logpi = np.tile(value[None, :], (self.num_states, 1)) 
開發者ID:slinderman,項目名稱:recurrent-slds,代碼行數:5,代碼來源:transitions.py

示例11: resample

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def resample(self, stateseqs=None, covseqs=None,
                 n_steps=10, step_sz=0.01, **kwargs):
        K, D = self.num_states, self.covariate_dim

        # Run HMC
        from hips.inference.hmc import hmc

        def hmc_objective(params):
            # Unpack params
            assert params.size == K + K * D
            assert params.ndim == 1
            b = params[:K]
            logpi = anp.tile(b[None, :], (K, 1))
            W = params[K:].reshape((D, K))
            return self.joint_log_probability(logpi, W, stateseqs, covseqs)

        # hmc_objective = lambda params: self.joint_log_probability(params, stateseqs, covseqs)
        grad_hmc_objective = grad(hmc_objective)
        x0 = np.concatenate((self.b, np.ravel(self.W)))
        xf, self.step_sz, self.accept_rate = \
            hmc(hmc_objective, grad_hmc_objective,
                step_sz=self.step_sz, n_steps=n_steps, q_curr=x0,
                negative_log_prob=False,
                adaptive_step_sz=True,
                avg_accept_rate=self.accept_rate)

        self.b = xf[:K]
        self.W = xf[K:].reshape((D, K))

    ### EM 
開發者ID:slinderman,項目名稱:recurrent-slds,代碼行數:32,代碼來源:transitions.py

示例12: expected_logpi

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def expected_logpi(self):
        return np.tile(self.expected_b[None,:], (self.num_states, 1)) 
開發者ID:slinderman,項目名稱:recurrent-slds,代碼行數:4,代碼來源:transitions.py

示例13: expected_logpi_WT

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def expected_logpi_WT(self):
        return np.tile(self.expected_bWT[:,None,:], (1, self.num_states, 1)) 
開發者ID:slinderman,項目名稱:recurrent-slds,代碼行數:4,代碼來源:transitions.py

示例14: expected_logpi_logpiT

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def expected_logpi_logpiT(self):
        return np.tile(self.expected_bsq[:,None,None], (1, self.num_states, self.num_states)) 
開發者ID:slinderman,項目名稱:recurrent-slds,代碼行數:4,代碼來源:transitions.py

示例15: test_tile

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import tile [as 別名]
def test_tile():
    combo_check(np.tile, [0])([R(2,1,3,1)], reps=[(1, 4, 1, 2)])
    combo_check(np.tile, [0])([R(1,2)], reps=[(1,2), (2,3), (3,2,1)])
    combo_check(np.tile, [0])([R(1)], reps=[(2,), 2]) 
開發者ID:HIPS,項目名稱:autograd,代碼行數:6,代碼來源:test_systematic.py


注:本文中的autograd.numpy.tile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。