#NEWLINE# def _calculate_log_likelihood( self ) : #NEWLINE# #INDENT# '\n        Calculates the log-likelihood (up to a constant) for a given\n        self.theta.\n\n        ' #NEWLINE# R = zeros ( ( self . n , self . n ) ) #NEWLINE# ( X , Y ) = ( self . X , self . Y ) #NEWLINE# thetas = power ( 10.0 , self . thetas ) #NEWLINE# for i in range ( self . n ) : #NEWLINE# #INDENT# R [ i , ( i + 1 ) : self . n ] = exp ( ( - thetas . dot ( square ( ( X [ ( i , ... ) ] - X [ ( i + 1 ) : self . n , ... ] ) ) . T ) ) ) #NEWLINE# #UNINDENT# R *= ( 1.0 - self . nugget ) #NEWLINE# R += ( R . T + eye ( self . n ) ) #NEWLINE# self . R = R #NEWLINE# one = ones ( self . n ) #NEWLINE# rhs = column_stack ( [ Y , one ] ) #NEWLINE# try : #NEWLINE# #INDENT# self . R_fact = cho_factor ( R ) #NEWLINE# sol = cho_solve ( self . R_fact , rhs ) #NEWLINE# solve = ( lambda x : cho_solve ( self . R_fact , x ) ) #NEWLINE# det_factor = log ( ( abs ( ( prod ( diagonal ( self . R_fact [ 0 ] ) ) ** 2 ) ) + 1e-16 ) ) #NEWLINE# #UNINDENT# except ( linalg . LinAlgError , ValueError ) : #NEWLINE# #INDENT# self . R_fact = None #NEWLINE# sol = lstsq ( self . R , rhs ) [ 0 ] #NEWLINE# solve = ( lambda x : lstsq ( self . R , x ) [ 0 ] ) #NEWLINE# det_factor = slogdet ( self . R ) [ 1 ] #NEWLINE# #UNINDENT# self . mu = ( dot ( one , sol [ : , : ( - 1 ) ] ) / dot ( one , sol [ : , ( - 1 ) ] ) ) #NEWLINE# y_minus_mu = ( Y - self . mu ) #NEWLINE# self . R_solve_ymu = solve ( y_minus_mu ) #NEWLINE# self . R_solve_one = sol [ : , ( - 1 ) ] #NEWLINE# self . sig2 = ( dot ( y_minus_mu . T , self . R_solve_ymu ) / self . n ) #NEWLINE# if isinstance ( self . sig2 , ndarray ) : #NEWLINE# #INDENT# self . log_likelihood = ( ( ( ( - self . n ) / 2.0 ) * slogdet ( self . sig2 ) [ 1 ] ) - ( ( 1.0 / 2.0 ) * det_factor ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . log_likelihood = ( ( ( ( - self . n ) / 2.0 ) * log ( self . sig2 ) ) - ( ( 1.0 / 2.0 ) * det_factor ) )