def _compute_empirical_phi(self, beta):
def F(phishort):<EOL><INDENT>"""<STR_LIT>"""<EOL>phifull = scipy.append(phishort, <NUM_LIT:1> - phishort.sum())<EOL>phiprod = scipy.ones(N_CODON, dtype='<STR_LIT:float>')<EOL>for w in range(N_NT):<EOL><INDENT>phiprod *= phifull[w]**CODON_NT_COUNT[w]<EOL><DEDENT>frx_phiprod = frx * phiprod<EOL>frx_phiprod_codonsum = frx_phiprod.sum(axis=<NUM_LIT:1>)<EOL>gexpect = []<EOL>for w in range(N_NT - <NUM_LIT:1>):<EOL><INDENT>gexpect.append(<EOL>((CODON_NT_COUNT[w] * frx_phiprod).sum(axis=<NUM_LIT:1>) /<EOL>frx_phiprod_codonsum).sum() / (<NUM_LIT:3> * self.nsites))<EOL><DEDENT>gexpect = scipy.array(gexpect, dtype='<STR_LIT:float>')<EOL>return self.g[ : -<NUM_LIT:1>] - gexpect<EOL><DEDENT>frx = self.pi_codon**beta<EOL>with scipy.errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = scipy.optimize.root(F, self.phi[ : -<NUM_LIT:1>].copy(),<EOL>tol=<NUM_LIT>)<EOL>assert result.success, "<STR_LIT>".format(result)<EOL>phishort = result.x<EOL><DEDENT>return scipy.append(phishort, <NUM_LIT:1> - phishort.sum())<EOL>
Returns empirical `phi` at the given value of `beta`.

        Does **not** set `phi` attribute, simply returns what
        should be value of `phi` given the current `g` and
        `pi_codon` attributes, plus the passed value of `beta`.
        Note that it uses the passed value of `beta`, **not**
        the current `beta` attribute.

        Initial guess is current value of `phi` attribute.