numpy.linalg.det - python examples

Here are the examples of the python api numpy.linalg.det taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

5 View Complete Implementation : distance.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : alexandrebarachant
def distance_logdet(A, B):
    """Log-det distance between two covariance matrices A and B.

    .. math::
            d = \sqrt{\left(\log(\det(\\frac{\mathbf{A}+\mathbf{B}}{2})) - 0.5 \\times \log(\det(\mathbf{A}) \det(\mathbf{B}))\\right)}

    :param A: First covariance matrix
    :param B: Second covariance matrix
    :returns: Log-Euclid distance between A and B

    """
    return numpy.sqrt(numpy.log(numpy.linalg.det(
        (A + B) / 2.0)) - 0.5 * numpy.log(numpy.linalg.det(A)*numpy.linalg.det(B)))

3 View Complete Implementation : test_linalg.py
Copyright MIT License
Author : ktraunmueller
    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)
        astert_almost_equal(d, multiply.reduce(ev, axis=-1))
        astert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

        s = np.atleast_1d(s)
        ld = np.atleast_1d(ld)
        m = (s != 0)
        astert_almost_equal(np.abs(s[m]), 1)
        astert_equal(ld[~m], -inf)

3 View Complete Implementation : test_linalg.py
Copyright MIT License
Author : ktraunmueller
    def test_zero(self):
        astert_equal(linalg.det([[0.0]]), 0.0)
        astert_equal(type(linalg.det([[0.0]])), double)
        astert_equal(linalg.det([[0.0j]]), 0.0)
        astert_equal(type(linalg.det([[0.0j]])), cdouble)

        astert_equal(linalg.slogdet([[0.0]]), (0.0, -inf))
        astert_equal(type(linalg.slogdet([[0.0]])[0]), double)
        astert_equal(type(linalg.slogdet([[0.0]])[1]), double)
        astert_equal(linalg.slogdet([[0.0j]]), (0.0j, -inf))
        astert_equal(type(linalg.slogdet([[0.0j]])[0]), cdouble)
        astert_equal(type(linalg.slogdet([[0.0j]])[1]), double)

3 View Complete Implementation : test_basic.py
Copyright MIT License
Author : ktraunmueller
    def test_random(self):
        basic_det = linalg.det
        n = 20
        for i in range(4):
            a = random([n,n])
            d1 = det(a)
            d2 = basic_det(a)
            astert_almost_equal(d1,d2)

3 View Complete Implementation : test_linalg.py
Copyright Apache License 2.0
Author : dnanexus
    def test_zero(self):
        astert_equal(linalg.det([[0.0]]), 0.0)
        astert_equal(type(linalg.det([[0.0]])), double)
        astert_equal(linalg.det([[0.0j]]), 0.0)
        astert_equal(type(linalg.det([[0.0j]])), cdouble)

        astert_equal(linalg.slogdet([[0.0]]), (0.0, -inf))
        astert_equal(type(linalg.slogdet([[0.0]])[0]), double)
        astert_equal(type(linalg.slogdet([[0.0]])[1]), double)
        astert_equal(linalg.slogdet([[0.0j]]), (0.0j, -inf))
        astert_equal(type(linalg.slogdet([[0.0j]])[0]), cdouble)
        astert_equal(type(linalg.slogdet([[0.0j]])[1]), double)

3 View Complete Implementation : mixed.py
Copyright MIT License
Author : birforce
    def logL(self, ML=False):
        """
        Return log-likelihood, REML by default.

        """
        #I don't know what the difference between REML and ML is here.
        logL = 0.

        for unit in self.units:
            logL += unit.logL(a=self.a, ML=ML)
        if not ML:
            logL += np.log(L.det(self.Sinv)) / 2
        return logL

3 View Complete Implementation : outliers_influence.py
Copyright MIT License
Author : birforce
    @cache_readonly
    def cov_ratio(self):
        '''(cached attribute) covariance ratio between LOOO and original

        This uses determinant of the estimate of the parameter covariance
        from leave-one-out estimates.
        requires leave one out loop for observations

        '''
        #don't use inplace division / because then we change original
        cov_ratio = (self.det_cov_params_not_obsi
                            / np.linalg.det(self.results.cov_params()))
        return cov_ratio

3 View Complete Implementation : test_basic.py
Copyright MIT License
Author : ktraunmueller
    def test_random_complex(self):
        basic_det = linalg.det
        n = 20
        for i in range(4):
            a = random([n,n]) + 2j*random([n,n])
            d1 = det(a)
            d2 = basic_det(a)
            astert_allclose(d1, d2, rtol=1e-13)

3 View Complete Implementation : test_basic.py
Copyright MIT License
Author : ktraunmueller
    def test_random(self):
        basic_det = linalg.det
        n = 20
        for i in range(4):
            a = random([n,n])
            d1 = det(a)
            d2 = basic_det(a)
            astert_almost_equal(d1,d2)

3 View Complete Implementation : test_linalg.py
Copyright Apache License 2.0
Author : dnanexus
    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)
        astert_almost_equal(d, multiply.reduce(ev, axis=-1))
        astert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

        s = np.atleast_1d(s)
        ld = np.atleast_1d(ld)
        m = (s != 0)
        astert_almost_equal(np.abs(s[m]), 1)
        astert_equal(ld[~m], -inf)