当前位置: 首页>>代码示例>>Python>>正文


Python linalg.inv方法代码示例

本文整理汇总了Python中numpy.linalg.inv方法的典型用法代码示例。如果您正苦于以下问题:Python linalg.inv方法的具体用法?Python linalg.inv怎么用?Python linalg.inv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.linalg的用法示例。


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

示例1: super_circum

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def super_circum(self, radius):
        """
        Supercell dimensions such that the supercell circumsribes a sphere.

        :param float radius: circumscribed radius in angstroms

        Returns :data:`None` when geometry is not a crystal.
        """
        if self.lattice is None:
            return
        rec_lattice = 2 * pi * inv(self.lattice.T)
        layer_sep = np.array(
            [
                sum(vec * rvec / norm(rvec))
                for vec, rvec in zip(self.lattice, rec_lattice)
            ]
        )
        return np.array(np.ceil(radius / layer_sep + 0.5), dtype=int) 
开发者ID:jhrmnn,项目名称:pyberny,代码行数:20,代码来源:geomlib.py

示例2: test_basic

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def test_basic(self):
        import numpy.linalg as linalg

        A = np.array([[1., 2.],
                      [3., 4.]])
        mA = matrix(A)
        assert_(np.allclose(linalg.inv(A), mA.I))
        assert_(np.all(np.array(np.transpose(A) == mA.T)))
        assert_(np.all(np.array(np.transpose(A) == mA.H)))
        assert_(np.all(A == mA.A))

        B = A + 2j*A
        mB = matrix(B)
        assert_(np.allclose(linalg.inv(B), mB.I))
        assert_(np.all(np.array(np.transpose(B) == mB.T)))
        assert_(np.all(np.array(np.transpose(B).conj() == mB.H))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_defmatrix.py

示例3: test_byteorder_check

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def test_byteorder_check():
    # Byte order check should pass for native order
    if sys.byteorder == 'little':
        native = '<'
    else:
        native = '>'

    for dtt in (np.float32, np.float64):
        arr = np.eye(4, dtype=dtt)
        n_arr = arr.newbyteorder(native)
        sw_arr = arr.newbyteorder('S').byteswap()
        assert_equal(arr.dtype.byteorder, '=')
        for routine in (linalg.inv, linalg.det, linalg.pinv):
            # Normal call
            res = routine(arr)
            # Native but not '='
            assert_array_equal(res, routine(n_arr))
            # Swapped
            assert_array_equal(res, routine(sw_arr)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_linalg.py

示例4: cov_params_default

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def cov_params_default(self):  # p.296 (7.2.21)
        # Sigma_co described on p. 287
        beta = self.beta
        if self.det_coef_coint.size > 0:
            beta = vstack((beta, self.det_coef_coint))
        dt = self.deterministic
        num_det = ("co" in dt) + ("lo" in dt)
        num_det += (self.seasons-1) if self.seasons else 0
        if self.exog is not None:
            num_det += self.exog.shape[1]
        b_id = scipy.linalg.block_diag(beta,
                                       np.identity(self.neqs * (self.k_ar-1) +
                                                   num_det))

        y_lag1 = self._y_lag1
        b_y = beta.T.dot(y_lag1)
        omega11 = b_y.dot(b_y.T)
        omega12 = b_y.dot(self._delta_x.T)
        omega21 = omega12.T
        omega22 = self._delta_x.dot(self._delta_x.T)
        omega = np.bmat([[omega11, omega12],
                         [omega21, omega22]]).A

        mat1 = b_id.dot(inv(omega)).dot(b_id.T)
        return np.kron(mat1, self.sigma_u) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:vecm.py

示例5: _presample_varcov

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def _presample_varcov(self, params):
        """
        Returns the inverse of the presample variance-covariance.

        Notes
        -----
        See Hamilton p. 125
        """
        k = self.k_trend
        p = self.k_ar
        p1 = p+1

        # get inv(Vp) Hamilton 5.3.7
        params0 = np.r_[-1, params[k:]]

        Vpinv = np.zeros((p, p), dtype=params.dtype)
        for i in range(1, p1):
            Vpinv[i-1, i-1:] = np.correlate(params0, params0[:i],)[:-1]
            Vpinv[i-1, i-1:] -= np.correlate(params0[-i:], params0,)[:-1]

        Vpinv = Vpinv + Vpinv.T - np.diag(Vpinv.diagonal())
        return Vpinv 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:ar_model.py

示例6: _multivariate_ols_test

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def _multivariate_ols_test(hypotheses, fit_results, exog_names,
                            endog_names):
    def fn(L, M, C):
        # .. [1] https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_introreg_sect012.htm
        params, df_resid, inv_cov, sscpr = fit_results
        # t1 = (L * params)M
        t1 = L.dot(params).dot(M) - C
        # H = t1'L(X'X)^L't1
        t2 = L.dot(inv_cov).dot(L.T)
        q = matrix_rank(t2)
        H = t1.T.dot(inv(t2)).dot(t1)

        # E = M'(Y'Y - B'(X'X)B)M
        E = M.T.dot(sscpr).dot(M)
        return E, H, q, df_resid

    return _multivariate_test(hypotheses, exog_names, endog_names, fn) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:multivariate_ols.py

示例7: normal_eqn

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def normal_eqn(X, y):
    """Produces optimal theta via normal equation.

    Args:
        X (numpy.array): Features' dataset plus bias column.
        y (numpy.array): Column vector of expected values.

    Raises:
        LinAlgError

    Returns:
        numpy.array: Optimized model parameters theta.
    """
    n = X.shape[1]  # number of columns
    theta = zeros((n, 1), dtype=float64)

    X_T = X.T
    theta = inv(X_T.dot(X)).dot(X_T).dot(y)

    return theta 
开发者ID:Benardi,项目名称:touvlo,代码行数:22,代码来源:lin_rg.py

示例8: reg_normal_eqn

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def reg_normal_eqn(X, y, _lambda):
    """Produces optimal theta via normal equation.

    Args:
        X (numpy.array): Features' dataset plus bias column.
        y (numpy.array): Column vector of expected values.
        _lambda (float): The regularization hyperparameter.

    Returns:
        numpy.array: Optimized model parameters theta.
    """
    n = X.shape[1]  # number of columns, already has bias
    theta = zeros((n, 1), dtype=float64)
    L = identity(n)
    L[0, 0] = 0
    X_T = X.T

    theta = inv(X_T.dot(X) + _lambda * L).dot(X_T).dot(y)

    return theta 
开发者ID:Benardi,项目名称:touvlo,代码行数:22,代码来源:lin_rg.py

示例9: multi_gaussian

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def multi_gaussian(X, mu, sigma):
    """Estimates probability that examples belong to Multivariate Gaussian.

    Args:
        X (numpy.array): Features' dataset.
        mu (numpy.array): Mean of each feature/column of X.
        sigma (numpy.array): Covariance matrix for X.

    Returns:
        numpy.array: Probability density function for each example
    """
    m, n = X.shape
    X = X - mu

    factor = X.dot(inv(sigma))
    factor = multiply(factor, X)
    factor = - (1 / 2) * sum(factor, axis=1, keepdims=True)

    p = 1 / (power(2 * pi, n / 2) * sqrt(det(sigma)))
    p = p * exp(factor)

    return p 
开发者ID:Benardi,项目名称:touvlo,代码行数:24,代码来源:anmly_detc.py

示例10: test_basic

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def test_basic(self):
        import numpy.linalg as linalg

        A = array([[1., 2.],
                   [3., 4.]])
        mA = matrix(A)
        assert_(allclose(linalg.inv(A), mA.I))
        assert_(all(array(transpose(A) == mA.T)))
        assert_(all(array(transpose(A) == mA.H)))
        assert_(all(A == mA.A))

        B = A + 2j*A
        mB = matrix(B)
        assert_(allclose(linalg.inv(B), mB.I))
        assert_(all(array(transpose(B) == mB.T)))
        assert_(all(array(conjugate(transpose(B)) == mB.H))) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_defmatrix.py

示例11: _compute_covariance

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def _compute_covariance(self):
        self.factor = self.scotts_factor()
        # Cache covariance and inverse covariance of the data
        if not hasattr(self, '_data_inv_cov'):
            self._data_covariance = atleast_2d(np.cov(self.dataset, rowvar=1,
                                               bias=False))
            self._data_inv_cov = linalg.inv(self._data_covariance)

        self.covariance = self._data_covariance * self.factor**2
        self.inv_cov = self._data_inv_cov / self.factor**2
        self._norm_factor = sqrt(linalg.det(2*pi*self.covariance)) * self.n 
开发者ID:svviz,项目名称:svviz,代码行数:13,代码来源:kde.py

示例12: _compute_dxdy

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def _compute_dxdy(self, pos=None, lengths=None, weights=None, m=None):
        dEx, dEy, d2Ex2, d2Ey2, d2Exy, d2Eyx = self._compute_dE(pos,
                                                                lengths,
                                                                weights,
                                                                m)
        A = np.array([[d2Ex2, d2Exy], [d2Eyx, d2Ey2]])
        B = np.array([[-dEx], [-dEy]])
        X = inv(A).dot(B)
        dx = X[0]
        dy = X[1]
        return dx, dy 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:13,代码来源:graph_layout.py

示例13: inverse_transform

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def inverse_transform(transform):
        '''
        mdl.inverse_transform is the inverse transform (see RetinotopyMeshModel.transform).
        '''
        if transform is None: return None
        return pimms.imm_array(npla.inv(transform)) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:8,代码来源:models.py

示例14: get_from_std

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def get_from_std(self):
        '''
        Retrieve the matrix that transforms vectors from the standard basis
        to this basis.

        Returns
        -------
        numpy array or scipy sparse matrix
            An array of shape `(size, dim)` where `dim` is the dimension
            of this basis (the length of its vectors) and `size` is the
            size of this basis (its number of vectors).
        '''
        if self.sparse:
            if self.is_complete():
                return _spsl.inv(self.get_to_std().tocsc()).tocsr()
            else:
                assert(self.size < self.dim), "Basis seems to be overcomplete: size > dimension!"
                # we'd need to construct a different pseudo-inverse if the above assert fails

                A = self.get_to_std()  # shape (dim,size) - should have indep *cols*
                Adag = A.getH()        # shape (size, dim)
                invAdagA = _spsl.inv(Adag.tocsr().dot(A.tocsc())).tocsr()
                return invAdagA.dot(Adag.tocsc())
        else:
            if self.is_complete():
                return _inv(self.get_to_std())
            else:
                assert(self.size < self.dim), "Basis seems to be overcomplete: size > dimension!"
                # we'd need to construct a different pseudo-inverse if the above assert fails

                A = self.get_to_std()  # shape (dim,size) - should have indep *cols*
                Adag = A.transpose().conjugate()  # shape (size, dim)
                return _np.dot(_inv(_np.dot(Adag, A)), Adag) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:35,代码来源:basis.py

示例15: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import inv [as 别名]
def do(self, a, b, tags):
        a_inv = linalg.inv(a)
        assert_almost_equal(dot_generalized(a, a_inv),
                            identity_like_generalized(a))
        assert_(consistent_subclass(a_inv, a)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_linalg.py


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