def _calculate_correctedF3X4(self):
def F(phi):<EOL><INDENT>phi_reshape = phi.reshape((<NUM_LIT:3>, N_NT))<EOL>functionList = []<EOL>stop_frequency = []<EOL>for x in range(N_STOP):<EOL><INDENT>codonFrequency = STOP_CODON_TO_NT_INDICES[x] * phi_reshape<EOL>codonFrequency = scipy.prod(codonFrequency.sum(axis=<NUM_LIT:1>))<EOL>stop_frequency.append(codonFrequency)<EOL><DEDENT>C = scipy.sum(stop_frequency)<EOL>for p in range(<NUM_LIT:3>):<EOL><INDENT>for w in range(N_NT):<EOL><INDENT>s = <NUM_LIT:0><EOL>for x in range(N_STOP):<EOL><INDENT>if STOP_CODON_TO_NT_INDICES[x][p][w] == <NUM_LIT:1>:<EOL><INDENT>s += stop_frequency[x]<EOL><DEDENT><DEDENT>functionList.append((phi_reshape[p][w] - s)/(<NUM_LIT:1> - C)<EOL>- self.e_pw[p][w])<EOL><DEDENT><DEDENT>return functionList<EOL><DEDENT>phi = self.e_pw.copy().flatten()<EOL>with scipy.errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = scipy.optimize.root(F, phi,<EOL>tol=<NUM_LIT>)<EOL>assert result.success, "<STR_LIT>".format(result)<EOL>return result.x.reshape((<NUM_LIT:3>, N_NT))<EOL><DEDENT>
Calculate `phi` based on the empirical `e_pw` values