# 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)
        g = numpy.random.dirichlet([3] * N_NT)
        omega = 0.7
        kappa = 2.5
        beta = 1.2
        self.expcm = (phydmslib.models
                      .ExpCM_empirical_phi(self.prefs, g=g, omega=omega,
                                           kappa=kappa, beta=beta))
        self.assertTrue(numpy.allclose(g, self.expcm.g))

        # now check ExpCM attributes / derivates, updating several times
        for _update in range(2):
            self.params = {'omega': random.uniform(0.1, 2),
                           'kappa': random.uniform(0.5, 10),
                           'beta': random.uniform(0.5, 5),
                           'mu': random.uniform(0.05, 5.0),
                           }
            self.expcm.updateParams(self.params)
            self.assertTrue(numpy.allclose(g, self.expcm.g))
            self.check_empirical_phi()
            self.check_dQxy_dbeta()
            self.check_dprx_dbeta()
            self.check_ExpCM_attributes()
            self.check_ExpCM_derivatives()
            self.check_ExpCM_matrix_exponentials()

    def check_empirical_phi(self):
        """Check that `phi` gives right `g`, and has right derivative."""
        nt_freqs = [0] * N_NT
        for r in range(self.nsites):
            for x in range(N_CODON):

# 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)

        g = numpy.random.dirichlet([3] * N_NT)
        omega = 0.7
        kappa = 2.5
        beta = 1.2
        self.expcm = (phydmslib.models
                      .ExpCM_empirical_phi(self.prefs, g=g, omega=omega,
                                           kappa=kappa, beta=beta))
        self.assertTrue(numpy.allclose(g, self.expcm.g))

        # now check ExpCM attributes / derivates, updating several times
        for _update in range(2):
            self.params = {'omega': random.uniform(0.1, 2),
                           'kappa': random.uniform(0.5, 10),
                           'beta': random.uniform(0.5, 5),
                           'mu': random.uniform(0.05, 5.0),
                           }
            self.expcm.updateParams(self.params)
            self.assertTrue(numpy.allclose(g, self.expcm.g))
            self.check_empirical_phi()
            self.check_dQxy_dbeta()
            self.check_dprx_dbeta()
            self.check_ExpCM_attributes()
            self.check_ExpCM_derivatives()
            self.check_ExpCM_matrix_exponentials()

    def check_empirical_phi(self):
        """Check that `phi` gives right `g`, and has right derivative."""
        nt_freqs = [0] * N_NT
        for r in range(self.nsites):
            for x in range(N_CODON):

                for w in range(N_NT):