当前位置: 首页>>代码示例>>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;未经允许,请勿转载。