#NEWLINE# def update_gradients_KL( self , variational_posterior ) : #NEWLINE# #INDENT# mu = variational_posterior . mean #NEWLINE# S = variational_posterior . variance #NEWLINE# N = variational_posterior . num_data #NEWLINE# if self . group_spike : #NEWLINE# #INDENT# gamma = variational_posterior . binary_prob . values [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# gamma = variational_posterior . binary_prob . values #NEWLINE# #UNINDENT# if ( len ( self . pi . shape ) == 2 ) : #NEWLINE# #INDENT# idx = np . unique ( ( gamma . _raveled_index ( ) / gamma . shape [ ( - 1 ) ] ) ) #NEWLINE# pi = self . pi [ idx ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pi = self . pi #NEWLINE# #UNINDENT# if self . group_spike : #NEWLINE# #INDENT# tmp = ( self . _b_prob_all / ( 1.0 - gamma ) ) #NEWLINE# variational_posterior . binary_prob . gradient -= ( ( np . log ( ( ( ( ( 1 - pi ) / pi ) * gamma ) / ( 1.0 - self ) ) ) / N ) + ( ( tmp * ( ( ( ( ( np . square ( mu ) + S ) / self . variance ) - np . log ( S ) ) + np . log ( self . variance ) ) - 1.0 ) ) / 2.0 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# variational_posterior . binary_prob . gradient -= ( np . log ( ( ( ( ( 1 - pi ) / pi ) * gamma ) / ( 1.0 - gamma ) ) ) + ( ( ( ( ( ( np . square ( mu ) + S ) / self . variance ) - np . log ( S ) ) + np . log ( self . variance ) ) - 1.0 ) / 2.0 ) ) #NEWLINE# #UNINDENT# mu . gradient -= ( ( ( 1.0 - self . _b_prob_all ) * mu ) / ( self . variance * self . nModels ) ) #NEWLINE# S . gradient -= ( ( ( ( 1.0 / self . variance ) - ( 1.0 / S ) ) * ( 1.0 - self . _b_prob_all ) ) / ( 2.0 * self . nModels ) ) #NEWLINE# if self . learnPi : #NEWLINE# #INDENT# raise 'Not Supported!'