Example #1
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
Example #2
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
Example #3
0
def printout_tcrit(mec):
    """
    Output calculations based on division into bursts by critical time (tcrit).

    Parameters
    ----------
    mec : dcpyps.Mechanism
        The mechanism to be analysed.
    output : output device
        Default device: sys.stdout
    """

    str = ('\n\n*******************************************\n' +
        'CALCULATIONS BASED ON DIVISION INTO BURSTS BY' +
        ' tcrit- CRITICAL TIME.\n')
    # Ideal shut time pdf
    eigs, w = ideal_dwell_time_pdf_components(mec.QII, qml.phiF(mec))
    str += ('\nIDEAL SHUT TIME DISTRIBUTION\n')
    str += pdfs.expPDF_printout(eigs, w)
    taus = 1 / eigs
    areas = w /eigs
    taus, areas = sortShell2(taus, areas)

    comps = taus.shape[0]-1
    tcrits = np.empty((3, comps))
    for i in range(comps):
        str += ('\nCritical time between components {0:d} and {1:d}\n'.
            format(i+1, i+2) + '\nEqual % misclassified (DC criterion)\n')
        try:
            tcrit = so.bisect(pdfs.expPDF_tcrit_DC,
                taus[i], taus[i+1], args=(taus, areas, i+1))
            enf, ens, pf, ps = pdfs.expPDF_misclassified(tcrit, taus, areas, i+1)
            str += pdfs.expPDF_misclassified_printout(tcrit, enf, ens, pf, ps)
        except:
            str += ('Bisection with DC criterion failed.\n')
            tcrit = None
        tcrits[0, i] = tcrit
        
        str += ('\nEqual # misclassified (Clapham & Neher criterion)\n')
        try:
            tcrit = so.bisect(pdfs.expPDF_tcrit_CN,
                taus[i], taus[i+1], args=(taus, areas, i+1))
            enf, ens, pf, ps = pdfs.expPDF_misclassified(tcrit, taus, areas, i+1)
            str += pdfs.expPDF_misclassified_printout(tcrit, enf, ens, pf, ps)
        except:
            str += ('Bisection with Clapham & Neher criterion failed.\n')
            tcrit = None
        tcrits[1, i] = tcrit
        
        str += ('\nMinimum total # misclassified (Jackson et al criterion)')
        try:
            tcrit = so.bisect(pdfs.expPDF_tcrit_Jackson,
                taus[i], taus[i+1], args=(taus, areas, i+1))
            enf, ens, pf, ps = pdfs.expPDF_misclassified(tcrit, taus, areas, i+1)
            str += pdfs.expPDF_misclassified_printout(tcrit, enf, ens, pf, ps)
        except:
            str += ('\nBisection with Jackson et al criterion failed.')
            tcrit = None
        tcrits[2, i] = tcrit
        
    str += ('\nSUMMARY of tcrit values:\n' +
        'Components  DC\tC&N\tJackson\n')
    for i in range(comps):
        str += ('{0:d} to {1:d} '.format(i+1, i+2) +
            '\t{0:.5g}'.format(tcrits[0, i] * 1000) +
            '\t{0:.5g}'.format(tcrits[1, i] * 1000) +
            '\t{0:.5g}\n'.format(tcrits[2, i] * 1000))
            
    return str
Example #4
0
def printout_pdfs(mec, output=sys.stdout):
    """
    Output burst calculations into selected device (sys.stdout, printer, file,
    text field.

    Parameters
    ----------
    mec : dcpyps.Mechanism
        The mechanism to be analysed.
    output : output device
        Default device: sys.stdout
    """

    str = ('\n*******************************************\n' +
        'CALCULATED SINGLE CHANNEL BURST PDFS ETC....\n')

    # # #
    phiB = phiBurst(mec)
    str += ('Initial vector for burst (phiB) = \n')
    str1 = ''
    for i in range(mec.kA):
        str1 += '{0:.5g}\t'.format(phiB[i])
    str += str1 + '\n'
    endB = endBurst(mec)
    str += 'End vector for burst (endB) = \n'
    str1 = ''
    for i in range(mec.kA):
        str1 += '{0:.5g}\t'.format(endB[i, 0])
    str += str1 + '\n'

    # # #
    eigs, w = length_pdf_components(mec)
    str += ('\nTotal burst length, unconditional pdf\n')
    str += ('Fbst(t) =\n')
    str += pdfs.expPDF_printout(eigs, w)
    mbl = length_mean(mec)
    str += ('Mean from direct matrix calc = {0:.5g} millisec\n'.
        format(mbl * 1000))
        
    # # #
    eigs, w = length_no_single_openings_pdf_components(mec)
    str += ('\nBurst length pdf for bursts with 2 or more openings.\n')
    str += ('Fbst(bst>1) =\n')
    str += pdfs.expPDF_printout(eigs, w)

    # # #
    rho, w = openings_distr_components(mec)
    str += ('\nNumber (r) of openings / burst (unconditional)\n')
    str += ('P(r) =\n')
    str += pdfs.geometricPDF_printout(rho, w)
    mu = openings_mean(mec)
    str += ('Mean from direct matrix calc = {0:.5g}\n'. format(mu))

    # # #
    str += ('\nPDF of first opening in a burst with 2 or more openings\n')
    str += ('f(open; r>1) =\n')
    eigs, w = first_opening_length_pdf_components(mec)
    str += pdfs.expPDF_printout(eigs, w)

    # # #
    str += ('\nPDF of total open time per bursts\n')
    str += ('f(open tot) =\n')
    eigs, w = open_time_total_pdf_components(mec)
    str += pdfs.expPDF_printout(eigs, w)
    mop = open_time_mean(mec)
    str += ('Mean from direct matrix calc = {0:.5g} '.
        format(mop * 1000) + 'millisec\n')

    # # #
    str += ('\nPDF of total shut time per bursts for bursts with at least 2 openings\n')
    str += ('f(gap tot) =\n')
    eigs, w = shut_time_total_pdf_components_2more_openings(mec)
    str += pdfs.expPDF_printout(eigs, w)
    msh = shut_time_total_mean(mec)
    str += ('Mean of total shut time for all bursts = {0:.5g} '.
        format(msh * 1000) + 'millisec\n')

    str += ('\nNo of gaps within burst per unit open time = {0:.5g} \n'.
        format((mu - 1) / mop))

    # # #
    str += ('\nPDF of gaps inside bursts\n')
    str += ('f(gap) =\n')
    eigs, w = shut_times_inside_burst_pdf_components(mec)
    str += pdfs.expPDF_printout(eigs, w)

    # # #
    str += ('\nPDF of gaps between bursts\n')
    str += ('f(gap) =\n')
    eigs, w = shut_times_between_burst_pdf_components(mec)
    str += pdfs.expPDF_printout(eigs, w)
    msh = shut_times_between_burst_mean(mec)
    str += ('Mean from direct matrix calc = {0:.5g} '.
        format(msh * 1000) + 'millisec\n')

    # # #
    bpop = mop / mbl
    str += ('\nPopen WITHIN BURST = (open time/bst)/(bst length)\
        = {0:.5g} \n'.format(bpop))
    tpop = mop / (mbl + msh)
    str += ('Total Popen = (open time/bst)/(bst_length + ' +
        'mean gap between burst) = {0:.5g} \n'.format(tpop))

    return str