コード例 #1
0
def main():

    # use standard notation
    Nmu = 1.0
    N = 120
    mu = Nmu / float(N)

    print 'N*mu:', Nmu
    print 'N:', N
    print

    # multiply the rate matrix by this scaling factor
    m_factor = mu

    # use the moran drift
    distn_helper = moran_distn_helper

    # get properties of the collapsed diamond process
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = m_factor * wrightcore.create_mutation_collapsed(M, T)
    v = distn_helper(M, T, R_mut)

    for Ab_aB in range(N+1):
        nremaining = N - Ab_aB
        # compute the volume for normalization
        volume = 0.0
        for AB in range(nremaining+1):
            ab = nremaining - AB
            volume += v[T[AB, Ab_aB, ab]]
        # print some info
        print 'X_1 + X_4 =', Ab_aB, '/', N
        print 'probability =', volume
        print 'Y = X_2 / (1 - (X_1 + X_4)) = X_2 / (X_2 + X_3)'
        if not nremaining:
            print 'conditional distribution of Y is undefined'
        else:
            # compute the conditional moments
            m1 = 0.0
            m2 = 0.0
            for AB in range(nremaining+1):
                ab = nremaining - AB
                p = v[T[AB, Ab_aB, ab]] / volume
                x = AB / float(nremaining)
                m1 += x*p
                m2 += x*x*p
            # print some info
            print 'conditional E(Y) =', m1
            print 'conditional E(Y^2) =', m2
            print 'conditional V(Y) =', m2 - m1*m1
        print
コード例 #2
0
def main():

    # use standard notation
    Nmu = 1.0
    N = 120
    mu = Nmu / float(N)

    print 'N*mu:', Nmu
    print 'N:', N
    print

    # multiply the rate matrix by this scaling factor
    m_factor = mu

    # use the moran drift
    distn_helper = moran_distn_helper

    # get properties of the collapsed diamond process
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = m_factor * wrightcore.create_mutation_collapsed(M, T)
    v = distn_helper(M, T, R_mut)

    for Ab_aB in range(N + 1):
        nremaining = N - Ab_aB
        # compute the volume for normalization
        volume = 0.0
        for AB in range(nremaining + 1):
            ab = nremaining - AB
            volume += v[T[AB, Ab_aB, ab]]
        # print some info
        print 'X_1 + X_4 =', Ab_aB, '/', N
        print 'probability =', volume
        print 'Y = X_2 / (1 - (X_1 + X_4)) = X_2 / (X_2 + X_3)'
        if not nremaining:
            print 'conditional distribution of Y is undefined'
        else:
            # compute the conditional moments
            m1 = 0.0
            m2 = 0.0
            for AB in range(nremaining + 1):
                ab = nremaining - AB
                p = v[T[AB, Ab_aB, ab]] / volume
                x = AB / float(nremaining)
                m1 += x * p
                m2 += x * x * p
            # print some info
            print 'conditional E(Y) =', m1
            print 'conditional E(Y^2) =', m2
            print 'conditional V(Y) =', m2 - m1 * m1
        print
コード例 #3
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
コード例 #4
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
コード例 #5
0
ファイル: check-fold.py プロジェクト: argriffing/yolo-tyrion
def get_collapsed_diamond_process_distn(m_factor, N, distn_helper):
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = m_factor * wrightcore.create_mutation_collapsed(M, T)
    return distn_helper(M, T, R_mut)
コード例 #6
0
ファイル: check-fold.py プロジェクト: argriffing/yolo-tyrion
def get_collapsed_diamond_process_distn(m_factor, N, distn_helper):
    k = 3
    M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
    T = multinomstate.get_inverse_map(M)
    R_mut = m_factor * wrightcore.create_mutation_collapsed(M, T)
    return distn_helper(M, T, R_mut)