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


Python linalg.det方法代码示例

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


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

示例1: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [as 别名]
def do(self, a, b, tags):
        d = linalg.det(a)
        (s, ld) = linalg.slogdet(a)
        if asarray(a).dtype.type in (single, double):
            ad = asarray(a).astype(double)
        else:
            ad = asarray(a).astype(cdouble)
        ev = linalg.eigvals(ad)
        assert_almost_equal(d, multiply.reduce(ev, axis=-1))
        assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

        s = np.atleast_1d(s)
        ld = np.atleast_1d(ld)
        m = (s != 0)
        assert_almost_equal(np.abs(s[m]), 1)
        assert_equal(ld[~m], -inf) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_linalg.py

示例2: test_byteorder_check

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [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

示例3: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [as 别名]
def do(self, a, b):
        d = linalg.det(a)
        (s, ld) = linalg.slogdet(a)
        if asarray(a).dtype.type in (single, double):
            ad = asarray(a).astype(double)
        else:
            ad = asarray(a).astype(cdouble)
        ev = linalg.eigvals(ad)
        assert_almost_equal(d, multiply.reduce(ev, axis=-1))
        assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

        s = np.atleast_1d(s)
        ld = np.atleast_1d(ld)
        m = (s != 0)
        assert_almost_equal(np.abs(s[m]), 1)
        assert_equal(ld[~m], -inf) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:test_linalg.py

示例4: test_0_size

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [as 别名]
def test_0_size(self):
        a = np.zeros((0, 0), dtype=np.complex64)
        res = linalg.det(a)
        assert_equal(res, 1.)
        assert_(res.dtype.type is np.complex64)
        res = linalg.slogdet(a)
        assert_equal(res, (1, 0))
        assert_(res[0].dtype.type is np.complex64)
        assert_(res[1].dtype.type is np.float32)

        a = np.zeros((0, 0), dtype=np.float64)
        res = linalg.det(a)
        assert_equal(res, 1.)
        assert_(res.dtype.type is np.float64)
        res = linalg.slogdet(a)
        assert_equal(res, (1, 0))
        assert_(res[0].dtype.type is np.float64)
        assert_(res[1].dtype.type is np.float64) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_linalg.py

示例5: logL

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [as 别名]
def logL(self, a, ML=False):
        """
        Individual contributions to the log-likelihood, tries to return REML
        contribution by default though this requires estimated
        fixed effect a to be passed as an argument.

        no constant with pi included

        a is not used if ML=true  (should be a=None in signature)
        If ML is false, then the residuals are calculated for the given fixed
        effects parameters a.
        """

        if ML:
            return (np.log(L.det(self.W)) - (self.r * np.dot(self.W, self.r)).sum()) / 2.
        else:
            if a is None:
                raise ValueError('need fixed effect a for REML contribution to log-likelihood')
            r = self.Y - np.dot(self.X, a)
            return (np.log(L.det(self.W)) - (r * np.dot(self.W, r)).sum()) / 2. 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:mixed.py

示例6: multi_gaussian

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [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

示例7: __call__

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import det [as 别名]
def __call__(self, params):
        print '???', params
        sd1 = params[0]
        sd2 = params[1]
        cor = params[2]

        if sd1 < 0. or sd1 > 10. or sd2 < 0. or sd2 > 10. or cor < -1. or cor > 1.:
            return np.inf

        bandwidth = maths.stats.choleskysqrt2d(sd1, sd2, cor)
        bandwidthdet = la.det(bandwidth)
        bandwidthinv = la.inv(bandwidth)

        diff = sample[self.__iidx] - sample[self.__jidx]
        temp = diff.dot(bandwidthinv.T)
        temp *= temp
        e = np.exp(np.sum(temp, axis=1))
        s = np.sum(e**(-.25) - 4 * e**(-.5))

        cost = self.__n / bandwidthdet + (2. / bandwidthdet) * s
        print '!!!', cost
        return cost / 10000. 
开发者ID:thalesians,项目名称:bayestsa,代码行数:24,代码来源:studykde.py


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