예제 #1
0
 def _eval_determinant(self):
     if self.blockshape == (2, 2):
         [[A, B], [C, D]] = self.blocks.tolist()
         if ask(Q.invertible(A)):
             return det(A) * det(D - C * A.I * B)
         elif ask(Q.invertible(D)):
             return det(D) * det(A - B * D.I * C)
예제 #2
0
 def _eval_determinant(self):
     if self.blockshape == (2, 2):
         [[A, B],
          [C, D]] = self.blocks.tolist()
         if ask(Q.invertible(A)):
             return det(A)*det(D - C*A.I*B)
         elif ask(Q.invertible(D)):
             return det(D)*det(A - B*D.I*C)
     return Determinant(self)
예제 #3
0
 def pdf(self, *args):
     mu, sigma = Matrix(self.mu), Matrix(self.sigma)
     k = len(mu)
     args = Matrix(args)
     return  S(1)/sqrt((2*pi)**(k)*det(sigma))*exp(
         -S(1)/2*(mu - args).transpose()*(sigma**(-1)*\
             (mu - args)))[0]
예제 #4
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     k = mu.shape[0]
     args = ImmutableMatrix(args)
     x = args - mu
     return (S.One / sqrt((2 * pi)**(k) * det(sigma)) *
             exp(Rational(-1, 2) * x.transpose() * (sigma.inv() * x))[0])
예제 #5
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     k = len(mu)
     args = ImmutableMatrix(args)
     x = args - mu
     return  S(1)/sqrt((2*pi)**(k)*det(sigma))*exp(
         -S(1)/2*x.transpose()*(sigma.inv()*\
             x))[0]
예제 #6
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     k = len(mu)
     args = ImmutableMatrix(args)
     x = args - mu
     return  S(1)/sqrt((2*pi)**(k)*det(sigma))*exp(
         -S(1)/2*x.transpose()*(sigma.inv()*\
             x))[0]
예제 #7
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.shape_mat
     v = S(self.dof)
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     x = args - mu
     return gamma((k + v)/2)/(gamma(v/2)*(v*pi)**(k/2)*sqrt(det(sigma)))\
     *(1 + 1/v*(x.transpose()*sigma_inv*x)[0])**((-v - k)/2)
예제 #8
0
 def pdf(self, *args):
     from sympy.functions.special.gamma_functions import gamma
     mu, sigma = Matrix(self.mu), Matrix(self.shape_mat)
     v = S(self.dof)
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = Matrix(args)
     x = args - mu
     return gamma((k + v)/2)/(gamma(v/2)*(v*pi)**(k/2)*sqrt(det(sigma)))\
     *(1 + 1/v*(x.transpose()*sigma_inv*x)[0])**((-v - k)/2)
예제 #9
0
 def pdf(self, *args):
     from sympy.functions.special.gamma_functions import gamma
     mu, sigma = self.mu, self.shape_mat
     v = S(self.dof)
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     x = args - mu
     return gamma((k + v)/2)/(gamma(v/2)*(v*pi)**(k/2)*sqrt(det(sigma)))\
     *(1 + 1/v*(x.transpose()*sigma_inv*x)[0])**((-v - k)/2)
예제 #10
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     k = mu.shape[0]
     if len(args) == 1 and args[0].is_Matrix:
         args = args[0]
     else:
         args = ImmutableMatrix(args)
     x = args - mu
     density = S.One / sqrt((2 * pi)**(k) * det(sigma)) * exp(
         Rational(-1, 2) * x.transpose() * (sigma.inv() * x))
     return MatrixElement(density, 0, 0)
예제 #11
0
 def marginal_distribution(self, indices, sym):
     sym = Matrix([Symbol(str(Indexed(sym, i))) for i in indices])
     _mu, _sigma = Matrix(self.mu), Matrix(self.sigma)
     k = len(self.mu)
     for i in range(k):
         if i not in indices:
             _mu.row_del(i)
             _sigma.col_del(i)
             _sigma.row_del(i)
     return Lambda(sym, S(1)/sqrt((2*pi)**(len(_mu))*det(_sigma))*exp(
         -S(1)/2*(_mu - sym).transpose()*(_sigma**(-1)*\
             (_mu - sym)))[0])
예제 #12
0
 def _marginal_distribution(self, indices, sym):
     sym = ImmutableMatrix([Indexed(sym, i) for i in indices])
     _mu, _sigma = self.mu, self.sigma
     k = self.mu.shape[0]
     for i in range(k):
         if i not in indices:
             _mu = _mu.row_del(i)
             _sigma = _sigma.col_del(i)
             _sigma = _sigma.row_del(i)
     return Lambda(tuple(sym), S.One/sqrt((2*pi)**(len(_mu))*det(_sigma))*exp(
         Rational(-1, 2)*(_mu - sym).transpose()*(_sigma.inv()*\
             (_mu - sym)))[0])
예제 #13
0
 def marginal_distribution(self, indices, sym):
     sym = ImmutableMatrix([Indexed(sym, i) for i in indices])
     _mu, _sigma = self.mu, self.sigma
     k = len(self.mu)
     for i in range(k):
         if i not in indices:
             _mu = _mu.row_del(i)
             _sigma = _sigma.col_del(i)
             _sigma = _sigma.row_del(i)
     return Lambda(sym, S(1)/sqrt((2*pi)**(len(_mu))*det(_sigma))*exp(
         -S(1)/2*(_mu - sym).transpose()*(_sigma.inv()*\
             (_mu - sym)))[0])
예제 #14
0
 def marginal_distribution(self, indices, sym):
     sym = ImmutableMatrix([Indexed(sym, i) for i in indices])
     _mu, _sigma = self.mu, self.sigma
     k = len(self.mu)
     for i in range(k):
         if i not in indices:
             _mu = _mu.row_del(i)
             _sigma = _sigma.col_del(i)
             _sigma = _sigma.row_del(i)
     return Lambda(sym, S(1)/sqrt((2*pi)**(len(_mu))*det(_sigma))*exp(
         -S(1)/2*(_mu - sym).transpose()*(_sigma.inv()*\
             (_mu - sym)))[0])
예제 #15
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     mu_T = mu.transpose()
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     args_T = args.transpose()
     x = (mu_T*sigma_inv*mu)[0]
     y = (args_T*sigma_inv*args)[0]
     v = 1 - k/2
     return S(2)/((2*pi)**(S(k)/2)*sqrt(det(sigma)))\
     *(y/(2 + x))**(S(v)/2)*besselk(v, sqrt((2 + x)*(y)))\
     *exp((args_T*sigma_inv*mu)[0])
예제 #16
0
 def pdf(self, *args):
     mu, sigma = self.mu, self.sigma
     mu_T = mu.transpose()
     k = S(mu.shape[0])
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     args_T = args.transpose()
     x = (mu_T*sigma_inv*mu)[0]
     y = (args_T*sigma_inv*args)[0]
     v = 1 - k/2
     return (2 * (y/(2 + x))**(v/2) * besselk(v, sqrt((2 + x)*y)) *
             exp((args_T * sigma_inv * mu)[0]) /
             ((2 * pi)**(k/2) * sqrt(det(sigma))))
예제 #17
0
 def pdf(self, *args):
     from sympy.functions.special.bessel import besselk
     mu, sigma = self.mu, self.sigma
     mu_T = mu.transpose()
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     args_T = args.transpose()
     x = (mu_T*sigma_inv*mu)[0]
     y = (args_T*sigma_inv*args)[0]
     v = 1 - k/2
     return S(2)/((2*pi)**(S(k)/2)*sqrt(det(sigma)))\
     *(y/(2 + x))**(S(v)/2)*besselk(v, sqrt((2 + x)*(y)))\
     *exp((args_T*sigma_inv*mu)[0])
예제 #18
0
 def pdf(self, *args):
     from sympy.functions.special.bessel import besselk
     mu, sigma = Matrix(self.mu), Matrix(self.sigma)
     mu_T = mu.transpose()
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = Matrix(args)
     args_T = args.transpose()
     x = (mu_T * sigma_inv * mu)[0]
     y = (args_T * sigma_inv * args)[0]
     v = 1 - k / 2
     return S(2)/((2*pi)**(S(k)/2)*sqrt(det(sigma)))\
     *(y/(2 + x))**(S(v)/2)*besselk(v, sqrt((2 + x)*(y)))\
     *exp((args_T*sigma_inv*mu)[0])
예제 #19
0
def test_MatrixSymbol_determinant():
    A = MatrixSymbol('A', 4, 4)
    assert A.as_explicit().det() == A[0, 0]*A[1, 1]*A[2, 2]*A[3, 3] - \
        A[0, 0]*A[1, 1]*A[2, 3]*A[3, 2] - A[0, 0]*A[1, 2]*A[2, 1]*A[3, 3] + \
        A[0, 0]*A[1, 2]*A[2, 3]*A[3, 1] + A[0, 0]*A[1, 3]*A[2, 1]*A[3, 2] - \
        A[0, 0]*A[1, 3]*A[2, 2]*A[3, 1] - A[0, 1]*A[1, 0]*A[2, 2]*A[3, 3] + \
        A[0, 1]*A[1, 0]*A[2, 3]*A[3, 2] + A[0, 1]*A[1, 2]*A[2, 0]*A[3, 3] - \
        A[0, 1]*A[1, 2]*A[2, 3]*A[3, 0] - A[0, 1]*A[1, 3]*A[2, 0]*A[3, 2] + \
        A[0, 1]*A[1, 3]*A[2, 2]*A[3, 0] + A[0, 2]*A[1, 0]*A[2, 1]*A[3, 3] - \
        A[0, 2]*A[1, 0]*A[2, 3]*A[3, 1] - A[0, 2]*A[1, 1]*A[2, 0]*A[3, 3] + \
        A[0, 2]*A[1, 1]*A[2, 3]*A[3, 0] + A[0, 2]*A[1, 3]*A[2, 0]*A[3, 1] - \
        A[0, 2]*A[1, 3]*A[2, 1]*A[3, 0] - A[0, 3]*A[1, 0]*A[2, 1]*A[3, 2] + \
        A[0, 3]*A[1, 0]*A[2, 2]*A[3, 1] + A[0, 3]*A[1, 1]*A[2, 0]*A[3, 2] - \
        A[0, 3]*A[1, 1]*A[2, 2]*A[3, 0] - A[0, 3]*A[1, 2]*A[2, 0]*A[3, 1] + \
        A[0, 3]*A[1, 2]*A[2, 1]*A[3, 0]

    B = MatrixSymbol('B', 4, 4)
    assert Determinant(A + B).doit() == det(A + B) == (A + B).det()
예제 #20
0
 def det(self):
     from sympy.matrices.expressions.determinant import det
     return det(self)
예제 #21
0
 def _eval_determinant(self):
     from sympy.matrices.expressions.determinant import det
     return det(self.base)**self.exp
예제 #22
0
 def _eval_determinant(self):
     from sympy.matrices.expressions.determinant import det
     return 1/det(self.arg)
예제 #23
0
 def _eval_determinant(self):
     if self._all_square_blocks():
         return Mul(*[det(mat) for mat in self.args])
     # At least one block is non-square.  Since the entire matrix must be square we know there must
     # be at least two blocks in this matrix, in which case the entire matrix is necessarily rank-deficient
     return S.Zero
예제 #24
0
파일: transpose.py 프로젝트: cklb/sympy
 def _eval_determinant(self):
     from sympy.matrices.expressions.determinant import det
     return det(self.arg)
예제 #25
0
def apply(A):
    n = A.shape[0]
    k = Symbol.k(integer=True)
    return Equality(det(Sum[k:1:n - 1]((Shift(n, 0, n - 1)**k) @ A)),
                    det(A) * (n - 1) * (-1)**(n - 1))