示例#1
0
    def __init__(self,
                 mu=array([0, 0]),
                 Sigma=eye(2),
                 is_cholesky=False,
                 ell=None):
        Distribution.__init__(self, len(Sigma))

        assert (len(shape(mu)) == 1)
        assert (max(shape(Sigma)) == len(mu))
        self.mu = mu
        self.ell = ell
        if is_cholesky:
            self.L = Sigma
            if ell == None:
                assert (shape(Sigma)[0] == shape(Sigma)[1])
            else:
                assert (shape(Sigma)[1] == ell)
        else:
            assert (shape(Sigma)[0] == shape(Sigma)[1])
            if ell is not None:
                self.L, _, _ = MatrixTools.low_rank_approx(Sigma, ell)
                self.L = self.L.T
                assert (shape(self.L)[1] == ell)
            else:
                try:
                    self.L = cholesky(Sigma)
                except LinAlgError:
                    # some really crude check for PSD (which only corrects for orunding errors
                    self.L = cholesky(Sigma + eye(len(Sigma)) * 1e-5)
示例#2
-1
 def __init__(self, mu=array([0, 0]), Sigma=eye(2), is_cholesky=False, ell=None):
     Distribution.__init__(self, len(Sigma))
     
     assert(len(shape(mu)) == 1)
     assert(max(shape(Sigma)) == len(mu))
     self.mu = mu
     self.ell = ell
     if is_cholesky: 
         self.L = Sigma
         if ell == None:
             assert(shape(Sigma)[0] == shape(Sigma)[1])
         else:
             assert(shape(Sigma)[1] == ell)
     else: 
         assert(shape(Sigma)[0] == shape(Sigma)[1])
         if ell is not None:
             self.L, _, _ = MatrixTools.low_rank_approx(Sigma, ell)
             self.L = self.L.T
             assert(shape(self.L)[1] == ell)
         else:
             try:
                 self.L = cholesky(Sigma)
             except LinAlgError:
                 # some really crude check for PSD (which only corrects for orunding errors
                 self.L = cholesky(Sigma+eye(len(Sigma))*1e-5)