<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _log_posterior(theta, counts, alpha, beta, n):
 """Log of the posterior probability and gradient Parameters theta : ndarray, shape=(n_params,) The free parameters of the reversible rate matrix counts : ndarray, shape=(n, n) The count matrix (sufficient statistics for the likielihood) alpha : ndarray, shape=(n,) Dirichlet concentration parameters beta : ndarray, shape=(n_params-n,) Scale parameter for the exponential prior on the symmetric rate matrix. """

    # likelihood + grad
    logp1, grad = loglikelihood(theta, counts)
    # exponential prior on s_{ij}
    logp2 = lexponential(theta[:-n], beta, grad=grad[:-n])
    # dirichlet prior on \pi
    logp3 = ldirichlet_softmax(theta[-n:], alpha=alpha, grad=grad[-n:])
    logp = logp1 + logp2 + logp3
    return logp, grad