Esempio n. 1
0
def get_fixation_unconstrained_kb_fquad(
        S, d, log_kb, x, w, codon_neighbor_mask):
    """
    This uses the Kacser and Burns effect instead of the sign function.
    """
    #TODO: possibly use a mirror symmetry to double the speed
    soft_sign_S = algopy.tanh(algopy.exp(log_kb)*S)
    D = d * soft_sign_S
    H = algopy.zeros_like(S)
    for i in range(H.shape[0]):
        for j in range(H.shape[1]):
            if codon_neighbor_mask[i, j]:
                H[i, j] = 1. / kimrecessive.denom_fixed_quad(
                        0.5*S[i, j], D[i, j], x, w)
    return H
Esempio n. 2
0
def get_fixation_unconstrained_kb_fquad(
        S, d, log_kb, x, w, codon_neighbor_mask):
    """
    This uses the Kacser and Burns effect instead of the sign function.
    """
    #TODO: possibly use a mirror symmetry to double the speed
    soft_sign_S = algopy.tanh(algopy.exp(log_kb)*S)
    D = d * soft_sign_S
    H = algopy.zeros_like(S)
    for i in range(H.shape[0]):
        for j in range(H.shape[1]):
            if codon_neighbor_mask[i, j]:
                H[i, j] = 1. / kimrecessive.denom_fixed_quad(
                        0.5*S[i, j], D[i, j], x, w)
    return H
Esempio n. 3
0
def get_fixation_unconstrained_fquad(S, d, x, w, codon_neighbor_mask):
    """
    In this function name, fquad means "fixed quadrature."
    The S ndarray with ndim=2 depends on free parameters.
    The d parameter is itself a free parameter.
    So both of those things are algopy objects carrying Taylor information.
    On the other hand, x and w are precomputed ndim=1 ndarrays
    which are not carrying around extra Taylor information.
    @param S: array of selection differences
    @param d: parameter that controls dominance vs. recessivity
    @param x: precomputed roots for quadrature
    @param w: precomputed weights for quadrature
    @param codon_neighbor_mask: only compute entries neighboring pairs
    """
    #TODO: possibly use a mirror symmetry to double the speed
    sign_S = algopy.sign(S)
    D = d * sign_S
    H = algopy.zeros_like(S)
    for i in range(H.shape[0]):
        for j in range(H.shape[1]):
            if codon_neighbor_mask[i, j]:
                H[i, j] = 1. / kimrecessive.denom_fixed_quad(
                        0.5*S[i, j], D[i, j], x, w)
    return H
Esempio n. 4
0
def get_fixation_unconstrained_fquad(S, d, x, w, codon_neighbor_mask):
    """
    In this function name, fquad means "fixed quadrature."
    The S ndarray with ndim=2 depends on free parameters.
    The d parameter is itself a free parameter.
    So both of those things are algopy objects carrying Taylor information.
    On the other hand, x and w are precomputed ndim=1 ndarrays
    which are not carrying around extra Taylor information.
    @param S: array of selection differences
    @param d: parameter that controls dominance vs. recessivity
    @param x: precomputed roots for quadrature
    @param w: precomputed weights for quadrature
    @param codon_neighbor_mask: only compute entries of neighboring codon pairs
    """
    #TODO: possibly use a mirror symmetry to double the speed
    sign_S = algopy.sign(S)
    D = d * sign_S
    H = algopy.zeros_like(S)
    for i in range(H.shape[0]):
        for j in range(H.shape[1]):
            if codon_neighbor_mask[i, j]:
                H[i, j] = 1. / kimrecessive.denom_fixed_quad(
                        0.5*S[i, j], D[i, j], x, w)
    return H
Esempio n. 5
0
def do_integration_demo():
    N = 101
    #d = np.linspace(-5, 5, N) / 10000.
    #c = np.linspace(-100, 100, N) / 10.
    #d = np.linspace(-5, 5, N) / 3.
    #c = np.linspace(-100, 100, N) / 3.
    d = np.linspace(-5, 5, N)
    c = np.linspace(-100, 100, N)
    #d = np.linspace(-1, 1, N) * 0.25
    #c = np.linspace(-1, 1, N) * 0.02
    #d = np.linspace(-3, 3, N) / 10.
    #c = np.linspace(-30, 30, N) / 10.
    #d = np.linspace(-3, 3, N) / 10000.
    #c = np.linspace(-30, 30, N) / 10000.
    #d = np.linspace(-3, 3, N)
    #c = np.linspace(-30, 30, N)
    #d = np.linspace(-4, 4, N)
    #c = np.linspace(-40, 40, N)
    #c = np.linspace(-20, 20, N)
    #d = np.linspace(-.2, .2, N)
    #c = np.linspace(-100, 100, N)
    #c = np.linspace(-200, 200, N)
    #dc, dd = 0.001, 0.001
    #c = np.arange(1.-0.05, 1.+0.05, dc)
    #d = np.arange(1.-0.05, 1.+0.05, dd)
    ##dc, dd = 0.005, 0.005
    ##c = np.arange(0, 0.3, dc)
    ##d = np.arange(-0.2, 0.2, dd)


    """
    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_a(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()
    """

    """
    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_b(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()
    """

    """
    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_c(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()
    """

    """
    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_d(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()
    """

    """
    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_e1(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()

    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_e2(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()

    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_e3(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()

    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_e4(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()

    Z = np.zeros((len(d), len(c)))
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            Z[j, i] = get_relative_error_e6(ci, dj)
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()
    """

    Z = np.zeros((len(d), len(c)))
    W = np.zeros((len(d), len(c)))
    quad_x, quad_w = kimrecessive.precompute_quadrature(0, 1, 101)
    for j, dj in enumerate(d):
        for i, ci in enumerate(c):
            x = kimrecessive.denom_quad(ci, dj)
            #y = kimrecessive.denom_poly_b(ci, dj)
            #y = kimengine.denom_poly(ci, dj)
            #y = kimrecessive.denom_hyperu_b(ci, dj)
            #y = kimrecessive.denom_erfcx_b(ci, dj)
            y = kimrecessive.denom_fixed_quad(ci, dj, quad_x, quad_w)
            #y = kimrecessive.denom_combo_b(ci, dj)
            w = abs(y - x) / abs(x)
            W[j, i] = w
            Z[j, i] = refilter(w)
    print numpy.max(W)
    import matplotlib.pyplot as plt
    fig = plt.figure()
    im = plt.imshow(Z, cmap=plt.cm.jet)
    plt.show()