bayesreg.py
def post(self, hyp, X, y):
        """ Generic function to compute posterior distribution.
            This function will save the posterior mean and precision matrix as
            self.m and self.A and will also update internal parameters (e.g.
            N, D and the prior covariance (Sigma) and precision (iSigma).
        """

        N = X.shape[0]
        if len(X.shape) == 1:
            D = 1
        else:
            D = X.shape[1]

        if (hyp == self.hyp).all() and hasattr(self, 'N'):
            print("hyperparameters have not changed, exiting")
            return

        # hyperparameters
        beta = np.exp(hyp[0])    # noise precision
        alpha = np.exp(hyp[1:])  # precision for the coefficients

        if self.verbose:
            print("estimating posterior ... | hyp=", hyp)

        # prior variance
        if len(alpha) == 1 or len(alpha) == D:
            self.Sigma = np.diag(np.ones(D))/alpha
            self.iSigma = np.diag(np.ones(D))*alpha
        else:
            raise ValueError("hyperparameter vector has invalid length")

        # compute posterior precision and mean
        self.A = beta*X.T.dot(X) + self.iSigma
        self.m = beta*linalg.solve(self.A, X.T, check_finite=False).dot(y)

        # save stuff
        self.N = N
        self.D = D
        self.hyp = hyp
 Generic function to compute posterior distribution.
            This function will save the posterior mean and precision matrix as
            self.m and self.A and will also update internal parameters (e.g.
            N, D and the prior covariance (Sigma) and precision (iSigma).
        
Generic function to compute posterior distribution.
This function will save the posterior mean and precision matrix as
self.m and self.A and will also update internal parameters  and precision (iSigma).
Generic function to compute posterior distribution . This function will save the posterior mean and precision matrix as self . m and self . A and will also update internal parameters and precision ( iSigma ) .
def post(self, hyp, X, y):
        N = X.shape[0]
        if len(X.shape) == 1:
            D = 1
        else:
            D = X.shape[1]
        if (hyp == self.hyp).all() and hasattr(self, 'N'):
            print("hyperparameters have not changed, exiting")
            return
        beta = np.exp(hyp[0])    
        alpha = np.exp(hyp[1:])  
        if self.verbose:
            print("estimating posterior ... | hyp=", hyp)
        if len(alpha) == 1 or len(alpha) == D:
            self.Sigma = np.diag(np.ones(D))/alpha
            self.iSigma = np.diag(np.ones(D))*alpha
        else:
            raise ValueError("hyperparameter vector has invalid length")
        self.A = beta*X.T.dot(X) + self.iSigma
        self.m = beta*linalg.solve(self.A, X.T, check_finite=False).dot(y)
        self.N = N
        self.D = D
        self.hyp = hyp
def post ( self , hyp , X , y ) : N = X . shape [ 0 ] if len ( X . shape ) == 1 : D = 1 else : D = X . shape [ 1 ] if ( hyp == self . hyp ) . all ( ) and hasattr ( self , 'N' ) : print ( "hyperparameters have not changed, exiting" ) return beta = np . exp ( hyp [ 0 ] ) alpha = np . exp ( hyp [ 1 : ] ) if self . verbose : print ( "estimating posterior ... | hyp=" , hyp ) if len ( alpha ) == 1 or len ( alpha ) == D : self . Sigma = np . diag ( np . ones ( D ) ) / alpha self . iSigma = np . diag ( np . ones ( D ) ) * alpha else : raise ValueError ( "hyperparameter vector has invalid length" ) self . A = beta * X . T . dot ( X ) + self . iSigma self . m = beta * linalg . solve ( self . A , X . T , check_finite = False ) . dot ( y ) self . N = N self . D = D self . hyp = hyp
Generic function to compute posterior distribution.
Generic function to compute posterior distribution .
""" Generic function to compute posterior distribution.
            This function will save the posterior mean and precision matrix as
            self.m and self.A and will also update internal parameters (e.g.
            N, D and the prior covariance (Sigma) and precision (iSigma).
        """ # hyperparameters # noise precision # precision for the coefficients # prior variance # compute posterior precision and mean # save stuff
self
hyp
X
y