Exemplo n.º 1
0
def adjacent_open_time_pdf(mec,
                           tres,
                           u1,
                           u2,
                           tmin=0.00001,
                           tmax=1000,
                           points=512,
                           unit='ms'):
    """
    Calculate pdf's of ideal all open time and open time adjacent to specified shut
    time range.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    ipdf, ajpdf : ndarrays of floats, shape (num of points)
        Ideal all and adjacent open time distributions.
    """

    # Ideal pdf.
    eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    tmax = (1 / eigs.max()) * 100
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)

    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs))  # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    # Ajacent open time pdf
    eigs, w = scl.adjacent_open_to_shut_range_pdf_components(
        u1, u2, mec.QAA, mec.QAI, mec.QII, mec.QIA,
        qml.phiA(mec).reshape((1, mec.kA)))
    #    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs)) # Scale factor
    ajpdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    if unit == 'ms':
        t = t * 1000  # x scale in millisec

    return t, ipdf, ajpdf
Exemplo n.º 2
0
def open_time_pdf(mec, tres, tmin=0.00001, tmax=1000, points=512, unit='ms'):
    """
    Calculate ideal asymptotic and exact open time distributions.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    ipdf, epdf, apdf : ndarrays of floats, shape (num of points)
        Ideal, exact and asymptotic open time distributions.
    """

    open = True

    # Asymptotic pdf
    roots = scl.asymptotic_roots(tres,
        mec.QAA, mec.QII, mec.QAI, mec.QIA, mec.kA, mec.kI)

    tmax = (-1 / roots.max()) * 20
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)

    # Ideal pdf.
    eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs)) # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    # Asymptotic pdf
    GAF, GFA = qml.iGs(mec.Q, mec.kA, mec.kI)
    areas = scl.asymptotic_areas(tres, roots,
        mec.QAA, mec.QII, mec.QAI, mec.QIA,
        mec.kA, mec.kI, GAF, GFA)
    apdf = scl.asymptotic_pdf(t, tres, -1 / roots, areas)

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = scl.exact_GAMAxx(mec,
        tres, open)
    epdf = np.zeros(points)
    for i in range(points):
        epdf[i] = (t[i] * scl.exact_pdf(t[i], tres,
            roots, areas, eigvals, gamma00, gamma10, gamma11))
            
    if unit == 'ms':
        t = t * 1000 # x scale in millisec

    return t, ipdf, epdf, apdf
Exemplo n.º 3
0
def adjacent_open_time_pdf(mec, tres, u1, u2, 
    tmin=0.00001, tmax=1000, points=512, unit='ms'):
    """
    Calculate pdf's of ideal all open time and open time adjacent to specified shut
    time range.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    ipdf, ajpdf : ndarrays of floats, shape (num of points)
        Ideal all and adjacent open time distributions.
    """

    # Ideal pdf.
    eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    tmax = (1 / eigs.max()) * 100
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)
    
    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs)) # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    # Ajacent open time pdf
    eigs, w = scl.adjacent_open_to_shut_range_pdf_components(u1, u2, 
        mec.QAA, mec.QAI, mec.QII, mec.QIA, qml.phiA(mec).reshape((1,mec.kA)))
#    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs)) # Scale factor
    ajpdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac
           
    if unit == 'ms':
        t = t * 1000 # x scale in millisec

    return t, ipdf, ajpdf
Exemplo n.º 4
0
def open_time_pdf(mec, tres, tmin=0.00001, tmax=1000, points=512, unit='ms'):
    """
    Calculate ideal asymptotic and exact open time distributions.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    ipdf, epdf, apdf : ndarrays of floats, shape (num of points)
        Ideal, exact and asymptotic open time distributions.
    """

    open = True

    # Asymptotic pdf
    roots = scl.asymptotic_roots(tres, mec.QAA, mec.QII, mec.QAI, mec.QIA,
                                 mec.kA, mec.kI)

    tmax = (-1 / roots.max()) * 20
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)

    # Ideal pdf.
    eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs))  # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    # Asymptotic pdf
    GAF, GFA = qml.iGs(mec.Q, mec.kA, mec.kI)
    areas = scl.asymptotic_areas(tres, roots, mec.QAA, mec.QII, mec.QAI,
                                 mec.QIA, mec.kA, mec.kI, GAF, GFA)
    apdf = scl.asymptotic_pdf(t, tres, -1 / roots, areas)

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = scl.exact_GAMAxx(mec, tres, open)
    epdf = np.zeros(points)
    for i in range(points):
        epdf[i] = (t[i] * scl.exact_pdf(t[i], tres, roots, areas, eigvals,
                                        gamma00, gamma10, gamma11))

    if unit == 'ms':
        t = t * 1000  # x scale in millisec

    return t, ipdf, epdf, apdf
Exemplo n.º 5
0
def subset_time_pdf(mec,
                    tres,
                    state1,
                    state2,
                    tmin=0.00001,
                    tmax=1000,
                    points=512,
                    unit='ms'):
    """
    Calculate ideal pdf of any subset dwell times.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    state1, state2 : ints
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    spdf : ndarray of floats, shape (num of points)
        Subset dwell time pdf.
    """

    open = False
    if open:
        eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    else:
        eigs, w = scl.ideal_dwell_time_pdf_components(mec.QII, qml.phiF(mec))

    tmax = tau.max() * 20
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)

    # Ideal pdf.
    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs))  # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    spdf = np.zeros(points)
    for i in range(points):
        spdf[i] = t[i] * scl.ideal_subset_time_pdf(mec.Q, state1, state2,
                                                   t[i]) * fac

    if unit == 'ms':
        t = t * 1000  # x scale in millisec

    return t, ipdf, spdf
Exemplo n.º 6
0
def subset_time_pdf(mec, tres, state1, state2,
    tmin=0.00001, tmax=1000, points=512, unit='ms'):
    """
    Calculate ideal pdf of any subset dwell times.

    Parameters
    ----------
    mec : instance of type Mechanism
    tres : float
        Time resolution.
    state1, state2 : ints
    tmin, tmax : floats
        Time range for burst length ditribution.
    points : int
        Number of points per plot.
    unit : str
        'ms'- milliseconds.

    Returns
    -------
    t : ndarray of floats, shape (num of points)
        Time in millisec.
    spdf : ndarray of floats, shape (num of points)
        Subset dwell time pdf.
    """

    open = False
    if open:
        eigs, w = scl.ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    else:
        eigs, w = scl.ideal_dwell_time_pdf_components(mec.QII, qml.phiF(mec))

    tmax = tau.max() * 20
    t = np.logspace(math.log10(tmin), math.log10(tmax), points)

    # Ideal pdf.
    fac = 1 / np.sum((w / eigs) * np.exp(-tres * eigs)) # Scale factor
    ipdf = t * pdfs.expPDF(t, 1 / eigs, w / eigs) * fac

    spdf = np.zeros(points)
    for i in range(points):
        spdf[i] = t[i] * scl.ideal_subset_time_pdf(mec.Q,
            state1, state2, t[i]) * fac

    if unit == 'ms':
        t = t * 1000 # x scale in millisec

    return t, ipdf, spdf
Exemplo n.º 7
0
def corr_open_shut(mec, lag):
    """
    Calculate data for the plot of open, shut and open-shut time correlations.
    
    Parameters
    ----------
    mec : instance of type Mechanism
    lag : int
        Number of lags.

    Returns
    -------
    c : ndarray of floats, shape (num of points,)
        Concentration in mikroM
    br : ndarray of floats, shape (num of points,)
        Mean burst length in millisec.
    brblk : ndarray of floats, shape (num of points,)
        Mean burst length in millisec corrected for fast block.
    """

    kA, kF = mec.kA, mec.kI
    GAF, GFA = qml.iGs(mec.Q, kA, kF)
    XAA, XFF = np.dot(GAF, GFA), np.dot(GFA, GAF)
    phiA, phiF = qml.phiA(mec).reshape((1, kA)), qml.phiF(mec).reshape((1, kF))
    varA = scl.corr_variance_A(phiA, mec.QAA, kA)
    varF = scl.corr_variance_A(phiF, mec.QII, kF)

    r = np.arange(1, lag + 1)
    roA, roF, roAF = np.zeros(lag), np.zeros(lag), np.zeros(lag)
    for i in range(lag):
        covA = scl.corr_covariance_A(i + 1, phiA, mec.QAA, XAA, kA)
        roA[i] = scl.correlation_coefficient(covA, varA, varA)
        covF = scl.corr_covariance_A(i + 1, phiF, mec.QII, XFF, kF)
        roF[i] = scl.correlation_coefficient(covF, varF, varF)
        covAF = scl.corr_covariance_AF(i + 1, phiA, mec.QAA, mec.QII, XAA, GAF,
                                       kA, kF)
        roAF[i] = scl.correlation_coefficient(covAF, varA, varF)

    return r, roA, roF, roAF
Exemplo n.º 8
0
def corr_open_shut(mec, lag):
    """
    Calculate data for the plot of open, shut and open-shut time correlations.
    
    Parameters
    ----------
    mec : instance of type Mechanism
    lag : int
        Number of lags.

    Returns
    -------
    c : ndarray of floats, shape (num of points,)
        Concentration in mikroM
    br : ndarray of floats, shape (num of points,)
        Mean burst length in millisec.
    brblk : ndarray of floats, shape (num of points,)
        Mean burst length in millisec corrected for fast block.
    """
    
    kA, kF = mec.kA, mec.kI
    GAF, GFA = qml.iGs(mec.Q, kA, kF)
    XAA, XFF = np.dot(GAF, GFA), np.dot(GFA, GAF)
    phiA, phiF = qml.phiA(mec).reshape((1,kA)), qml.phiF(mec).reshape((1,kF))
    varA = scl.corr_variance_A(phiA, mec.QAA, kA)
    varF = scl.corr_variance_A(phiF, mec.QII, kF)
    
    r = np.arange(1, lag + 1)
    roA, roF, roAF = np.zeros(lag), np.zeros(lag), np.zeros(lag)
    for i in range(lag):
        covA = scl.corr_covariance_A(i+1, phiA, mec.QAA, XAA, kA)
        roA[i] = scl.correlation_coefficient(covA, varA, varA)
        covF = scl.corr_covariance_A(i+1, phiF, mec.QII, XFF, kF)
        roF[i] = scl.correlation_coefficient(covF, varF, varF)
        covAF = scl.corr_covariance_AF(i+1, phiA, mec.QAA, mec.QII,
            XAA, GAF, kA, kF)
        roAF[i] = scl.correlation_coefficient(covAF, varA, varF)
            
    return r, roA, roF, roAF
Exemplo n.º 9
0
def printout_adjacent(mec, t1, t2):
    """

    """

    str = ('\n*************************************\n' +
        ' OPEN TIMES ADJACENT TO SPECIFIED SHUT TIME RANGE\n')
    
    kA = mec.kA
    phiA = qml.phiA(mec).reshape((1,kA))
    
    str += ('PDF of open times that precede shut times between {0:.3f}\
 and {1:.3f} ms\n'.format(t1 * 1000, t2 * 1000))
        
    eigs, w = adjacent_open_to_shut_range_pdf_components(t1, t2, 
        mec.QAA, mec.QAF, mec.QFF, mec.QFA, phiA)
    str += pdfs.expPDF_printout(eigs, w)

    mean = adjacent_open_to_shut_range_mean(t1, t2, 
        mec.QAA, mec.QAF, mec.QFF, mec.QFA, phiA)
    str += ('Mean from direct calculation (ms) = {0:.6f}\n'.format(mean * 1000))
    return str
Exemplo n.º 10
0
def printout_adjacent(mec, t1, t2):
    """

    """

    str = ('\n*************************************\n' +
           ' OPEN TIMES ADJACENT TO SPECIFIED SHUT TIME RANGE\n')

    kA = mec.kA
    phiA = qml.phiA(mec).reshape((1, kA))

    str += ('PDF of open times that precede shut times between {0:.3f}\
 and {1:.3f} ms\n'.format(t1 * 1000, t2 * 1000))

    eigs, w = adjacent_open_to_shut_range_pdf_components(
        t1, t2, mec.QAA, mec.QAF, mec.QFF, mec.QFA, phiA)
    str += pdfs.expPDF_printout(eigs, w)

    mean = adjacent_open_to_shut_range_mean(t1, t2, mec.QAA, mec.QAF, mec.QFF,
                                            mec.QFA, phiA)
    str += ('Mean from direct calculation (ms) = {0:.6f}\n'.format(mean *
                                                                   1000))
    return str
Exemplo n.º 11
0
def likelihood(theta, opts):
    """
    Calculate likelihood for a series of open and shut times using ideal
    probability density functions.
    """

    mec = opts['mec']
    conc = opts['conc']
    bursts = opts['data']

    #mec.set_rateconstants(np.exp(theta))
    mec.theta_unsqueeze(np.exp(theta))
    mec.set_eff('c', conc)

    startB = qml.phiA(mec)
    endB = np.ones((mec.kF, 1))

    loglik = 0
    for ind in bursts:
        burst = bursts[ind]
        grouplik = startB
        for i in range(len(burst)):
            t = burst[i]
            if i % 2 == 0: # open time
                GAFt = qml.iGt(t, mec.QAA, mec.QAF)
            else: # shut
                GAFt = qml.iGt(t, mec.QFF, mec.QFA)
            grouplik = np.dot(grouplik, GAFt)
            if grouplik.max() > 1e50:
                grouplik = grouplik * 1e-100
                print ('grouplik was scaled down')
        grouplik = np.dot(grouplik, endB)
        loglik += log(grouplik[0])

    newrates = np.log(mec.theta())
    return -loglik, newrates
Exemplo n.º 12
0
def likelihood(theta, opts):
    """
    Calculate likelihood for a series of open and shut times using ideal
    probability density functions.
    """

    mec = opts['mec']
    conc = opts['conc']
    bursts = opts['data']

    #mec.set_rateconstants(np.exp(theta))
    mec.theta_unsqueeze(np.exp(theta))
    mec.set_eff('c', conc)

    startB = qml.phiA(mec)
    endB = np.ones((mec.kF, 1))

    loglik = 0
    for ind in bursts:
        burst = bursts[ind]
        grouplik = startB
        for i in range(len(burst)):
            t = burst[i]
            if i % 2 == 0:  # open time
                GAFt = qml.iGt(t, mec.QAA, mec.QAF)
            else:  # shut
                GAFt = qml.iGt(t, mec.QFF, mec.QFA)
            grouplik = np.dot(grouplik, GAFt)
            if grouplik.max() > 1e50:
                grouplik = grouplik * 1e-100
                print('grouplik was scaled down')
        grouplik = np.dot(grouplik, endB)
        loglik += log(grouplik[0])

    newrates = np.log(mec.theta())
    return -loglik, newrates
Exemplo n.º 13
0
def printout_occupancies(mec, tres):
    """
    """

    str = ('\n\n\n*******************************************\n\n' +
        'Open\tEquilibrium\tMean life\tMean latency (ms)\n' +
        'state\toccupancy\t(ms)\tto next shutting\n' +
        '\t\t\tgiven start in this state\n')

    pinf = qml.pinf(mec.Q)

    for i in range(mec.k):
        if i == 0:
            mean_life_A = ideal_subset_mean_life_time(mec.Q, 1, mec.kA)
            str += ('Subset A ' +
                '\t{0:.5g}'.format(np.sum(pinf[:mec.kA])) +
                '\t{0:.5g}\n'.format(mean_life_A * 1000))
        if i == mec.kA:
            mean_life_B = ideal_subset_mean_life_time(mec.Q, mec.kA + 1, mec.kE)
            str += ('\nShut\tEquilibrium\tMean life\tMean latency (ms)\n' +
                'state\toccupancy\t(ms)\tto next opening\n' +
                '\t\t\tgiven start in this state\n' +
                'Subset B ' +
                '\t{0:.5g}'.format(np.sum(pinf[mec.kA : mec.kE])) +
                '\t{0:.5g}\n'.format(mean_life_B * 1000))
        if i == mec.kE:
            mean_life_C = ideal_subset_mean_life_time(mec.Q, mec.kE + 1, mec.kG)
            str += ('\nSubset C ' +
                '\t{0:.5g}'.format(np.sum(pinf[mec.kE : mec.kG])) +
                '\t{0:.5g}\n'.format(mean_life_C * 1000))
        if i == mec.kG:
            mean_life_D = ideal_subset_mean_life_time(mec.Q, mec.kG + 1, mec.k)
            str += ('\nSubset D ' +
                '\t{0:.5g}'.format(np.sum(pinf[mec.kG : mec.k])) +
                '\t{0:.5g}\n'.format(mean_life_D * 1000))

        mean = ideal_mean_latency_given_start_state(mec, i+1)
        str += ('{0:d}'.format(i+1) +
            '\t{0:.5g}'.format(pinf[i]) +
            '\t{0:.5g}'.format(-1 / mec.Q[i,i] * 1000) +
            '\t{0:.5g}\n'.format(mean * 1000))

    expQFF = qml.expQt(mec.QFF, tres)
    expQAA = qml.expQt(mec.QAA, tres)
    GAF, GFA = qml.iGs(mec.Q, mec.kA, mec.kF)
    eGAF = qml.eGs(GAF, GFA, mec.kA, mec.kF, expQFF)
    eGFA = qml.eGs(GFA, GAF, mec.kF, mec.kA, expQAA)
    phiA = qml.phiHJC(eGAF, eGFA, mec.kA)
    phiF = qml.phiHJC(eGFA, eGAF, mec.kF)

    str += ('\n\nInitial vector for HJC openings phiOp =\n')
    for i in range(phiA.shape[0]):
        str += ('\t{0:.5g}'.format(phiA[i]))
    str += ('\nInitial vector for ideal openings phiOp =\n')
    phiAi = qml.phiA(mec)
    for i in range(phiA.shape[0]):
        str += ('\t{0:.5g}'.format(phiAi[i]))
    str += ('\nInitial vector for HJC shuttings phiSh =\n')
    for i in range(phiF.shape[0]):
        str += ('\t{0:.5g}'.format(phiF[i]))
    str += ('\nInitial vector for ideal shuttings phiSh =\n')
    phiFi = qml.phiF(mec)
    for i in range(phiF.shape[0]):
        str += ('\t{0:.5g}'.format(phiFi[i]))
    str += '\n'
    
    return str
Exemplo n.º 14
0
def printout_correlations(mec, output=sys.stdout, eff='c'):
    """

    """

    str = ('\n\n*************************************\n' +
        'CORRELATIONS\n')
    
    kA, kI = mec.kA, mec.kI
    str += ('kA, kF = {0:d}, {1:d}\n'.format(kA, kI))
    GAF, GFA = qml.iGs(mec.Q, kA, kI)
    rGAF, rGFA = np.rank(GAF), np.rank(GFA)
    str += ('Ranks of GAF, GFA = {0:d}, {1:d}\n'.format(rGAF, rGFA))
    XFF = np.dot(GFA, GAF)
    rXFF = np.rank(XFF)
    str += ('Rank of GFA * GAF = {0:d}\n'.format(rXFF))
    ncF = rXFF - 1
    eigXFF, AXFF = qml.eigs(XFF)
    str += ('Eigenvalues of GFA * GAF:\n')
    str1 = ''
    for i in range(kI):
        str1 += '\t{0:.5g}'.format(eigXFF[i])
    str += str1 + '\n'
    XAA = np.dot(GAF, GFA)
    rXAA = np.rank(XAA)
    str += ('Rank of GAF * GFA = {0:d}\n'.format(rXAA))
    ncA = rXAA - 1
    eigXAA, AXAA = qml.eigs(XAA)
    str += ('Eigenvalues of GAF * GFA:\n')
    str1 = ''
    for i in range(kA):
        str1 += '\t{0:.5g}'.format(eigXAA[i])
    str += str1 + '\n'
    phiA, phiF = qml.phiA(mec).reshape((1,kA)), qml.phiF(mec).reshape((1,kI))
    varA = corr_variance_A(phiA, mec.QAA, kA)
    varF = corr_variance_A(phiF, mec.QII, kI)
    
    #   open - open time correlations
    str += ('\n OPEN - OPEN TIME CORRELATIONS')
    str += ('Variance of open time = {0:.5g}\n'.format(varA))
    SDA = sqrt(varA)
    str += ('SD of all open times = {0:.5g} ms\n'.format(SDA * 1000))
    n = 50
    SDA_mean_n = SDA / sqrt(float(n))
    str += ('SD of means of {0:d} open times if'.format(n) + 
        'uncorrelated = {0:.5g} ms\n'.format(SDA_mean_n * 1000))
    covAtot = 0
    for i in range(1, n):
        covA = corr_covariance_A(i+1, phiA, mec.QAA, XAA, kA)
        ro = correlation_coefficient(covA, varA, varA)
        covAtot += (n - i) * ro * varA
    vtot = n * varA + 2. * covAtot
    actSDA = sqrt(vtot / (n * n))
    str += ('Actual SD of mean = {0:.5g} ms\n'.format(actSDA * 1000))
    pA = 100 * (actSDA - SDA_mean_n) / SDA_mean_n
    str += ('Percent difference as result of correlation = {0:.5g}\n'.
        format(pA))
    v2A = corr_limit_A(phiA, mec.QAA, AXAA, eigXAA, kA)
    pmaxA = 100 * (sqrt(1 + 2 * v2A / varA) - 1)
    str += ('Limiting value of percent difference for large n = {0:.5g}\n'.
        format(pmaxA))
    str += ('Correlation coefficients, r(k), for up to lag k = 5:\n')
    for i in range(5):
        covA = corr_covariance_A(i+1, phiA, mec.QAA, XAA, kA)
        ro = correlation_coefficient(covA, varA, varA)
        str += ('r({0:d}) = {1:.5g}\n'.format(i+1, ro))

    # shut - shut time correlations
    str += ('\n SHUT - SHUT TIME CORRELATIONS\n')
    str += ('Variance of shut time = {0:.5g}\n'.format(varF))
    SDF = sqrt(varF)
    str += ('SD of all shut times = {0:.5g} ms\n'.format(SDF * 1000))
    n = 50
    SDF_mean_n = SDF / sqrt(float(n))
    str += ('SD of means of {0:d} shut times if'.format(n) +
        'uncorrelated = {0:.5g} ms\n'.format(SDF_mean_n * 1000))
    covFtot = 0
    for i in range(1, n):
        covF = corr_covariance_A(i+1, phiF, mec.QII, XFF, kI)
        ro = correlation_coefficient(covF, varF, varF)
        covFtot += (n - i) * ro * varF
    vtotF = 50 * varF + 2. * covFtot
    actSDF = sqrt(vtotF / (50. * 50.))
    str += ('Actual SD of mean = {0:.5g} ms\n'.format(actSDF * 1000))
    pF = 100 * (actSDF - SDF_mean_n) / SDF_mean_n
    str += ('Percent difference as result of correlation = {0:.5g}\n'.
        format(pF))
    v2F = corr_limit_A(phiF, mec.QII, AXFF, eigXFF, kI)
    pmaxF = 100 * (sqrt(1 + 2 * v2F / varF) - 1)
    str += ('Limiting value of percent difference for large n = {0:.5g}\n'.
        format(pmaxF))
    str += ('Correlation coefficients, r(k), for up to k = 5 lags:\n')
    for i in range(5):
        covF = corr_covariance_A(i+1, phiF, mec.QII, XFF, kI)
        ro = correlation_coefficient(covF, varF, varF)
        str += ('r({0:d}) = {1:.5g}\n'.format(i+1, ro))

    # open - shut time correlations 
    str += ('\n OPEN - SHUT TIME CORRELATIONS\n')
    str += ('Correlation coefficients, r(k), for up to k= 5 lags:\n')
    for i in range(5):
        covAF = corr_covariance_AF(i+1, phiA, mec.QAA, mec.QII, XAA, GAF, kA, kI)
        ro = correlation_coefficient(covAF, varA, varF)
        str += ('r({0:d}) = {1:.5g}\n'.format(i+1, ro))
    return str
Exemplo n.º 15
0
def printout_occupancies(mec, tres):
    """
    """

    str = ('\n\n\n*******************************************\n\n' +
           'Open\tEquilibrium\tMean life\tMean latency (ms)\n' +
           'state\toccupancy\t(ms)\tto next shutting\n' +
           '\t\t\tgiven start in this state\n')

    pinf = qml.pinf(mec.Q)

    for i in range(mec.k):
        if i == 0:
            mean_life_A = ideal_subset_mean_life_time(mec.Q, 1, mec.kA)
            str += ('Subset A ' + '\t{0:.5g}'.format(np.sum(pinf[:mec.kA])) +
                    '\t{0:.5g}\n'.format(mean_life_A * 1000))
        if i == mec.kA:
            mean_life_B = ideal_subset_mean_life_time(mec.Q, mec.kA + 1,
                                                      mec.kE)
            str += ('\nShut\tEquilibrium\tMean life\tMean latency (ms)\n' +
                    'state\toccupancy\t(ms)\tto next opening\n' +
                    '\t\t\tgiven start in this state\n' + 'Subset B ' +
                    '\t{0:.5g}'.format(np.sum(pinf[mec.kA:mec.kE])) +
                    '\t{0:.5g}\n'.format(mean_life_B * 1000))
        if i == mec.kE:
            mean_life_C = ideal_subset_mean_life_time(mec.Q, mec.kE + 1,
                                                      mec.kG)
            str += ('\nSubset C ' +
                    '\t{0:.5g}'.format(np.sum(pinf[mec.kE:mec.kG])) +
                    '\t{0:.5g}\n'.format(mean_life_C * 1000))
        if i == mec.kG:
            mean_life_D = ideal_subset_mean_life_time(mec.Q, mec.kG + 1, mec.k)
            str += ('\nSubset D ' +
                    '\t{0:.5g}'.format(np.sum(pinf[mec.kG:mec.k])) +
                    '\t{0:.5g}\n'.format(mean_life_D * 1000))

        mean = ideal_mean_latency_given_start_state(mec, i + 1)
        str += ('{0:d}'.format(i + 1) + '\t{0:.5g}'.format(pinf[i]) +
                '\t{0:.5g}'.format(-1 / mec.Q[i, i] * 1000) +
                '\t{0:.5g}\n'.format(mean * 1000))

    expQFF = qml.expQt(mec.QFF, tres)
    expQAA = qml.expQt(mec.QAA, tres)
    GAF, GFA = qml.iGs(mec.Q, mec.kA, mec.kF)
    eGAF = qml.eGs(GAF, GFA, mec.kA, mec.kF, expQFF)
    eGFA = qml.eGs(GFA, GAF, mec.kF, mec.kA, expQAA)
    phiA = qml.phiHJC(eGAF, eGFA, mec.kA)
    phiF = qml.phiHJC(eGFA, eGAF, mec.kF)

    str += ('\n\nInitial vector for HJC openings phiOp =\n')
    for i in range(phiA.shape[0]):
        str += ('\t{0:.5g}'.format(phiA[i]))
    str += ('\nInitial vector for ideal openings phiOp =\n')
    phiAi = qml.phiA(mec)
    for i in range(phiA.shape[0]):
        str += ('\t{0:.5g}'.format(phiAi[i]))
    str += ('\nInitial vector for HJC shuttings phiSh =\n')
    for i in range(phiF.shape[0]):
        str += ('\t{0:.5g}'.format(phiF[i]))
    str += ('\nInitial vector for ideal shuttings phiSh =\n')
    phiFi = qml.phiF(mec)
    for i in range(phiF.shape[0]):
        str += ('\t{0:.5g}'.format(phiFi[i]))
    str += '\n'

    return str
Exemplo n.º 16
0
def printout_distributions(mec, tres, eff='c'):
    """

    """

    str = '\n*******************************************\n'
    GAI, GIA = qml.iGs(mec.Q, mec.kA, mec.kI)
    # OPEN TIME DISTRIBUTIONS
    open = True
    # Ideal pdf
    eigs, w = ideal_dwell_time_pdf_components(mec.QAA, qml.phiA(mec))
    str += 'IDEAL OPEN TIME DISTRIBUTION\n'
    str += pdfs.expPDF_printout(eigs, w)

    # Asymptotic pdf
    #roots = asymptotic_roots(mec, tres, open)
    roots = asymptotic_roots(tres, mec.QAA, mec.QII, mec.QAI, mec.QIA, mec.kA,
                             mec.kI)
    #areas = asymptotic_areas(mec, tres, roots, open)
    areas = asymptotic_areas(tres, roots, mec.QAA, mec.QII, mec.QAI, mec.QIA,
                             mec.kA, mec.kI, GAI, GIA)
    str += '\nASYMPTOTIC OPEN TIME DISTRIBUTION\n'
    str += 'term\ttau (ms)\tarea (%)\trate const (1/sec)\n'
    for i in range(mec.kA):
        str += ('{0:d}'.format(i + 1) +
                '\t{0:.5g}'.format(-1.0 / roots[i] * 1000) +
                '\t{0:.5g}'.format(areas[i] * 100) +
                '\t{0:.5g}\n'.format(-roots[i]))
    areast0 = np.zeros(mec.kA)
    for i in range(mec.kA):
        areast0[i] = areas[i] * np.exp(-tres * roots[i])
    areast0 = areast0 / np.sum(areast0)
    str += ('Areas for asymptotic pdf renormalised for t=0 to\
    infinity (and sum=1), so areas can be compared with ideal pdf.\n')
    for i in range(mec.kA):
        str += ('{0:d}'.format(i + 1) + '\t{0:.5g}\n'.format(areast0[i] * 100))
    mean = exact_mean_time(tres, mec.QAA, mec.QII, mec.QAI, mec.kA, mec.kI,
                           GAI, GIA)
    str += ('Mean open time (ms) = {0:.5g}\n'.format(mean * 1000))

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = exact_GAMAxx(mec, tres, open)
    str += ('\nEXACT OPEN TIME DISTRIBUTION\n')
    str += ('eigen\tg00(m)\tg10(m)\tg11(m)\n')
    for i in range(mec.k):
        str += ('{0:.5g}'.format(eigvals[i]) + '\t{0:.5g}'.format(gamma00[i]) +
                '\t{0:.5g}'.format(gamma10[i]) +
                '\t{0:.5g}\n'.format(gamma11[i]))

    str += ('\n\n*******************************************\n')
    # SHUT TIME DISTRIBUTIONS
    open = False
    # Ideal pdf
    eigs, w = ideal_dwell_time_pdf_components(mec.QII, qml.phiF(mec))
    str += ('IDEAL SHUT TIME DISTRIBUTION\n')
    str += pdfs.expPDF_printout(eigs, w)

    # Asymptotic pdf
    #roots = asymptotic_roots(mec, tres, open)
    roots = asymptotic_roots(tres, mec.QII, mec.QAA, mec.QIA, mec.QAI, mec.kI,
                             mec.kA)
    #areas = asymptotic_areas(mec, tres, roots, open)
    areas = asymptotic_areas(tres, roots, mec.QII, mec.QAA, mec.QIA, mec.QAI,
                             mec.kI, mec.kA, GIA, GAI)
    str += ('\nASYMPTOTIC SHUT TIME DISTRIBUTION\n')
    str += ('term\ttau (ms)\tarea (%)\trate const (1/sec)\n')
    for i in range(mec.kI):
        str += ('{0:d}'.format(i + 1) +
                '\t{0:.5g}'.format(-1.0 / roots[i] * 1000) +
                '\t{0:.5g}'.format(areas[i] * 100) +
                '\t{0:.5g}\n'.format(-roots[i]))
    areast0 = np.zeros(mec.kI)
    for i in range(mec.kI):
        areast0[i] = areas[i] * np.exp(-tres * roots[i])
    areast0 = areast0 / np.sum(areast0)
    str += ('Areas for asymptotic pdf renormalised for t=0 to\
    infinity (and sum=1), so areas can be compared with ideal pdf.\n')
    for i in range(mec.kI):
        str += ('{0:d}'.format(i + 1) + '\t{0:.5g}\n'.format(areast0[i] * 100))
    mean = exact_mean_time(tres, mec.QII, mec.QAA, mec.QIA, mec.kI, mec.kA,
                           GIA, GAI)
    str += ('Mean shut time (ms) = {0:.6f}\n'.format(mean * 1000))

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = exact_GAMAxx(mec, tres, open)
    str += ('\nEXACT SHUT TIME DISTRIBUTION\n' +
            'eigen\tg00(m)\tg10(m)\tg11(m)\n')
    for i in range(mec.k):
        str += ('{0:.5g}'.format(eigvals[i]) + '\t{0:.5g}'.format(gamma00[i]) +
                '\t{0:.5g}'.format(gamma10[i]) +
                '\t{0:.5g}\n'.format(gamma11[i]))

    # Transition probabilities
    pi = transition_probability(mec.Q)
    str += ('\nProbability of transitions regardless of time:\n')
    for i in range(mec.k):
        str1 = '['
        for j in range(mec.k):
            str1 += '{0:.4g}\t'.format(pi[i, j])
        str1 += ']\n'
        str += str1

    # Transition frequency
    f = transition_frequency(mec.Q)
    str += ('\nFrequency of transitions (per second):\n')
    for i in range(mec.k):
        str1 = '['
        for j in range(mec.k):
            str1 += '{0:.4g}\t'.format(f[i, j])
        str1 += ']\n'
        str += str1

    return str
Exemplo n.º 17
0
def printout_correlations(mec, output=sys.stdout, eff='c'):
    """

    """

    str = ('\n\n*************************************\n' + 'CORRELATIONS\n')

    kA, kI = mec.kA, mec.kI
    str += ('kA, kF = {0:d}, {1:d}\n'.format(kA, kI))
    GAF, GFA = qml.iGs(mec.Q, kA, kI)
    rGAF, rGFA = np.rank(GAF), np.rank(GFA)
    str += ('Ranks of GAF, GFA = {0:d}, {1:d}\n'.format(rGAF, rGFA))
    XFF = np.dot(GFA, GAF)
    rXFF = np.rank(XFF)
    str += ('Rank of GFA * GAF = {0:d}\n'.format(rXFF))
    ncF = rXFF - 1
    eigXFF, AXFF = qml.eigs(XFF)
    str += ('Eigenvalues of GFA * GAF:\n')
    str1 = ''
    for i in range(kI):
        str1 += '\t{0:.5g}'.format(eigXFF[i])
    str += str1 + '\n'
    XAA = np.dot(GAF, GFA)
    rXAA = np.rank(XAA)
    str += ('Rank of GAF * GFA = {0:d}\n'.format(rXAA))
    ncA = rXAA - 1
    eigXAA, AXAA = qml.eigs(XAA)
    str += ('Eigenvalues of GAF * GFA:\n')
    str1 = ''
    for i in range(kA):
        str1 += '\t{0:.5g}'.format(eigXAA[i])
    str += str1 + '\n'
    phiA, phiF = qml.phiA(mec).reshape((1, kA)), qml.phiF(mec).reshape((1, kI))
    varA = corr_variance_A(phiA, mec.QAA, kA)
    varF = corr_variance_A(phiF, mec.QII, kI)

    #   open - open time correlations
    str += ('\n OPEN - OPEN TIME CORRELATIONS')
    str += ('Variance of open time = {0:.5g}\n'.format(varA))
    SDA = sqrt(varA)
    str += ('SD of all open times = {0:.5g} ms\n'.format(SDA * 1000))
    n = 50
    SDA_mean_n = SDA / sqrt(float(n))
    str += ('SD of means of {0:d} open times if'.format(n) +
            'uncorrelated = {0:.5g} ms\n'.format(SDA_mean_n * 1000))
    covAtot = 0
    for i in range(1, n):
        covA = corr_covariance_A(i + 1, phiA, mec.QAA, XAA, kA)
        ro = correlation_coefficient(covA, varA, varA)
        covAtot += (n - i) * ro * varA
    vtot = n * varA + 2. * covAtot
    actSDA = sqrt(vtot / (n * n))
    str += ('Actual SD of mean = {0:.5g} ms\n'.format(actSDA * 1000))
    pA = 100 * (actSDA - SDA_mean_n) / SDA_mean_n
    str += (
        'Percent difference as result of correlation = {0:.5g}\n'.format(pA))
    v2A = corr_limit_A(phiA, mec.QAA, AXAA, eigXAA, kA)
    pmaxA = 100 * (sqrt(1 + 2 * v2A / varA) - 1)
    str += ('Limiting value of percent difference for large n = {0:.5g}\n'.
            format(pmaxA))
    str += ('Correlation coefficients, r(k), for up to lag k = 5:\n')
    for i in range(5):
        covA = corr_covariance_A(i + 1, phiA, mec.QAA, XAA, kA)
        ro = correlation_coefficient(covA, varA, varA)
        str += ('r({0:d}) = {1:.5g}\n'.format(i + 1, ro))

    # shut - shut time correlations
    str += ('\n SHUT - SHUT TIME CORRELATIONS\n')
    str += ('Variance of shut time = {0:.5g}\n'.format(varF))
    SDF = sqrt(varF)
    str += ('SD of all shut times = {0:.5g} ms\n'.format(SDF * 1000))
    n = 50
    SDF_mean_n = SDF / sqrt(float(n))
    str += ('SD of means of {0:d} shut times if'.format(n) +
            'uncorrelated = {0:.5g} ms\n'.format(SDF_mean_n * 1000))
    covFtot = 0
    for i in range(1, n):
        covF = corr_covariance_A(i + 1, phiF, mec.QII, XFF, kI)
        ro = correlation_coefficient(covF, varF, varF)
        covFtot += (n - i) * ro * varF
    vtotF = 50 * varF + 2. * covFtot
    actSDF = sqrt(vtotF / (50. * 50.))
    str += ('Actual SD of mean = {0:.5g} ms\n'.format(actSDF * 1000))
    pF = 100 * (actSDF - SDF_mean_n) / SDF_mean_n
    str += (
        'Percent difference as result of correlation = {0:.5g}\n'.format(pF))
    v2F = corr_limit_A(phiF, mec.QII, AXFF, eigXFF, kI)
    pmaxF = 100 * (sqrt(1 + 2 * v2F / varF) - 1)
    str += ('Limiting value of percent difference for large n = {0:.5g}\n'.
            format(pmaxF))
    str += ('Correlation coefficients, r(k), for up to k = 5 lags:\n')
    for i in range(5):
        covF = corr_covariance_A(i + 1, phiF, mec.QII, XFF, kI)
        ro = correlation_coefficient(covF, varF, varF)
        str += ('r({0:d}) = {1:.5g}\n'.format(i + 1, ro))

    # open - shut time correlations
    str += ('\n OPEN - SHUT TIME CORRELATIONS\n')
    str += ('Correlation coefficients, r(k), for up to k= 5 lags:\n')
    for i in range(5):
        covAF = corr_covariance_AF(i + 1, phiA, mec.QAA, mec.QII, XAA, GAF, kA,
                                   kI)
        ro = correlation_coefficient(covAF, varA, varF)
        str += ('r({0:d}) = {1:.5g}\n'.format(i + 1, ro))
    return str
Exemplo n.º 18
0
def printout_distributions(mec, tres, eff='c'):
    """

    """

    str = '\n*******************************************\n'
    GAI, GIA = qml.iGs(mec.Q, mec.kA, mec.kI)
    # OPEN TIME DISTRIBUTIONS
    open = True
    # Ideal pdf
    eigs, w = ideal_dwell_time_pdf_components(mec.QAA,
        qml.phiA(mec))
    str += 'IDEAL OPEN TIME DISTRIBUTION\n'
    str += pdfs.expPDF_printout(eigs, w)

    # Asymptotic pdf
    #roots = asymptotic_roots(mec, tres, open)
    roots = asymptotic_roots(tres,
        mec.QAA, mec.QII, mec.QAI, mec.QIA, mec.kA, mec.kI)
    #areas = asymptotic_areas(mec, tres, roots, open)
    areas = asymptotic_areas(tres, roots,
        mec.QAA, mec.QII, mec.QAI, mec.QIA, mec.kA, mec.kI, GAI, GIA)
    str += '\nASYMPTOTIC OPEN TIME DISTRIBUTION\n'
    str += 'term\ttau (ms)\tarea (%)\trate const (1/sec)\n'
    for i in range(mec.kA):
        str += ('{0:d}'.format(i+1) +
        '\t{0:.5g}'.format(-1.0 / roots[i] * 1000) +
        '\t{0:.5g}'.format(areas[i] * 100) +
        '\t{0:.5g}\n'.format(- roots[i]))
    areast0 = np.zeros(mec.kA)
    for i in range(mec.kA):
        areast0[i] = areas[i] * np.exp(- tres * roots[i])
    areast0 = areast0 / np.sum(areast0)
    str += ('Areas for asymptotic pdf renormalised for t=0 to\
    infinity (and sum=1), so areas can be compared with ideal pdf.\n')
    for i in range(mec.kA):
        str += ('{0:d}'.format(i+1) +
        '\t{0:.5g}\n'.format(areast0[i] * 100))
    mean = exact_mean_time(tres,
            mec.QAA, mec.QII, mec.QAI, mec.kA, mec.kI, GAI, GIA)
    str += ('Mean open time (ms) = {0:.5g}\n'.format(mean * 1000))

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = exact_GAMAxx(mec, tres, open)
    str += ('\nEXACT OPEN TIME DISTRIBUTION\n')
    str += ('eigen\tg00(m)\tg10(m)\tg11(m)\n')
    for i in range(mec.k):
        str += ('{0:.5g}'.format(eigvals[i]) +
        '\t{0:.5g}'.format(gamma00[i]) +
        '\t{0:.5g}'.format(gamma10[i]) +
        '\t{0:.5g}\n'.format(gamma11[i]))

    str += ('\n\n*******************************************\n')
    # SHUT TIME DISTRIBUTIONS
    open = False
    # Ideal pdf
    eigs, w = ideal_dwell_time_pdf_components(mec.QII, qml.phiF(mec))
    str += ('IDEAL SHUT TIME DISTRIBUTION\n')
    str += pdfs.expPDF_printout(eigs, w)

    # Asymptotic pdf
    #roots = asymptotic_roots(mec, tres, open)
    roots = asymptotic_roots(tres,
        mec.QII, mec.QAA, mec.QIA, mec.QAI, mec.kI, mec.kA)
    #areas = asymptotic_areas(mec, tres, roots, open)
    areas = asymptotic_areas(tres, roots,
        mec.QII, mec.QAA, mec.QIA, mec.QAI, mec.kI, mec.kA, GIA, GAI)
    str += ('\nASYMPTOTIC SHUT TIME DISTRIBUTION\n')
    str += ('term\ttau (ms)\tarea (%)\trate const (1/sec)\n')
    for i in range(mec.kI):
        str += ('{0:d}'.format(i+1) +
        '\t{0:.5g}'.format(-1.0 / roots[i] * 1000) +
        '\t{0:.5g}'.format(areas[i] * 100) +
        '\t{0:.5g}\n'.format(- roots[i]))
    areast0 = np.zeros(mec.kI)
    for i in range(mec.kI):
        areast0[i] = areas[i] * np.exp(- tres * roots[i])
    areast0 = areast0 / np.sum(areast0)
    str += ('Areas for asymptotic pdf renormalised for t=0 to\
    infinity (and sum=1), so areas can be compared with ideal pdf.\n')
    for i in range(mec.kI):
        str += ('{0:d}'.format(i+1) +
        '\t{0:.5g}\n'.format(areast0[i] * 100))
    mean = exact_mean_time(tres,
            mec.QII, mec.QAA, mec.QIA, mec.kI, mec.kA, GIA, GAI)
    str += ('Mean shut time (ms) = {0:.6f}\n'.format(mean * 1000))

    # Exact pdf
    eigvals, gamma00, gamma10, gamma11 = exact_GAMAxx(mec, tres, open)
    str += ('\nEXACT SHUT TIME DISTRIBUTION\n' + 
        'eigen\tg00(m)\tg10(m)\tg11(m)\n')
    for i in range(mec.k):
        str += ('{0:.5g}'.format(eigvals[i]) +
        '\t{0:.5g}'.format(gamma00[i]) +
        '\t{0:.5g}'.format(gamma10[i]) +
        '\t{0:.5g}\n'.format(gamma11[i]))

    # Transition probabilities
    pi = transition_probability(mec.Q)
    str += ('\nProbability of transitions regardless of time:\n')
    for i in range(mec.k):
        str1 = '['
        for j in range(mec.k):
            str1 += '{0:.4g}\t'.format(pi[i,j])
        str1 += ']\n'
        str += str1

    # Transition frequency
    f = transition_frequency(mec.Q)
    str += ('\nFrequency of transitions (per second):\n')
    for i in range(mec.k):
        str1 = '['
        for j in range(mec.k):
            str1 += '{0:.4g}\t'.format(f[i,j])
        str1 += ']\n'
        str += str1
        
    return str