本文整理匯總了Python中numpy.linalg.slogdet方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.slogdet方法的具體用法?Python linalg.slogdet怎麽用?Python linalg.slogdet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.linalg
的用法示例。
在下文中一共展示了linalg.slogdet方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: do
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [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)
示例2: do
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [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)
示例3: test_0_size
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [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)
示例4: initialize
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [as 別名]
def initialize(self):
""" Initialize members for faster scoring. """
self.ct = self.cw + self.cb
self.p = inv(self.ct * 0.5) - inv(0.5 * self.cw + self.cb)
self.q = inv(2 * self.cw) - inv(2 * self.ct)
k1 = reduce(operator.mul, slogdet(0.5 * self.ct))
k2 = reduce(operator.mul, slogdet(0.5 * self.cw + self.cb))
k3 = reduce(operator.mul, slogdet(2 * self.ct))
k4 = reduce(operator.mul, slogdet(2 * self.cw))
self.k = 0.5 * (k1 - k2 + k3 - k4)
self.r = 0.5 * (0.25 * self.p - self.q)
self.s = 0.5 * (0.25 * self.p + self.q)
self.t = 0.25 * np.dot(self.p, self.mean.T)
u1 = 2 * np.dot(self.mean, 0.25 * self.p)
self.u = self.k + np.dot(u1, self.mean.T)
self.initialized = True
示例5: error
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [as 別名]
def error(self, start, end):
"""Return the approximation cost on the segment [start:end].
Args:
start (int): start of the segment
end (int): end of the segment
Returns:
float: segment cost
Raises:
NotEnoughPoints: when the segment is too short (less than ``'min_size'`` samples).
"""
if end - start < self.min_size:
raise NotEnoughPoints
sub = self.signal[start:end]
if self.signal.shape[1] > 1:
cov = np.cov(sub.T)
else:
cov = np.array([[sub.var()]])
_, val = slogdet(cov)
return val * (end - start)
示例6: orientation
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [as 別名]
def orientation(face, origin):
"""Compute the orientation of the face with respect to a point, origin.
Parameters
----------
face : array-like, of shape (N-dim, N-dim)
The hyperplane we want to know the orientation of
Do notice that the order in which you provide the points is critical
origin : array-like, point of shape (N-dim)
The point to compute the orientation from
Returns
-------
0 if the origin lies in the same hyperplane as face,
-1 or 1 to indicate left or right orientation
If two points lie on the same side of the face, the orientation will
be equal, if they lie on the other side of the face, it will be negated.
"""
vectors = array(face)
sign, logdet = slogdet(vectors - origin)
if logdet < -50: # assume it to be zero when it's close to zero
return 0
return sign
示例7: test_zero
# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import slogdet [as 別名]
def test_zero(self):
assert_equal(linalg.det([[0.0]]), 0.0)
assert_equal(type(linalg.det([[0.0]])), double)
assert_equal(linalg.det([[0.0j]]), 0.0)
assert_equal(type(linalg.det([[0.0j]])), cdouble)
assert_equal(linalg.slogdet([[0.0]]), (0.0, -inf))
assert_equal(type(linalg.slogdet([[0.0]])[0]), double)
assert_equal(type(linalg.slogdet([[0.0]])[1]), double)
assert_equal(linalg.slogdet([[0.0j]]), (0.0j, -inf))
assert_equal(type(linalg.slogdet([[0.0j]])[0]), cdouble)
assert_equal(type(linalg.slogdet([[0.0j]])[1]), double)