コード例 #1
0
    def __init__(self, mu, spread, flip_at_least_one=True):
        if not type(mu) is numpy.ndarray:
            raise TypeError("Mean vector must be a numpy array")

        if not len(mu.shape) == 1:
            raise ValueError("Mean vector must be a 1D numpy array")

        if not len(mu) > 0:
            raise ValueError("Mean vector dimension must be positive")

        if mu.dtype != numpy.bool8:
            raise ValueError("Mean must be a bool8 numpy array")

        Distribution.__init__(self, len(mu))

        if not type(spread) is float:
            raise TypeError("Spread must be a float")

        if not (spread > 0. and spread < 1.):
            raise ValueError("Spread must be a probability")

        if not type(flip_at_least_one) is bool:
            raise ValueError("Flip at least one must be a boolean")

        self.mu = mu
        self.spread = spread
        self.flip_at_least_one = flip_at_least_one
コード例 #2
0
    def __init__(self, mu, spread, flip_at_least_one=True):
        if not type(mu) is numpy.ndarray:
            raise TypeError("Mean vector must be a numpy array")
        
        if not len(mu.shape) == 1:
            raise ValueError("Mean vector must be a 1D numpy array")
        
        if not len(mu) > 0:
            raise ValueError("Mean vector dimension must be positive")
        
        if mu.dtype != numpy.bool8:
            raise ValueError("Mean must be a bool8 numpy array")
        
        Distribution.__init__(self, len(mu))

        if not type(spread) is float:
            raise TypeError("Spread must be a float")
        
        if not (spread > 0. and spread < 1.):
            raise ValueError("Spread must be a probability")
        
        if not type(flip_at_least_one) is bool:
            raise ValueError("Flip at least one must be a boolean")
        
        self.mu = mu
        self.spread = spread
        self.flip_at_least_one = flip_at_least_one
コード例 #3
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)
コード例 #4
0
    def __init__(self, X, y, n_importance, prior, ridge=None):
        Distribution.__init__(self, dimension=shape(X)[1])

        self.n_importance = n_importance
        self.prior = prior
        self.ridge = ridge
        self.X = X
        self.y = y
 def __init__(self, X, y, n_importance, prior, ridge=None):
     Distribution.__init__(self, dimension=shape(X)[1])
     
     self.n_importance=n_importance
     self.prior=prior
     self.ridge=ridge
     self.X=X
     self.y=y
コード例 #6
0
ファイル: Flower.py プロジェクト: karlnapf/kameleon-mcmc
 def __init__(self, amplitude=6, frequency=6, variance=1, radius=10, dimension=2):
     Distribution.__init__(self, dimension)
     
     self.amplitude = amplitude
     self.frequency = frequency
     self.variance = variance
     self.radius = radius
     
     assert(dimension >= 2)
コード例 #7
0
 def __init__(self, prior=None, logdet_alg="shogun_exact",
              solve_method="shogun", shogun_loglevel=2):
     Distribution.__init__(self, dimension=2)
     
     self.prior = prior
     self.logdet_alg = logdet_alg
     self.solve_method = solve_method
     
     LogDetEstimator().io.set_loglevel(shogun_loglevel)
     LogDetEstimator().io.set_location_info(1)
コード例 #8
0
ファイル: Discrete.py プロジェクト: mgong2/kameleon-mcmc
 def __init__(self, omega, support=None):
     Distribution.__init__(self, dimension=None)
     assert (abs(sum(omega) - 1) < 1e-6)
     if support == None:
         support = range(len(omega))
     else:
         assert (len(omega) == len(support))
     self.num_objects = len(omega)
     self.omega = omega
     self.cdf = np.cumsum(omega)
     self.support = support
コード例 #9
0
ファイル: Discrete.py プロジェクト: karlnapf/kameleon-mcmc
 def __init__(self, omega, support=None):
     Distribution.__init__(self, dimension=None)
     assert(abs(sum(omega) - 1) < 1e-6)
     if support == None:
         support = range(len(omega))
     else:
         assert(len(omega) == len(support))
     self.num_objects = len(omega)
     self.omega = omega
     self.cdf = np.cumsum(omega)
     self.support = support
 def __init__(self, X, y, n_importance, prior, ridge=None):
     Distribution.__init__(self, dimension=shape(X)[1])
     
     self.n_importance=n_importance
     self.prior=prior
     self.ridge=ridge
     self.X=X
     self.y=y
     
     # compute alphabet sizes based on number of unique elements for each
     # covariate in the cateogrical input data represented as reals
     self.alphabet_sizes=array([len(set(X[:,i])) for i in range(X.shape[1])],
                               dtype=int32)
    def __init__(self, X, y, n_importance, prior, ridge=None):
        Distribution.__init__(self, dimension=shape(X)[1])

        self.n_importance = n_importance
        self.prior = prior
        self.ridge = ridge
        self.X = X
        self.y = y

        # compute alphabet sizes based on number of unique elements for each
        # covariate in the cateogrical input data represented as reals
        self.alphabet_sizes = array(
            [len(set(X[:, i])) for i in range(X.shape[1])], dtype=int32)
コード例 #12
0
    def __init__(self,
                 prior=None,
                 logdet_alg="shogun_exact",
                 solve_method="shogun",
                 shogun_loglevel=2):
        Distribution.__init__(self, dimension=2)

        self.prior = prior
        self.logdet_alg = logdet_alg
        self.solve_method = solve_method

        LogDetEstimator().io.set_loglevel(shogun_loglevel)
        LogDetEstimator().io.set_location_info(1)
コード例 #13
0
ファイル: Bernoulli.py プロジェクト: karlnapf/kameleon-mcmc
 def __init__(self, ps):
     if not type(ps) is numpy.ndarray:
         raise TypeError("Probability vector must be a numpy array")
     
     Distribution.__init__(self, len(ps))
     
     if not len(ps) > 0:
         raise ValueError("Probability vector must contain at least one element")
     
     if not all(ps > 0) and all (ps < 1):
         raise ValueError("Probability vector must lie in (0,1)")
         
     self.ps = ps
コード例 #14
0
 def __init__(self, dimension=2, num_components=2, components=None, mixing_proportion=None):
     Distribution.__init__(self, dimension)
     self.num_components = num_components
     if (components == None):
         self.components = [Gaussian(mu=zeros(self.dimension),Sigma=eye(self.dimension)) for _ in range(self.num_components)]
     else:
         assert(len(components)==self.num_components)
         self.components=components
     if (mixing_proportion == None):
         self.mixing_proportion=Discrete((1.0/num_components)*ones([num_components]))
     else:
         assert(num_components==mixing_proportion.num_objects)
         self.mixing_proportion = mixing_proportion
コード例 #15
0
    def __init__(self,
                 full_target,
                 current_state,
                 schedule="in_turns",
                 index_block=None):
        """
        full_target   - Distribution instance on which Gibbs sampling is performed
        current_state - Current point of the Gibbs sampler, represented as a
                        list of arbritary objects.
        schedule      - Schedule for variables
        index_block   - If schedule is "in_turns", this can specify the order.
                        If not specified, arange(dimension) is used
        """
        if not type(current_state) is type([]):
            raise TypeError("Current state must be a list")

        Distribution.__init__(self, len(current_state))

        if not isinstance(full_target, Distribution):
            raise TypeError("Given full target is not a Distribution")

        if index_block is None:
            index_block = arange(self.dimension, dtype=numpy.int64)

        if not type(schedule) is type(""):
            raise TypeError("Schedule must be a string")

        if not schedule in FullConditionals.schedules:
            raise ValueError("Unknown schedule")

        if not type(index_block) is numpy.ndarray:
            raise TypeError("Index block must be numpy array")

        if not len(index_block.shape) is 1:
            raise TypeError("Index block must be 1D numpy array")

        if not len(index_block) is self.dimension:
            raise ValueError("Index block dimension does not match number of \
                                Gibbs blocks")

        if not index_block.dtype == numpy.int:
            raise ValueError("Index block must be integer numpy array")

        self.full_target = full_target
        self.current_state = current_state
        self.schedule = schedule
        self.index_block = index_block

        # this is the current index of the Gibbs block
        # initialise with last, to cause the first sample come from the first
        self.current_idx = self.dimension
コード例 #16
0
    def __init__(self,
                 amplitude=6,
                 frequency=6,
                 variance=1,
                 radius=10,
                 dimension=2):
        Distribution.__init__(self, dimension)

        self.amplitude = amplitude
        self.frequency = frequency
        self.variance = variance
        self.radius = radius

        assert (dimension >= 2)
コード例 #17
0
 def __init__(self, W, biasx, biash):
     GenericTests.check_type(W,'W',numpy.ndarray,2)
     GenericTests.check_type(biasx,'biasx',numpy.ndarray,1)
     GenericTests.check_type(biash,'biash',numpy.ndarray,1)
     if not biash.shape[0]==W.shape[0]:
         raise ValueError("dimensions of W and biash must agree along # of hidden units")
     if not biasx.shape[0]==W.shape[1]:
         raise ValueError("dimensions of W and biasx must agree along # of visible units")
     
     Distribution.__init__(self, W.shape[1])
     
     self.W = W
     self.biasx = biasx
     self.biash = biash
     self.num_hidden_units = W.shape[0]
コード例 #18
0
ファイル: Hopfield.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "W=" + str(self.W)    
     s += "bias=" + str(self.bias)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #19
0
ファイル: Ring.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "variance=" + str(self.variance)
     s += ", radius=" + str(self.radius)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #20
0
 def __str__(self):
     s=self.__class__.__name__+ "=["
     s += "components="+ str(self.components)
     s += ", mixing_proportion="+ str(self.mixing_proportion)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #21
0
ファイル: Banana.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "bananicity=" + str(self.bananicity)
     s += ", V=" + str(self.V)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #22
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "mu=" + str(self.mu)
     s += ", L=" + str(self.L)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #23
0
ファイル: Gaussian.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "mu=" + str(self.mu)
     s += ", L=" + str(self.L)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #24
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "spread=" + str(self.ps)
     s += ", flip_at_least_one=" + str(self.flip_at_least_one)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #25
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "W=" + str(self.W)
     s += "bias=" + str(self.bias)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #26
0
ファイル: Banana.py プロジェクト: mgong2/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "bananicity=" + str(self.bananicity)
     s += ", V=" + str(self.V)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #27
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "spread=" + str(self.ps)
     s += ", flip_at_least_one=" + str(self.flip_at_least_one)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #28
0
ファイル: Banana.py プロジェクト: mgong2/kameleon-mcmc
 def get_plotting_bounds(self):
     if self.bananicity == 0.03 and self.V == 100.0:
         return [(-20, 20), (-7, 12)]
     elif self.bananicity == 0.1 and self.V == 100.0:
         return [(-20, 20), (-5, 30)]
     else:
         return Distribution.get_plotting_bounds(self)
コード例 #29
0
ファイル: Banana.py プロジェクト: karlnapf/kameleon-mcmc
 def get_plotting_bounds(self):
     if self.bananicity == 0.03 and self.V == 100.0:
         return [(-20, 20), (-7, 12)]
     elif self.bananicity == 0.1 and self.V == 100.0:
         return [(-20, 20), (-5, 30)]
     else:
         return Distribution.get_plotting_bounds(self)
コード例 #30
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "components=" + str(self.components)
     s += ", mixing_proportion=" + str(self.mixing_proportion)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #31
0
 def __init__(self, full_target, current_state, schedule="in_turns", index_block=None):
     """
     full_target   - Distribution instance on which Gibbs sampling is performed
     current_state - Current point of the Gibbs sampler, represented as a
                     list of arbritary objects.
     schedule      - Schedule for variables
     index_block   - If schedule is "in_turns", this can specify the order.
                     If not specified, arange(dimension) is used
     """
     if not type(current_state) is type([]):
         raise TypeError("Current state must be a list")
     
     Distribution.__init__(self, len(current_state))
     
     if not isinstance(full_target, Distribution):
         raise TypeError("Given full target is not a Distribution")
     
     if index_block is None:
         index_block = arange(self.dimension, dtype=numpy.int64)
     
     if not type(schedule) is type(""):
         raise TypeError("Schedule must be a string") 
     
     if not schedule in FullConditionals.schedules:
         raise ValueError("Unknown schedule") 
     
     if not type(index_block) is numpy.ndarray:
         raise TypeError("Index block must be numpy array")
     
     if not len(index_block.shape) is 1:
         raise TypeError("Index block must be 1D numpy array")
     
     if not len(index_block) is self.dimension:
         raise ValueError("Index block dimension does not match number of \
                             Gibbs blocks")
     
     if not index_block.dtype == numpy.int:
         raise ValueError("Index block must be integer numpy array")
     
     self.full_target = full_target
     self.current_state = current_state
     self.schedule = schedule
     self.index_block = index_block
     
     # this is the current index of the Gibbs block
     # initialise with last, to cause the first sample come from the first
     self.current_idx = self.dimension
コード例 #32
0
 def __init__(self, mu, spread, N=3):
     GenericTests.check_type(mu, 'mu', numpy.ndarray, 1)
     GenericTests.check_type(spread, 'spread', float)
     GenericTests.check_type(N, 'N', int)
     
     if mu.dtype != numpy.bool8:
         raise ValueError("Mean must be a bool8 numpy array")
     
     Distribution.__init__(self, len(mu))
     
     
     if not (spread > 0. and spread < 1.):
         raise ValueError("Spread must be a probability")
     
     self.mu = mu
     self.spread = spread
     self.N = N
コード例 #33
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "mu=" + str(self.mu)
     s += "spread=" + str(self.spread)
     s += "N=" + str(self.N)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #34
0
ファイル: Discrete.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "num_objects=" + str(self.num_objects)
     s += ", omega=" + str(self.omega)
     s += ", cdf=" + str(self.cdf)
     s += ", support=" + str(self.support)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #35
0
ファイル: Flower.py プロジェクト: karlnapf/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "amplitude=" + str(self.amplitude)
     s += ", frequency=" + str(self.frequency)
     s += ", variance=" + str(self.variance)
     s += ", radius=" + str(self.radius)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #36
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "amplitude=" + str(self.amplitude)
     s += ", frequency=" + str(self.frequency)
     s += ", variance=" + str(self.variance)
     s += ", radius=" + str(self.radius)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #37
0
    def __init__(self, W, biasx, biash):
        GenericTests.check_type(W, 'W', numpy.ndarray, 2)
        GenericTests.check_type(biasx, 'biasx', numpy.ndarray, 1)
        GenericTests.check_type(biash, 'biash', numpy.ndarray, 1)
        if not biash.shape[0] == W.shape[0]:
            raise ValueError(
                "dimensions of W and biash must agree along # of hidden units")
        if not biasx.shape[0] == W.shape[1]:
            raise ValueError(
                "dimensions of W and biasx must agree along # of visible units"
            )

        Distribution.__init__(self, W.shape[1])

        self.W = W
        self.biasx = biasx
        self.biash = biash
        self.num_hidden_units = W.shape[0]
コード例 #38
0
ファイル: Discrete.py プロジェクト: mgong2/kameleon-mcmc
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "num_objects=" + str(self.num_objects)
     s += ", omega=" + str(self.omega)
     s += ", cdf=" + str(self.cdf)
     s += ", support=" + str(self.support)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #39
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "full_target=" + str(self.full_target)
     s += ", current_state=" + str(self.current_state)
     s += ", schedule=" + str(self.schedule)
     s += ", index_block=" + str(self.index_block)
     s += ", current_idx=" + str(self.current_idx)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #40
0
 def __str__(self):
     s = self.__class__.__name__ + "=["
     s += "full_target=" + str(self.full_target)
     s += ", current_state=" + str(self.current_state)
     s += ", schedule=" + str(self.schedule)
     s += ", index_block=" + str(self.index_block)
     s += ", current_idx=" + str(self.current_idx)
     s += ", " + Distribution.__str__(self)
     s += "]"
     return s
コード例 #41
0
ファイル: Banana.py プロジェクト: karlnapf/kameleon-mcmc
 def get_proposal_points(self, n):
     """
     Returns n points which lie on a uniform grid on the "center" of the banana
     """
     if self.dimension == 2:
         (xmin, xmax), _ = self.get_plotting_bounds()
         x1 = linspace(xmin, xmax, n)
         x2 = self.bananicity * (x1 ** 2 - self.V)
         return array([x1, x2]).T
     else:
         return Distribution.get_proposal_points(self, n)
コード例 #42
0
ファイル: Banana.py プロジェクト: mgong2/kameleon-mcmc
 def get_proposal_points(self, n):
     """
     Returns n points which lie on a uniform grid on the "center" of the banana
     """
     if self.dimension == 2:
         (xmin, xmax), _ = self.get_plotting_bounds()
         x1 = linspace(xmin, xmax, n)
         x2 = self.bananicity * (x1**2 - self.V)
         return array([x1, x2]).T
     else:
         return Distribution.get_proposal_points(self, n)
コード例 #43
0
    def __init__(self, W, bias):
        GenericTests.check_type(W, 'W', numpy.ndarray, 2)
        GenericTests.check_type(bias, 'bias', numpy.ndarray, 1)

        if not W.shape[0] == W.shape[1]:
            raise ValueError("W must be square")

        if not bias.shape[0] == W.shape[0]:
            raise ValueError("dimensions of W and bias must agree")

        if not all(diag(W) == 0):
            raise ValueError("W must have zeros along the diagonal")

        if not allclose(W, W.T):
            raise ValueError("W must be symmetric")

        Distribution.__init__(self, W.shape[0])

        self.W = W
        self.bias = bias
コード例 #44
0
ファイル: Hopfield.py プロジェクト: karlnapf/kameleon-mcmc
 def __init__(self, W, bias):
     GenericTests.check_type(W, 'W', numpy.ndarray, 2)
     GenericTests.check_type(bias, 'bias', numpy.ndarray, 1)
     
     if not W.shape[0] == W.shape[1]:
         raise ValueError("W must be square")
     
     if not bias.shape[0] == W.shape[0]:
         raise ValueError("dimensions of W and bias must agree")
     
     if not all(diag(W) == 0):
         raise ValueError("W must have zeros along the diagonal")
     
     if not allclose(W, W.T):
         raise ValueError("W must be symmetric")
     
     Distribution.__init__(self, W.shape[0])
     
     self.W = W
     self.bias = bias
コード例 #45
0
 def __init__(self,
              dimension=2,
              num_components=2,
              components=None,
              mixing_proportion=None):
     Distribution.__init__(self, dimension)
     self.num_components = num_components
     if (components == None):
         self.components = [
             Gaussian(mu=zeros(self.dimension), Sigma=eye(self.dimension))
             for _ in range(self.num_components)
         ]
     else:
         assert (len(components) == self.num_components)
         self.components = components
     if (mixing_proportion == None):
         self.mixing_proportion = Discrete(
             (1.0 / num_components) * ones([num_components]))
     else:
         assert (num_components == mixing_proportion.num_objects)
         self.mixing_proportion = mixing_proportion
コード例 #46
0
ファイル: Flower.py プロジェクト: karlnapf/kameleon-mcmc
 def get_proposal_points(self, n):
     """
     Returns n points which lie on a uniform grid on the "center" of the flower
     """
     if self.dimension == 2:
         theta = linspace(0, 2 * pi, n)
         
         # sample radius
         radius_sample = zeros(n) + self.radius + \
             self.amplitude * cos(self.frequency * theta)
         
         # sample points
         X = array((cos(theta) * radius_sample, sin(theta) * radius_sample)).T
         
         return X
     else:
         return Distribution.get_proposal_points(self, n)
コード例 #47
0
    def get_proposal_points(self, n):
        """
        Returns n points which lie on a uniform grid on the "center" of the flower
        """
        if self.dimension == 2:
            theta = linspace(0, 2 * pi, n)

            # sample radius
            radius_sample = zeros(n) + self.radius + \
                self.amplitude * cos(self.frequency * theta)

            # sample points
            X = array(
                (cos(theta) * radius_sample, sin(theta) * radius_sample)).T

            return X
        else:
            return Distribution.get_proposal_points(self, n)
コード例 #48
0
ファイル: Banana.py プロジェクト: mgong2/kameleon-mcmc
    def __init__(self, dimension=2, bananicity=0.03, V=100.0):
        assert (dimension >= 2)
        Distribution.__init__(self, dimension)

        self.bananicity = bananicity
        self.V = V
コード例 #49
0
ファイル: Banana.py プロジェクト: karlnapf/kameleon-mcmc
 def __init__(self, dimension=2, bananicity=0.03, V=100.0):
     assert(dimension >= 2)
     Distribution.__init__(self, dimension)
     
     self.bananicity = bananicity
     self.V = V
コード例 #50
-1
ファイル: Gaussian.py プロジェクト: karlnapf/kameleon-mcmc
 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)