#NEWLINE# def _calculate_log_likelihood( self ) : #NEWLINE# #INDENT# R = zeros ( ( self . n , self . n ) ) #NEWLINE# ( X , Y ) = ( array ( self . X ) , array ( self . Y ) ) #NEWLINE# thetas = ( 10.0 ** self . thetas ) #NEWLINE# for i in range ( self . n ) : #NEWLINE# #INDENT# R [ i , ( i + 1 ) : self . n ] = ( e ** ( - sum ( ( thetas * ( ( X [ i ] - X [ ( i + 1 ) : self . n ] ) ** 2.0 ) ) , 1 ) ) ) #NEWLINE# #UNINDENT# R = ( R * ( 1.0 - self . nugget ) ) #NEWLINE# R = ( ( R + R . T ) + eye ( self . n ) ) #NEWLINE# self . R = R #NEWLINE# one = ones ( self . n ) #NEWLINE# try : #NEWLINE# #INDENT# self . R_fact = cho_factor ( R ) #NEWLINE# rhs = vstack ( [ Y , one ] ) . T #NEWLINE# R_fact = ( self . R_fact [ 0 ] . T , ( not self . R_fact [ 1 ] ) ) #NEWLINE# cho = cho_solve ( R_fact , rhs ) . T #NEWLINE# self . mu = ( dot ( one , cho [ 0 ] ) / dot ( one , cho [ 1 ] ) ) #NEWLINE# ymdotone = ( Y - dot ( one , self . mu ) ) #NEWLINE# self . sig2 = ( dot ( ymdotone , cho_solve ( self . R_fact , ymdotone ) ) / self . n ) #NEWLINE# self . log_likelihood = ( ( ( ( - self . n ) / 2.0 ) * log ( self . sig2 ) ) - ( ( 1.0 / 2.0 ) * log ( abs ( ( det ( self . R ) + 1e-16 ) ) ) ) ) #NEWLINE# #UNINDENT# except ( linalg . LinAlgError , ValueError ) : #NEWLINE# #INDENT# self . R_fact = None #NEWLINE# rhs = vstack ( [ Y , one ] ) . T #NEWLINE# lsq = lstsq ( self . R . T , rhs ) [ 0 ] . T #NEWLINE# self . mu = ( dot ( one , lsq [ 0 ] ) / dot ( one , lsq [ 1 ] ) ) #NEWLINE# ymdotone = ( Y - dot ( one , self . mu ) ) #NEWLINE# self . sig2 = ( dot ( ymdotone , lstsq ( self . R , ymdotone ) [ 0 ] ) / self . n ) #NEWLINE# self . log_likelihood = ( ( ( ( - self . n ) / 2.0 ) * log ( self . sig2 ) ) - ( ( 1.0 / 2.0 ) * log ( abs ( ( det ( self . R ) + 1e-16 ) ) ) ) )