示例#1
0
def get_response_content(fs):
    out = StringIO()
    np.set_printoptions(linewidth=200)
    # get the user defined variables
    n = fs.nstates
    # sample a random reversible CTMC rate matrix
    v = divtime.sample_distribution(n)
    S = divtime.sample_symmetric_rate_matrix(n)
    R = mrate.to_gtr_halpern_bruno(S, v)
    distn = mrate.R_to_distn(R)
    spectrum = scipy.linalg.eigvalsh(mrate.symmetrized(R))
    print >> out, "random reversible CTMC rate matrix:"
    print >> out, R
    print >> out
    print >> out, "stationary distribution:"
    print >> out, distn
    print >> out
    print >> out, "spectrum:"
    print >> out, spectrum
    print >> out
    Q = aggregate(R)
    distn = mrate.R_to_distn(Q)
    spectrum = scipy.linalg.eigvalsh(mrate.symmetrized(Q))
    print >> out, "aggregated rate matrix:"
    print >> out, Q
    print >> out
    print >> out, "stationary distribution:"
    print >> out, distn
    print >> out
    print >> out, "spectrum:"
    print >> out, spectrum
    print >> out
    return out.getvalue()
示例#2
0
def get_response_content(fs):
    out = StringIO()
    np.set_printoptions(linewidth=200)
    # get the user defined variables
    n = fs.nstates
    t = fs.divtime
    #h = fs.delta
    # sample a random rate matrix
    v = divtime.sample_distribution(n)
    S = divtime.sample_symmetric_rate_matrix(n)
    R = mrate.to_gtr_halpern_bruno(S, v)
    # get some properties of the rate matrix
    distn = mrate.R_to_distn(R)
    spectrum = np.linalg.eigvalsh(mrate.symmetrized(R))
    #spectrum, U = np.linalg.eigh(mrate.symmetrized(R))
    #spectrum = np.linalg.eigvals(R)
    # report some information about the mutual information curve
    mi = ctmcmi.get_mutual_information(R, t)
    mi_diff = ctmcmi.get_mutual_information_diff(R, t)
    mi_diff_b = ctmcmi.get_mutual_information_diff_b(R, t)
    mi_diff_c = ctmcmi.get_mutual_information_diff_c(R, t)
    print >> out, 'arbitrary large-ish divergence time:'
    print >> out, t
    print >> out
    print >> out, 'randomly sampled reversible rate matrix:'
    print >> out, R
    print >> out
    print >> out, 'stationary distribution:'
    print >> out, distn
    print >> out
    print >> out, 'spectrum of the rate matrix:'
    print >> out, spectrum
    print >> out
    print >> out, 'mutual information at t = %f:' % t
    print >> out, mi
    print >> out
    print >> out, 'mutual information at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_approx(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_approx_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 3):' % t
    print >> out, ctmcmi.cute_MI_alternate(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 4):' % t
    print >> out, ctmcmi.get_mutual_information_approx_c(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_small_approx(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_b(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 3):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_c(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 4):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_d(R, t)
    print >> out
    print >> out, 'mutual information diff at t = %f:' % t
    print >> out, mi_diff
    print >> out
    print >> out, 'mutual information diff at t = %f (ver. 2):' % t
    print >> out, mi_diff_b
    print >> out
    print >> out, 'mutual information diff at t = %f (ver. 3):' % t
    print >> out, mi_diff_c
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx(R, t)
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f: (ver. 2)' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f: (ver. 4)' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_c(R, t)
    print >> out
    print >> out, 'log of mutual information at t = %f:' % t
    print >> out, math.log(mi)
    print >> out
    #print >> out, 'estimated derivative',
    #print >> out, 'of log of mutual information at t = %f:' % t
    #print >> out, (math.log(mi_c) - math.log(mi_a)) / (2*h)
    #print >> out
    print >> out, 'estimated derivative of log of MI',
    print >> out, 'at t = %f:' % t
    print >> out, mi_diff / mi
    print >> out
    print >> out, 'large t approximation of derivative of log of MI',
    print >> out, 'at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx(
        R, t) / ctmcmi.get_mutual_information_approx(R, t)
    print >> out
    print >> out, 'large t approximation of derivative of log of MI',
    print >> out, 'at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_b(
        R, t) / ctmcmi.get_mutual_information_approx_b(R, t)
    print >> out
    print >> out, 'twice the relevant eigenvalue:'
    print >> out, 2 * spectrum[-2]
    print >> out
    print >> out
    #print >> out, 'estimated derivative',
    #print >> out, 'of mutual information at t = %f:' % t
    #print >> out, (mi_c - mi_a) / (2*h)
    #print >> out
    #print >> out, '(estimated derivative of mutual information) /',
    #print >> out, '(mutual information) at t = %f:' % t
    #print >> out, (mi_c - mi_a) / (2*h*mi_b)
    #print >> out
    return out.getvalue()
示例#3
0
def get_response_content(fs):
    out = StringIO()
    np.set_printoptions(linewidth=200)
    # get the user defined variables
    n = fs.nstates
    # sample a random rate matrix
    v = divtime.sample_distribution(n)
    S = divtime.sample_symmetric_rate_matrix(n)
    R = mrate.to_gtr_halpern_bruno(S, v)
    # get some properties of the rate matrix and its re-symmetrization
    S = mrate.symmetrized(R)
    distn = mrate.R_to_distn(R)
    w, U = np.linalg.eigh(S)
    D = np.diag(U.T[-1])**2
    D_inv = np.diag(np.reciprocal(U.T[-1]))**2
    for t in (1.0, 2.0):
        P = scipy.linalg.expm(R*t)
        M = ndot(D**.5, scipy.linalg.expm(S*t), D**.5)
        M_star = ndot(D_inv**.5, scipy.linalg.expm(S*t), D_inv**.5)
        M_star_log = np.log(M_star)
        M_star_log_w, M_star_log_U = np.linalg.eigh(M_star_log)
        E = M * np.log(M_star)
        E_w, E_U = np.linalg.eigh(E)
        print >> out, 't:'
        print >> out, t
        print >> out
        print >> out, 'randomly sampled rate matrix R'
        print >> out, R
        print >> out
        print >> out, 'symmetrized matrix S'
        print >> out, S
        print >> out
        print >> out, 'stationary distribution diagonal D'
        print >> out, D
        print >> out
        print >> out, 'R = D^-1/2 S D^1/2'
        print >> out, ndot(D_inv**.5, S, D**.5)
        print >> out
        print >> out, 'probability matrix e^(R*t) = P'
        print >> out, P
        print >> out
        print >> out, 'P = D^-1/2 e^(S*t) D^1/2'
        print >> out, ndot(D_inv**.5, scipy.linalg.expm(S*t), D**.5)
        print >> out
        print >> out, 'pairwise distribution matrix M'
        print >> out, 'M = D^1/2 e^(S*t) D^1/2'
        print >> out, M
        print >> out
        print >> out, 'sum of entries of M'
        print >> out, np.sum(M)
        print >> out
        print >> out, 'M_star = D^-1/2 e^(S*t) D^-1/2'
        print >> out, M_star
        print >> out
        print >> out, 'entrywise logarithm logij(M_star)'
        print >> out, np.log(M_star)
        print >> out
        print >> out, 'Hadamard product M o logij(M_star) = E'
        print >> out, E
        print >> out
        print >> out, 'spectrum of M:'
        print >> out, np.linalg.eigvalsh(M)
        print >> out
        print >> out, 'spectrum of logij(M_star):'
        print >> out, M_star_log_w
        print >> out
        print >> out, 'corresponding eigenvectors of logij(M_star) as columns:'
        print >> out, M_star_log_U
        print >> out
        print >> out, 'spectrum of E:'
        print >> out, E_w
        print >> out
        print >> out, 'corresponding eigenvectors of E as columns:'
        print >> out, E_U
        print >> out
        print >> out, 'entrywise square roots of stationary distribution:'
        print >> out, np.sqrt(v)
        print >> out
        print >> out, 'sum of entries of E:'
        print >> out, np.sum(E)
        print >> out
        print >> out, 'mutual information:'
        print >> out, ctmcmi.get_mutual_information(R, t)
        print >> out
        print >> out
    return out.getvalue()
示例#4
0
def get_response_content(fs):
    out = StringIO()
    np.set_printoptions(linewidth=200)
    # get the user defined variables
    n = fs.nstates
    # sample a random rate matrix
    v = divtime.sample_distribution(n)
    S = divtime.sample_symmetric_rate_matrix(n)
    R = mrate.to_gtr_halpern_bruno(S, v)
    # get some properties of the rate matrix and its re-symmetrization
    S = mrate.symmetrized(R)
    distn = mrate.R_to_distn(R)
    w, U = np.linalg.eigh(S)
    D = np.diag(U.T[-1])**2
    D_inv = np.diag(np.reciprocal(U.T[-1]))**2
    for t in (1.0, 2.0):
        P = scipy.linalg.expm(R * t)
        M = ndot(D**.5, scipy.linalg.expm(S * t), D**.5)
        M_star = ndot(D_inv**.5, scipy.linalg.expm(S * t), D_inv**.5)
        M_star_log = np.log(M_star)
        M_star_log_w, M_star_log_U = np.linalg.eigh(M_star_log)
        E = M * np.log(M_star)
        E_w, E_U = np.linalg.eigh(E)
        print >> out, 't:'
        print >> out, t
        print >> out
        print >> out, 'randomly sampled rate matrix R'
        print >> out, R
        print >> out
        print >> out, 'symmetrized matrix S'
        print >> out, S
        print >> out
        print >> out, 'stationary distribution diagonal D'
        print >> out, D
        print >> out
        print >> out, 'R = D^-1/2 S D^1/2'
        print >> out, ndot(D_inv**.5, S, D**.5)
        print >> out
        print >> out, 'probability matrix e^(R*t) = P'
        print >> out, P
        print >> out
        print >> out, 'P = D^-1/2 e^(S*t) D^1/2'
        print >> out, ndot(D_inv**.5, scipy.linalg.expm(S * t), D**.5)
        print >> out
        print >> out, 'pairwise distribution matrix M'
        print >> out, 'M = D^1/2 e^(S*t) D^1/2'
        print >> out, M
        print >> out
        print >> out, 'sum of entries of M'
        print >> out, np.sum(M)
        print >> out
        print >> out, 'M_star = D^-1/2 e^(S*t) D^-1/2'
        print >> out, M_star
        print >> out
        print >> out, 'entrywise logarithm logij(M_star)'
        print >> out, np.log(M_star)
        print >> out
        print >> out, 'Hadamard product M o logij(M_star) = E'
        print >> out, E
        print >> out
        print >> out, 'spectrum of M:'
        print >> out, np.linalg.eigvalsh(M)
        print >> out
        print >> out, 'spectrum of logij(M_star):'
        print >> out, M_star_log_w
        print >> out
        print >> out, 'corresponding eigenvectors of logij(M_star) as columns:'
        print >> out, M_star_log_U
        print >> out
        print >> out, 'spectrum of E:'
        print >> out, E_w
        print >> out
        print >> out, 'corresponding eigenvectors of E as columns:'
        print >> out, E_U
        print >> out
        print >> out, 'entrywise square roots of stationary distribution:'
        print >> out, np.sqrt(v)
        print >> out
        print >> out, 'sum of entries of E:'
        print >> out, np.sum(E)
        print >> out
        print >> out, 'mutual information:'
        print >> out, ctmcmi.get_mutual_information(R, t)
        print >> out
        print >> out
    return out.getvalue()
示例#5
0
def get_response_content(fs):
    out = StringIO()
    np.set_printoptions(linewidth=200)
    # get the user defined variables
    n = fs.nstates
    t = fs.divtime
    #h = fs.delta
    # sample a random rate matrix
    v = divtime.sample_distribution(n)
    S = divtime.sample_symmetric_rate_matrix(n)
    R = mrate.to_gtr_halpern_bruno(S, v)
    # get some properties of the rate matrix
    distn = mrate.R_to_distn(R)
    spectrum = np.linalg.eigvalsh(mrate.symmetrized(R))
    #spectrum, U = np.linalg.eigh(mrate.symmetrized(R))
    #spectrum = np.linalg.eigvals(R)
    # report some information about the mutual information curve
    mi = ctmcmi.get_mutual_information(R, t)
    mi_diff = ctmcmi.get_mutual_information_diff(R, t)
    mi_diff_b = ctmcmi.get_mutual_information_diff_b(R, t)
    mi_diff_c = ctmcmi.get_mutual_information_diff_c(R, t)
    print >> out, 'arbitrary large-ish divergence time:'
    print >> out, t
    print >> out
    print >> out, 'randomly sampled reversible rate matrix:'
    print >> out, R
    print >> out
    print >> out, 'stationary distribution:'
    print >> out, distn
    print >> out
    print >> out, 'spectrum of the rate matrix:'
    print >> out, spectrum
    print >> out
    print >> out, 'mutual information at t = %f:' % t
    print >> out, mi
    print >> out
    print >> out, 'mutual information at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_approx(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_approx_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 3):' % t
    print >> out, ctmcmi.cute_MI_alternate(R, t)
    print >> out
    print >> out, 'large t approximation of MI at t = %f (ver. 4):' % t
    print >> out, ctmcmi.get_mutual_information_approx_c(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_small_approx(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_b(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 3):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_c(R, t)
    print >> out
    print >> out, 'small t approximation of MI at t = %f (ver. 4):' % t
    print >> out, ctmcmi.get_mutual_information_small_approx_d(R, t)
    print >> out
    print >> out, 'mutual information diff at t = %f:' % t
    print >> out, mi_diff
    print >> out
    print >> out, 'mutual information diff at t = %f (ver. 2):' % t
    print >> out, mi_diff_b
    print >> out
    print >> out, 'mutual information diff at t = %f (ver. 3):' % t
    print >> out, mi_diff_c
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx(R, t)
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f: (ver. 2)' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_b(R, t)
    print >> out
    print >> out, 'large t approximation of MI diff at t = %f: (ver. 4)' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_c(R, t)
    print >> out
    print >> out, 'log of mutual information at t = %f:' % t
    print >> out, math.log(mi)
    print >> out
    #print >> out, 'estimated derivative',
    #print >> out, 'of log of mutual information at t = %f:' % t
    #print >> out, (math.log(mi_c) - math.log(mi_a)) / (2*h)
    #print >> out
    print >> out, 'estimated derivative of log of MI',
    print >> out, 'at t = %f:' % t
    print >> out, mi_diff / mi
    print >> out
    print >> out, 'large t approximation of derivative of log of MI',
    print >> out, 'at t = %f:' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx(R,
            t) / ctmcmi.get_mutual_information_approx(R, t)
    print >> out
    print >> out, 'large t approximation of derivative of log of MI',
    print >> out, 'at t = %f (ver. 2):' % t
    print >> out, ctmcmi.get_mutual_information_diff_approx_b(R,
            t) / ctmcmi.get_mutual_information_approx_b(R, t)
    print >> out
    print >> out, 'twice the relevant eigenvalue:'
    print >> out, 2 * spectrum[-2]
    print >> out
    print >> out
    #print >> out, 'estimated derivative',
    #print >> out, 'of mutual information at t = %f:' % t
    #print >> out, (mi_c - mi_a) / (2*h)
    #print >> out
    #print >> out, '(estimated derivative of mutual information) /',
    #print >> out, '(mutual information) at t = %f:' % t
    #print >> out, (mi_c - mi_a) / (2*h*mi_b)
    #print >> out
    return out.getvalue()