def check_YNGKP_M0_matrix_exponentials(self):
for r in range(<NUM_LIT:1>):<EOL><INDENT>fromdiag = scipy.dot(self.YNGKP_M0.A[<NUM_LIT:0>], scipy.dot(scipy.diag(<EOL>self.YNGKP_M0.D[r]), self.YNGKP_M0.Ainv[r]))<EOL>self.assertTrue(scipy.allclose(self.YNGKP_M0.Pxy[r], fromdiag,<EOL>atol=<NUM_LIT>), "<STR_LIT>".format((self.YNGKP_M0.Pxy[r] - fromdiag).max()))<EOL>for t in [<NUM_LIT>, <NUM_LIT>, <NUM_LIT:0.5>]:<EOL><INDENT>direct = scipy.linalg.expm(self.YNGKP_M0.Pxy[r] * self.YNGKP_M0.mu * t)<EOL>self.assertTrue(scipy.allclose(self.YNGKP_M0.M(t)[r], direct, atol=<NUM_LIT>),<EOL>"<STR_LIT>".format((self.YNGKP_M0.M(t)[r] - direct).max()))<EOL><DEDENT><DEDENT>def funcM(paramvalue, paramname, t, YNGKP_M0, r, x, y, storedvalues):<EOL><INDENT>"""<STR_LIT>"""<EOL>key = ('<STR_LIT:M>', tuple(paramvalue), paramname, t)<EOL>if key not in storedvalues:<EOL><INDENT>if len(paramvalue) == <NUM_LIT:1>:<EOL><INDENT>YNGKP_M0.updateParams({paramname:paramvalue[<NUM_LIT:0>]})<EOL><DEDENT>else:<EOL><INDENT>YNGKP_M0.updateParams({paramname:paramvalue})<EOL><DEDENT>storedvalues[key] = YNGKP_M0.M(t)<EOL><DEDENT>if len(storedvalues[key].shape) == <NUM_LIT:3>:<EOL><INDENT>return storedvalues[key][r][x][y]<EOL><DEDENT>else:<EOL><INDENT>return storedvalues[key][:,r,x,y]<EOL><DEDENT><DEDENT>def funcdM(paramvalue, paramname, t, YNGKP_M0, r, x, y, storedvalues):<EOL><INDENT>"""<STR_LIT>"""<EOL>key = ('<STR_LIT>', tuple(paramvalue), paramname, t)<EOL>if key not in storedvalues:<EOL><INDENT>if len(paramvalue) == <NUM_LIT:1>:<EOL><INDENT>YNGKP_M0.updateParams({paramname:paramvalue[<NUM_LIT:0>]})<EOL><DEDENT>else:<EOL><INDENT>YNGKP_M0.updateParams({paramname:paramvalue})<EOL><DEDENT>storedvalues[key] = YNGKP_M0.dM(t, paramname, YNGKP_M0.M(t))<EOL><DEDENT>if len(storedvalues[key].shape) == <NUM_LIT:3>:<EOL><INDENT>return storedvalues[key][r][x][y]<EOL><DEDENT>else:<EOL><INDENT>return storedvalues[key][:,r,x,y]<EOL><DEDENT><DEDENT>for (pname, pvalue) in sorted(self.params.items()):<EOL><INDENT>storedvalues = {} <EOL>if isinstance(pvalue, float):<EOL><INDENT>pvalue = [pvalue]<EOL><DEDENT>for t in [<NUM_LIT>, <NUM_LIT>, <NUM_LIT:0.5>]:<EOL><INDENT>for r in range(<NUM_LIT:1>):<EOL><INDENT>for x in range(N_CODON):<EOL><INDENT>for y in range(N_CODON):<EOL><INDENT>diff = scipy.optimize.check_grad(funcM, funcdM, pvalue,<EOL>pname, t, self.YNGKP_M0, r, x, y, storedvalues)<EOL>self.assertTrue(diff < <NUM_LIT>, ("<STR_LIT>" +<EOL>"<STR_LIT>"<EOL>).format(diff, pname, r, x, y))<EOL><DEDENT><DEDENT><DEDENT>self.YNGKP_M0.updateParams(self.params)<EOL><DEDENT><DEDENT>
Makes sure matrix exponentials of YNGKP_M0 are as expected.