#NEWLINE# def objFunc_u( u , sumLogPi , nDoc , gamma , alpha0 ) : #NEWLINE# #INDENT# ' Returns scalar value of constrained objective function\n      Args\n      -------\n      u := 2K-vector of real numbers, subject to 0 < u\n\n      Returns\n      -------\n      f := -1 * L(u), where L is ELBO objective function (log posterior prob)\n  ' #NEWLINE# assert ( not np . any ( np . isnan ( u ) ) ) #NEWLINE# ( u1 , u0 ) = _unpack ( u ) #NEWLINE# E = _calcExpectations ( u1 , u0 ) #NEWLINE# K = u1 . size #NEWLINE# kvec = ( ( K + 1 ) - np . arange ( 1 , ( K + 1 ) ) ) #NEWLINE# Elog_pmq_v = ( ( np . sum ( ( ( gammaln ( u1 ) + gammaln ( u0 ) ) - gammaln ( ( u1 + u0 ) ) ) ) + np . inner ( ( 1.0 - u1 ) , E [ 'logv' ] ) ) + np . inner ( ( alpha0 - u0 ) , E [ 'log1-v' ] ) ) #NEWLINE# if ( nDoc > 0 ) : #NEWLINE# #INDENT# Elogp_pi_C = ( np . sum ( E [ 'logv' ] ) + np . inner ( kvec , sumLogPi [ 'log1-v' ] ) ) #NEWLINE# Elogp_pi = np . inner ( ( ( gamma * E [ 'beta' ] ) - 1 ) , ( sumLogPi / nDoc ) ) #NEWLINE# Elog_pmq_v = ( Elog_pmq_v / nDoc ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Elogp_pi_C = 0 #NEWLINE# Elogp_pi = 0 #NEWLINE# #UNINDENT# elbo = ( ( Elogp_pi_C + Elogp_pi ) + Elog_pmq_v ) #NEWLINE# return ( ( - 1.0 ) * elbo )