def main(args):
    alpha = args.alpha
    N = args.N
    k = 3
    print 'alpha:', alpha
    print 'N:', N
    print 'k:', k
    print
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = wrightcore.create_mutation_abc(M, T)
    R_drift = wrightcore.create_moran_drift_rate_k3(M, T)
    Q = alpha * R_mut + R_drift
    # pick out the correct eigenvector
    W, V = scipy.linalg.eig(Q.T)
    w, v = min(zip(np.abs(W), V.T))
    print 'rate matrix:'
    print Q
    print
    print 'transpose of rate matrix:'
    print Q.T
    print
    print 'eigendecomposition of transpose of rate matrix as integers:'
    print scipy.linalg.eig(Q.T)
    print
    print 'transpose of rate matrix in mathematica notation:'
    print MatrixUtil.m_to_mathematica_string(Q.T.astype(int))
    print
    print 'abs eigenvector corresponding to smallest abs eigenvalue:'
    print np.abs(v)
    print
def main(args):
    alpha = args.alpha
    N = args.N
    k = 3
    print 'alpha:', alpha
    print 'N:', N
    print 'k:', k
    print
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = wrightcore.create_mutation_abc(M, T)
    R_drift = wrightcore.create_moran_drift_rate_k3(M, T)
    Q = alpha * R_mut + R_drift
    # pick out the correct eigenvector
    W, V = scipy.linalg.eig(Q.T)
    w, v = min(zip(np.abs(W), V.T))
    print 'rate matrix:'
    print Q
    print
    print 'transpose of rate matrix:'
    print Q.T
    print
    print 'eigendecomposition of transpose of rate matrix as integers:'
    print scipy.linalg.eig(Q.T)
    print
    print 'transpose of rate matrix in mathematica notation:'
    print MatrixUtil.m_to_mathematica_string(Q.T.astype(int))
    print
    print 'abs eigenvector corresponding to smallest abs eigenvalue:'
    print np.abs(v)
    print
Exemplo n.º 3
0
def get_moran_drift(M, T):
    k = M.shape[1]
    if k == 2:
        return wrightcore.create_moran_drift_rate_k2(M, T)
    elif k == 3:
        return wrightcore.create_moran_drift_rate_k3(M, T)
    elif k == 4:
        return wrightcore.create_moran_drift_rate_k4(M, T)
    else:
        raise NotImplementedError
Exemplo n.º 4
0
def get_moran_drift(M, T):
    k = M.shape[1]
    if k == 2:
        return wrightcore.create_moran_drift_rate_k2(M, T)
    elif k == 3:
        return wrightcore.create_moran_drift_rate_k3(M, T)
    elif k == 4:
        return wrightcore.create_moran_drift_rate_k4(M, T)
    else:
        raise NotImplementedError
Exemplo n.º 5
0
def get_moran_drift(M, T):
    #FIXME: this is dumb,
    #FIXME: but I'm not sure how to use variable-dimension ndarrays in cython
    k = M.shape[1]
    if k == 2:
        return wrightcore.create_moran_drift_rate_k2(M, T)
    elif k == 3:
        return wrightcore.create_moran_drift_rate_k3(M, T)
    elif k == 4:
        return wrightcore.create_moran_drift_rate_k4(M, T)
    else:
        raise NotImplementedError
Exemplo n.º 6
0
def get_moran_drift(M, T):
    #FIXME: this is dumb,
    #FIXME: but I'm not sure how to use variable-dimension ndarrays in cython
    k = M.shape[1]
    if k == 2:
        return wrightcore.create_moran_drift_rate_k2(M, T)
    elif k == 3:
        return wrightcore.create_moran_drift_rate_k3(M, T)
    elif k == 4:
        return wrightcore.create_moran_drift_rate_k4(M, T)
    else:
        raise NotImplementedError
Exemplo n.º 7
0
def do_collapsed_simplex(scaled_mut, N):
    """
    @param N: population size
    """
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    # Create the joint site pair mutation rate matrix.
    # This is scaled so that there are about popsize mutations per generation.
    R_mut_raw = wrightcore.create_mutation_collapsed(M, T)
    R_mut = (scaled_mut / float(N)) * R_mut_raw
    # Create the joint site pair drift transition matrix.
    lmcs = wrightcore.get_lmcs(M)
    lps = wrightcore.create_selection_neutral(M)
    #log_drift = wrightcore.create_neutral_drift(lmcs, lps, M)
    # Define the drift and mutation transition matrices.
    #P_drift = np.exp(log_drift)
    #P_mut = scipy.linalg.expm(R)
    # Define the composite per-generation transition matrix.
    #P = np.dot(P_mut, P_drift)
    # Solve a system of equations to find the stationary distribution.
    #v = MatrixUtil.get_stationary_distribution(P)
    # Try a new thing.
    # The raw drift matrix is scaled so that there are about N*N
    # replacements per generation.
    generation_rate = 1.0
    R_drift_raw = wrightcore.create_moran_drift_rate_k3(M, T)
    R_drift = (generation_rate / float(N)) * R_drift_raw
    #FIXME: you should get the stationary distn directly from the rate matrix
    P = scipy.linalg.expm(R_mut + R_drift)
    v = MatrixUtil.get_stationary_distribution(P)
    """
    for state, value in zip(M, v):
        print state, value
    """
    # draw an equilateral triangle
    #drawtri(M, T, v)
    return M, T, v
Exemplo n.º 8
0
def do_collapsed_simplex(scaled_mut, N):
    """
    @param N: population size
    """
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    # Create the joint site pair mutation rate matrix.
    # This is scaled so that there are about popsize mutations per generation.
    R_mut_raw = wrightcore.create_mutation_collapsed(M, T)
    R_mut = (scaled_mut / float(N)) * R_mut_raw
    # Create the joint site pair drift transition matrix.
    lmcs = wrightcore.get_lmcs(M)
    lps = wrightcore.create_selection_neutral(M)
    #log_drift = wrightcore.create_neutral_drift(lmcs, lps, M)
    # Define the drift and mutation transition matrices.
    #P_drift = np.exp(log_drift)
    #P_mut = scipy.linalg.expm(R)
    # Define the composite per-generation transition matrix.
    #P = np.dot(P_mut, P_drift)
    # Solve a system of equations to find the stationary distribution.
    #v = MatrixUtil.get_stationary_distribution(P)
    # Try a new thing.
    # The raw drift matrix is scaled so that there are about N*N
    # replacements per generation.
    generation_rate = 1.0
    R_drift_raw = wrightcore.create_moran_drift_rate_k3(M, T)
    R_drift = (generation_rate / float(N)) * R_drift_raw
    #FIXME: you should get the stationary distn directly from the rate matrix
    P = scipy.linalg.expm(R_mut + R_drift)
    v = MatrixUtil.get_stationary_distribution(P)
    """
    for state, value in zip(M, v):
        print state, value
    """
    # draw an equilateral triangle
    #drawtri(M, T, v)
    return M, T, v