# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# N_NT = len(INDEX_TO_NT)
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import phydmslib.models
from phydmslib.constants import (N_CODON, N_NT, CODON_NT_COUNT,
                                 AA_TO_INDEX, N_AA)
        # phi sums to one
        self.assertTrue(numpy.allclose(1, self.expcm.phi.sum()))

    def check_ExpCM_derivatives(self):
        """Makes sure derivatives are as expected."""
        # check derivatives of Prxy calculated by dPrxy
        # implementation looks a bit complex because `check_grad` function
        # can only be used for single values at a time, so have to loop
        # over r, x, y and so hash values to make faster

        def funcPrxy(paramvalue, paramname, expcm, r, x, y):
            if len(paramvalue) == 1:
                expcm.updateParams({paramname: paramvalue[0]})
            else:
                expcm.updateParams({paramname: paramvalue})
            return expcm.Prxy[r][x][y]

        def funcdPrxy(paramvalue, paramname, expcm, r, x, y):
            if len(paramvalue) == 1:
                expcm.updateParams({paramname: paramvalue[0]})
            else:
                expcm.updateParams({paramname: paramvalue})
            return expcm.dPrxy[paramname][r][x][y]

        for (pname, pvalue) in sorted(self.params.items()):
            if pname == 'mu':
                continue
            if isinstance(pvalue, float):
                pvalue = [pvalue]
            for r in random.sample(range(self.nsites), 2):  # check a few sites

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# N_NT = len(INDEX_TO_NT)
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


# Path: tests/test_expcm_empirical_phi.py
import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import phydmslib.models
from phydmslib.constants import (N_CODON, N_NT, CODON_NT_COUNT,
                                 AA_TO_INDEX, N_AA)

        # phi sums to one
        self.assertTrue(numpy.allclose(1, self.expcm.phi.sum()))

    def check_ExpCM_derivatives(self):
        """Makes sure derivatives are as expected."""
        # check derivatives of Prxy calculated by dPrxy
        # implementation looks a bit complex because `check_grad` function
        # can only be used for single values at a time, so have to loop
        # over r, x, y and so hash values to make faster

        def funcPrxy(paramvalue, paramname, expcm, r, x, y):
            if len(paramvalue) == 1:
                expcm.updateParams({paramname: paramvalue[0]})
            else:
                expcm.updateParams({paramname: paramvalue})
            return expcm.Prxy[r][x][y]

        def funcdPrxy(paramvalue, paramname, expcm, r, x, y):
            if len(paramvalue) == 1:
                expcm.updateParams({paramname: paramvalue[0]})
            else:
                expcm.updateParams({paramname: paramvalue})
            return expcm.dPrxy[paramname][r][x][y]

        for (pname, pvalue) in sorted(self.params.items()):
            if pname == 'mu':
                continue
            if isinstance(pvalue, float):
                pvalue = [pvalue]
            for r in random.sample(range(self.nsites), 2):  # check a few sites

                for x in random.sample(range(N_CODON), 3):  # check a few codon