#NEWLINE# def gradients_XX( self , dL_dK , X , X2 = None ) : #NEWLINE# #INDENT# '\n        Given the derivative of the objective K(dL_dK), compute the second derivative of K wrt X and X2:\n\n        ..math:\n          \x0crac{\\partial^2 K}{\\partial X\\partial X2}\n\n        ..returns:\n            dL2_dXdX2: NxMxQ, for X [NxQ] and X2[MxQ] (X2 is X if, X2 is None)\n            Thus, we return the second derivative in X2.\n        ' #NEWLINE# invdist = self . _inv_dist ( X , X2 ) #NEWLINE# invdist2 = ( invdist ** 2 ) #NEWLINE# dL_dr = ( self . dK_dr_via_X ( X , X2 ) * dL_dK ) #NEWLINE# tmp1 = ( dL_dr * invdist ) #NEWLINE# dL_drdr = ( self . dK2_drdr_via_X ( X , X2 ) * dL_dK ) #NEWLINE# tmp2 = ( dL_drdr * invdist2 ) #NEWLINE# l2 = ( np . ones ( X . shape [ 1 ] ) * ( self . lengthscale ** 2 ) ) #NEWLINE# if ( X2 is None ) : #NEWLINE# #INDENT# X2 = X #NEWLINE# tmp1 -= ( np . eye ( X . shape [ 0 ] ) * self . variance ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tmp1 [ ( X == X2 . T ) ] -= self . variance #NEWLINE# #UNINDENT# grad = np . empty ( ( X . shape [ 0 ] , X2 . shape [ 0 ] , X . shape [ 1 ] ) , dtype = np . float64 ) #NEWLINE# for q in range ( self . input_dim ) : #NEWLINE# #INDENT# tmpdist2 = ( ( X [ : , [ q ] ] - X2 [ : , [ q ] ] . T ) ** 2 ) #NEWLINE# grad [ : , : , q ] = ( ( ( ( ( ( tmp1 * invdist2 ) - tmp2 ) * tmpdist2 ) / l2 [ q ] ) - tmp1 ) / l2 [ q ] ) #NEWLINE# #UNINDENT# return grad