예제 #1
0
def get_scaled_fixation_probabilities(gammas):
    """
    The scaling factor is the same for each allele.
    It is something like 2N.
    @param gammas: scaled selections near zero, positive is better
    @return: a matrix of fixation probabilities
    """
    k = len(gammas)
    F = np.zeros((k, k))
    for i, gi in enumerate(gammas):
        for j, gj in enumerate(gammas):
            if i == j:
                continue
            F[i, j] = bernoulli.bgf(gj - gi)
    return F
예제 #2
0
def get_scaled_fixation_probabilities(gammas):
    """
    The scaling factor is the same for each allele.
    It is something like 2N.
    @param gammas: scaled selections near zero, positive is better
    @return: a matrix of fixation probabilities
    """
    k = len(gammas)
    F = np.zeros((k, k))
    for i, gi in enumerate(gammas):
        for j, gj in enumerate(gammas):
            if i == j:
                continue
            F[i, j] = bernoulli.bgf(gj - gi)
    return F
예제 #3
0
파일: mrate.py 프로젝트: BIGtigr/xgcode
def to_gtr_hb_known_energies(M, u, v):
    """
    The hb in the function name stands for Halpern-Bruno.
    @param M: a time-reversible rate matrix
    @param u: energies of states of M
    @param v: target energies
    @return: a time-reversible rate matrix
    """
    n = len(v)
    R = M.copy()
    # adjust the entries of the rate matrix
    for a in range(n):
        for b in range(n):
            if a != b:
                du = u[b] - u[a]
                dv = v[b] - v[a]
                log_tau = du - dv
                coeff = bernoulli.bgf(-log_tau)
                R[a, b] *= coeff
    # reset the diagonal entries of the rate matrix
    R -= np.diag(np.sum(R, axis=1))
    return R
예제 #4
0
파일: mrate.py 프로젝트: argriffing/xgcode
def to_gtr_hb_known_energies(M, u, v):
    """
    The hb in the function name stands for Halpern-Bruno.
    @param M: a time-reversible rate matrix
    @param u: energies of states of M
    @param v: target energies
    @return: a time-reversible rate matrix
    """
    n = len(v)
    R = M.copy()
    # adjust the entries of the rate matrix
    for a in range(n):
        for b in range(n):
            if a != b:
                du = u[b] - u[a]
                dv = v[b] - v[a]
                log_tau = du - dv
                coeff = bernoulli.bgf(-log_tau)
                R[a, b] *= coeff
    # reset the diagonal entries of the rate matrix
    R -= np.diag(np.sum(R, axis=1))
    return R