<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def thermodynamic_integration_log_evidence(betas, logls):
 """ Thermodynamic integration estimate of the evidence. :param betas: The inverse temperatures to use for the quadrature. :param logls: The mean log-likelihoods corresponding to ``betas`` to use for computing the thermodynamic evidence. :return ``(logZ, dlogZ)``: Returns an estimate of the log-evidence and the error associated with the finite number of temperatures at which the posterior has been sampled. The evidence is the integral of the un-normalized posterior over all of parameter space: .. math:: Z \\equiv \\int d\\theta \\, l(\\theta) p(\\theta) Thermodymanic integration is a technique for estimating the evidence integral using information from the chains at various temperatures. Let .. math:: Z(\\beta) = \\int d\\theta \\, l^\\beta(\\theta) p(\\theta) Then .. math:: \\frac{d \\log Z}{d \\beta} = \\frac{1}{Z(\\beta)} \\int d\\theta l^\\beta p \\log l = \\left \\langle \\log l \\right \\rangle_\\beta so .. math:: \\log Z(1) - \\log Z(0) = \\int_0^1 d\\beta \\left \\langle \\log l \\right\\rangle_\\beta By computing the average of the log-likelihood at the difference temperatures, the sampler can approximate the above integral. """

    if len(betas) != len(logls):
        raise ValueError('Need the same number of log(L) values as temperatures.')

    order = np.argsort(betas)[::-1]
    betas = betas[order]
    logls = logls[order]

    betas0 = np.copy(betas)
    if betas[-1] != 0:
        betas = np.concatenate((betas0, [0]))
        betas2 = np.concatenate((betas0[::2], [0]))

        # Duplicate mean log-likelihood of hottest chain as a best guess for beta = 0.
        logls2 = np.concatenate((logls[::2], [logls[-1]]))
        logls = np.concatenate((logls, [logls[-1]]))
    else:
        betas2 = np.concatenate((betas0[:-1:2], [0]))
        logls2 = np.concatenate((logls[:-1:2], [logls[-1]]))

    logZ = -np.trapz(logls, betas)
    logZ2 = -np.trapz(logls2, betas2)
    return logZ, np.abs(logZ - logZ2)