bayesreg.py
def loglik(self, hyp, X, y):
        """ Function to compute compute log (marginal) likelihood """

        # hyperparameters (only beta needed)
        beta = np.exp(hyp[0])  # noise precision

        # load posterior and prior covariance
        if (hyp != self.hyp).all() or not(hasattr(self, 'A')):
            try:
                self.post(hyp, X, y)
            except ValueError:
                print("Warning: Estimation of posterior distribution failed")
                nlZ = 1/np.finfo(float).eps
                return nlZ

        try:
            # compute the log determinants in a numerically stable way
            logdetA = 2*sum(np.log(np.diag(np.linalg.cholesky(self.A))))
        except (ValueError, LinAlgError):
            print("Warning: Estimation of posterior distribution failed")
            nlZ = 1/np.finfo(float).eps
            return nlZ

        logdetSigma = sum(np.log(np.diag(self.Sigma)))  # Sigma is diagonal

        # compute negative marginal log likelihood
        nlZ = -0.5 * (self.N*np.log(beta) - self.N*np.log(2*np.pi) -
                      logdetSigma -
                      beta*(y-X.dot(self.m)).T.dot(y-X.dot(self.m)) -
                      self.m.T.dot(self.iSigma).dot(self.m) -
                      logdetA
                      )

        # make sure the output is finite to stop the minimizer getting upset
        if not np.isfinite(nlZ):
            nlZ = 1/np.finfo(float).eps

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

        self.nlZ = nlZ
        return nlZ
 Function to compute compute log (marginal) likelihood 
Function to compute compute log (marginal) likelihood
Function to compute compute log ( marginal ) likelihood
def loglik(self, hyp, X, y):
        beta = np.exp(hyp[0])  
        if (hyp != self.hyp).all() or not(hasattr(self, 'A')):
            try:
                self.post(hyp, X, y)
            except ValueError:
                print("Warning: Estimation of posterior distribution failed")
                nlZ = 1/np.finfo(float).eps
                return nlZ
        try:
            logdetA = 2*sum(np.log(np.diag(np.linalg.cholesky(self.A))))
        except (ValueError, LinAlgError):
            print("Warning: Estimation of posterior distribution failed")
            nlZ = 1/np.finfo(float).eps
            return nlZ
        logdetSigma = sum(np.log(np.diag(self.Sigma)))  
        nlZ = -0.5 * (self.N*np.log(beta) - self.N*np.log(2*np.pi) -
                      logdetSigma -
                      beta*(y-X.dot(self.m)).T.dot(y-X.dot(self.m)) -
                      self.m.T.dot(self.iSigma).dot(self.m) -
                      logdetA
                      )
        if not np.isfinite(nlZ):
            nlZ = 1/np.finfo(float).eps
        if self.verbose:
            print("nlZ= ", nlZ, " | hyp=", hyp)
        self.nlZ = nlZ
        return nlZ
def loglik ( self , hyp , X , y ) : beta = np . exp ( hyp [ 0 ] ) if ( hyp != self . hyp ) . all ( ) or not ( hasattr ( self , 'A' ) ) : try : self . post ( hyp , X , y ) except ValueError : print ( "Warning: Estimation of posterior distribution failed" ) nlZ = 1 / np . finfo ( float ) . eps return nlZ try : logdetA = 2 * sum ( np . log ( np . diag ( np . linalg . cholesky ( self . A ) ) ) ) except ( ValueError , LinAlgError ) : print ( "Warning: Estimation of posterior distribution failed" ) nlZ = 1 / np . finfo ( float ) . eps return nlZ logdetSigma = sum ( np . log ( np . diag ( self . Sigma ) ) ) nlZ = - 0.5 * ( self . N * np . log ( beta ) - self . N * np . log ( 2 * np . pi ) - logdetSigma - beta * ( y - X . dot ( self . m ) ) . T . dot ( y - X . dot ( self . m ) ) - self . m . T . dot ( self . iSigma ) . dot ( self . m ) - logdetA ) if not np . isfinite ( nlZ ) : nlZ = 1 / np . finfo ( float ) . eps if self . verbose : print ( "nlZ= " , nlZ , " | hyp=" , hyp ) self . nlZ = nlZ return nlZ
Function to compute compute log (marginal) likelihood
Function to compute compute log ( marginal ) likelihood
""" Function to compute compute log (marginal) likelihood """ # hyperparameters (only beta needed) # noise precision # load posterior and prior covariance # compute the log determinants in a numerically stable way # Sigma is diagonal # compute negative marginal log likelihood # make sure the output is finite to stop the minimizer getting upset
self
hyp
X
y