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


Python linalg.cho_solve方法代碼示例

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


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

示例1: mvn_loglike

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def mvn_loglike(x, sigma):
    '''loglike multivariate normal

    assumes x is 1d, (nobs,) and sigma is 2d (nobs, nobs)

    brute force from formula
    no checking of correct inputs
    use of inv and log-det should be replace with something more efficient
    '''
    #see numpy thread
    #Sturla: sqmahal = (cx*cho_solve(cho_factor(S),cx.T).T).sum(axis=1)
    sigmainv = linalg.inv(sigma)
    logdetsigma = np.log(np.linalg.det(sigma))
    nobs = len(x)

    llf = - np.dot(x, np.dot(sigmainv, x))
    llf -= nobs * np.log(2 * np.pi)
    llf -= logdetsigma
    llf *= 0.5
    return llf 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:linalg_covmat.py

示例2: pred_constraint_voilation

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def pred_constraint_voilation(self, cand, comp, vals):
        # The primary covariances for prediction.
        comp_cov   = self.cov(self.constraint_amp2, self.constraint_ls, comp)
        cand_cross = self.cov(self.constraint_amp2, self.constraint_ls, comp,
                              cand)

        # Compute the required Cholesky.
        obsv_cov  = comp_cov + self.constraint_noise*np.eye(comp.shape[0])
        obsv_chol = spla.cholesky(obsv_cov, lower=True)

        cov_grad_func = getattr(gp, 'grad_' + self.cov_func.__name__)
        cand_cross_grad = cov_grad_func(self.constraint_ls, comp, cand)

        # Predictive things.
        # Solve the linear systems.
        alpha  = spla.cho_solve((obsv_chol, True), self.ff)
        beta   = spla.solve_triangular(obsv_chol, cand_cross, lower=True)

        # Predict the marginal means and variances at candidates.
        func_m = np.dot(cand_cross.T, alpha)# + self.constraint_mean
        func_m = sps.norm.cdf(func_m*self.constraint_gain)

        return func_m

    # Compute EI over hyperparameter samples 
開發者ID:NVIDIA,項目名稱:Milano,代碼行數:27,代碼來源:gpei_constrained_chooser.py

示例3: first_fit

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def first_fit(self, train_x, train_y):
        """ Fit the regressor for the first time. """
        train_x, train_y = np.array(train_x), np.array(train_y)

        self._x = np.copy(train_x)
        self._y = np.copy(train_y)

        self._distance_matrix = edit_distance_matrix(self._x)
        k_matrix = bourgain_embedding_matrix(self._distance_matrix)
        k_matrix[np.diag_indices_from(k_matrix)] += self.alpha

        self._l_matrix = cholesky(k_matrix, lower=True)  # Line 2

        self._alpha_vector = cho_solve(
            (self._l_matrix, True), self._y)  # Line 3

        self._first_fitted = True
        return self 
開發者ID:microsoft,項目名稱:nni,代碼行數:20,代碼來源:bayesian.py

示例4: do_sampleF2

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def do_sampleF2(Y, X, current_F1, log_theta):

    log_theta_sigma2, log_theta_lengthscale, log_theta_lambda = unpack_log_theta(log_theta)

    n = Y.shape[0]

    K_F2 = covariance_function(current_F1, current_F1, log_theta_sigma2[1], log_theta_lengthscale[1]) + np.eye(n) * 1e-9
    K_Y = K_F2 + np.eye(n) * np.exp(log_theta_lambda)
    L_K_Y, lower_K_Y = linalg.cho_factor(K_Y, lower=True)
    K_inv_Y = linalg.cho_solve((L_K_Y, lower_K_Y), Y)

    mu = np.dot(K_F2, K_inv_Y)

    K_inv_K = linalg.cho_solve((L_K_Y, lower_K_Y), K_F2)
    Sigma = K_F2 - np.dot(K_F2, K_inv_K)

    L_Sigma = linalg.cholesky(Sigma, lower=True)
    proposed_F2 = mu + np.dot(L_Sigma, np.random.normal(0.0, 1.0, [n, 1]))

    return proposed_F2

## Unpack the vector of parameters into their three elements 
開發者ID:mauriziofilippone,項目名稱:deep_gp_random_features,代碼行數:24,代碼來源:mcmc.py

示例5: inv

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def inv(self, logdet=False):
        if self.ndim == 1:
            inv = 1.0 / self

            if logdet:
                return inv, np.sum(np.log(self))
            else:
                return inv
        else:
            try:
                cf = sl.cho_factor(self)
                inv = sl.cho_solve(cf, np.identity(cf[0].shape[0]))
                if logdet:
                    ld = 2.0 * np.sum(np.log(np.diag(cf[0])))
            except np.linalg.LinAlgError:
                u, s, v = np.linalg.svd(self)
                inv = np.dot(u / s, u.T)
                if logdet:
                    ld = np.sum(np.log(s))
            if logdet:
                return inv, ld
            else:
                return inv 
開發者ID:nanograv,項目名稱:enterprise,代碼行數:25,代碼來源:utils.py

示例6: _kalman_correct

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def _kalman_correct(x, P, z, H, R, gain_factor, gain_curve):
    PHT = np.dot(P, H.T)

    S = np.dot(H, PHT) + R
    e = z - H.dot(x)
    L = cholesky(S, lower=True)
    inn = solve_triangular(L, e, lower=True)

    if gain_curve is not None:
        q = (np.dot(inn, inn) / inn.shape[0]) ** 0.5
        f = gain_curve(q)
        if f == 0:
            return inn
        L *= (q / f) ** 0.5

    K = cho_solve((L, True), PHT.T, overwrite_b=True).T
    if gain_factor is not None:
        K *= gain_factor[:, None]

    U = -K.dot(H)
    U[np.diag_indices_from(U)] += 1
    x += K.dot(z - H.dot(x))
    P[:] = U.dot(P).dot(U.T) + K.dot(R).dot(K.T)

    return inn 
開發者ID:nmayorov,項目名稱:pyins,代碼行數:27,代碼來源:filt.py

示例7: variance_values

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def variance_values(self, beta):
        """ Covariance matrix for the estimated function
        
        Parameters
        ----------
        beta : np.array
            Contains untransformed starting values for latent variables
        
        Returns
        ----------
        Covariance matrix for the estimated function 
        """     
        parm = np.array([self.latent_variables.z_list[k].prior.transform(beta[k]) for k in range(beta.shape[0])])
        L = self._L(parm)
        v = la.cho_solve((L, True), self.kernel.K(parm))
        return self.kernel.K(parm) - np.dot(v.T, v) 
開發者ID:RJT1990,項目名稱:pyflux,代碼行數:18,代碼來源:gpnarx.py

示例8: log_likelihood

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def log_likelihood(self, p):
        p = self.to_params(p)

        v = self.rvs(p)

        res = self.vs - v - p['mu']

        cov = p['nu']*p['nu']*np.diag(self.dvs*self.dvs)
        cov += generate_covariance(self.ts, p['sigma'], p['tau'])

        cfactor = sl.cho_factor(cov)
        cc, lower = cfactor

        n = self.ts.shape[0]

        return -0.5*n*np.log(2.0*np.pi) - np.sum(np.log(np.diag(cc))) - 0.5*np.dot(res, sl.cho_solve(cfactor, res)) 
開發者ID:bfarr,項目名稱:kombine,代碼行數:18,代碼來源:correlated_likelihood.py

示例9: _set_bandwidth

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def _set_bandwidth(self):
        r"""
        Use Scott's rule to set the kernel bandwidth:

        .. math::

            \mathcal{K} = n^{-1/(d+4)} \Sigma^{1/2}

        Also store Cholesky decomposition for later.
        """
        if self.size > 0 and self._cov is not None:
            self._kernel_cov = self._cov * self.size ** (-2/(self.ndim + 4))

            # Used to evaluate PDF with cho_solve()
            self._cho_factor = la.cho_factor(self._kernel_cov)

            # Make sure the estimated PDF integrates to 1.0
            self._lognorm = self.ndim/2 * np.log(2*np.pi) + np.log(self.size) +\
                np.sum(np.log(np.diag(self._cho_factor[0])))

        else:
            self._lognorm = -np.inf 
開發者ID:bfarr,項目名稱:kombine,代碼行數:24,代碼來源:clustered_kde.py

示例10: _evaluate_point_logpdf

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def _evaluate_point_logpdf(args):
    """
    Evaluate the Gaussian KDE at a given point `p`.  This lives outside the KDE method to allow for
    parallelization using :mod:`multipocessing`. Since :func:`map` only allows single-argument
    functions, the following arguments to be packed into a single tuple.

    :param p:
        The point to evaluate the KDE at.

    :param data:
        The `(N, ndim)`-shaped array of data used to construct the KDE.

    :param cho_factor:
        A Cholesky decomposition of the kernel covariance matrix.
    """
    point, data, cho_factor = args

    # Use Cholesky decomposition to avoid direct inversion of covariance matrix
    diff = data - point
    tdiff = la.cho_solve(cho_factor, diff.T, check_finite=False).T
    diff *= tdiff

    # Work in the log to avoid large numbers
    return logsumexp(-np.sum(diff, axis=1)/2) 
開發者ID:bfarr,項目名稱:kombine,代碼行數:26,代碼來源:clustered_kde.py

示例11: solve

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def solve(self, Y):
    return la.cho_solve(self._cholesky, Y) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:4,代碼來源:mvnormal.py

示例12: KLdiv

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def KLdiv(mu0, Lcov0, mu1, Lcov1):
    """Numpy KL calculation."""
    tr, dist, ldet = 0., 0., 0.
    D, n = mu0.shape
    for m0, m1, L0, L1 in zip(mu0, mu1, Lcov0, Lcov1):
        tr += np.trace(cho_solve((L1, True), L0.dot(L0.T)))
        md = m1 - m0
        dist += md.dot(cho_solve((L1, True), md))
        ldet += logdet(L1) - logdet(L0)

    KL = 0.5 * (tr + dist + ldet - D * n)
    return KL 
開發者ID:gradientinstitute,項目名稱:aboleth,代碼行數:14,代碼來源:test_distributions.py

示例13: _applyConstraints

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def _applyConstraints(blockVectorV, factYBY, blockVectorBY, blockVectorY):
    """Changes blockVectorV in place."""
    gramYBV = np.dot(blockVectorBY.T, blockVectorV)
    tmp = cho_solve(factYBY, gramYBV)
    blockVectorV -= np.dot(blockVectorY, tmp) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:7,代碼來源:lobpcg.py

示例14: chol2inv

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def chol2inv(chol):
    return spla.cho_solve((chol, False), numpy.eye(chol.shape[ 0 ])) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:4,代碼來源:nlinalg.py

示例15: yt_minv_y

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import cho_solve [as 別名]
def yt_minv_y(self, y):
        '''xSigmainvx
        doesn't use stored cholesky yet
        '''
        return np.dot(x,linalg.cho_solve(linalg.cho_factor(self.m),x))
        #same as
        #lower = False   #if cholesky(sigma) is used, default is upper
        #np.dot(x,linalg.cho_solve((self.cholsigma, lower),x)) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:linalg_decomp_1.py


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