def update_dir_prior(prior, N, logphat, rho):
 dprior = np.copy(prior)
 gradf = (N * ((psi(np.sum(prior)) - psi(prior)) + logphat))
 c = (N * polygamma(1, np.sum(prior)))
 q = ((- N) * polygamma(1, prior))
 b = (np.sum((gradf / q)) / ((1 / c) + np.sum((1 / q))))
 dprior = ((- (gradf - b)) / q)
 if all((((rho * dprior) + prior) > 0)):
  prior += (rho * dprior)
 else:
  logger.warning('updated prior not positive')
 return prior

def update_dir_prior ( prior , N , logphat , rho ) : dprior = np . copy ( prior ) gradf = ( N * ( ( psi ( np . sum ( prior ) ) - psi ( prior ) ) + logphat ) ) c = ( N * polygamma ( 1 , np . sum ( prior ) ) ) q = ( ( - N ) * polygamma ( 1 , prior ) ) b = ( np . sum ( ( gradf / q ) ) / ( ( 1 / c ) + np . sum ( ( 1 / q ) ) ) ) dprior = ( ( - ( gradf - b ) ) / q ) if all ( ( ( ( rho * dprior ) + prior ) > 0 ) ) : prior += ( rho * dprior ) else : logger . warning ( 'updated prior not positive' ) return prior
updates a given prior using newtons method .