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
def burst_length_pdf(mec, multicomp=False, conditional=False, tmin=0.00001, tmax=1000, points=512): """ Calculate the mean burst length and data for burst length distribution. Parameters ---------- mec : instance of type Mechanism conditional : bool True if conditional distribution is plotted. tmin, tmax : floats Time range for burst length ditribution. points : int Number of points per plot. Returns ------- t : ndarray of floats, shape (num of points) Time in millisec. fbst : ndarray of floats, shape (num of points) Burst length pdf. cfbrst : ndarray of floats, shape (num of open states, num of points) Conditional burst length pdf. """ eigs, w = scburst.length_pdf_components(mec) tmax = 20 / min(eigs) t = np.logspace(math.log10(tmin), math.log10(tmax), points) fbst = t * pdfs.expPDF(t, 1 / eigs, w / eigs) if multicomp: mfbst = np.zeros((mec.kE, points)) for i in range(mec.kE): mfbst[i] = t * pdfs.expPDF(t, 1 / eigs[i], w[i] / eigs[i]) return t * 1000, fbst, mfbst if conditional: cfbst = np.zeros((points, mec.kA)) for i in range(points): cfbst[i] = t[i] * scburst.length_cond_pdf(mec, t[i]) cfbrst = cfbst.transpose() return t * 1000, fbst, cfbrst t = t * 1000 # x axis in millisec return t, fbst
def asymptotic_pdf(t, tres, tau, area): """ Calculate asymptotic probabolity density function. Parameters ---------- t : ndarray. Time. tres : float Time resolution. tau : ndarray, shape(k, 1) Time constants. area : ndarray, shape(k, 1) Component relative area. Returns ------- apdf : ndarray. """ t1 = np.extract(t[:] < tres, t) t2 = np.extract(t[:] >= tres, t) apdf2 = t2 * pdfs.expPDF(t2 - tres, tau, area) apdf = np.append(t1 * 0.0, apdf2) return apdf
def shut_time_pdf(mec, tres, tmin=0.00001, tmax=1000, points=512, unit='ms'): """ Calculate ideal asymptotic and exact shut 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 shut time distributions. """ open = False # Asymptotic pdf roots = scl.asymptotic_roots(tres, mec.QII, mec.QAA, mec.QIA, mec.QAI, mec.kI, mec.kA) 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.QII, qml.phiF(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.QII, mec.QAA, mec.QIA, mec.QAI, mec.kI, mec.kA, GFA, GAF) 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
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
def exact_pdf(t, tres, roots, areas, eigvals, gamma00, gamma10, gamma11): r""" Calculate exponential probabolity density function with exact solution for missed events correction (Eq. 21, HJC92). .. math:: :nowrap: \begin{align*} f(t) = \begin{cases} f_0(t) & \text{for}\; 0 \leq t \leq t_\text{res} \\ f_0(t) - f_1(t - t_\text{res}) & \text{for}\; t_\text{res} \leq t \leq 2 t_\text{res} \end{cases} \end{align*} Parameters ---------- t : float Time. tres : float Time resolution (dead time). roots : array_like, shape (k,) areas : array_like, shape (k,) eigvals : array_like, shape (k,) Eigenvalues of -Q matrix. gama00, gama10, gama11 : lists of floats Coeficients for the exact open/shut time pdf. Returns ------- f : float """ if t < tres: f = 0 elif ((tres < t) and (t < (2 * tres))): f = qml.f0((t - tres), eigvals, gamma00) elif ((tres * 2) < t) and (t < (3 * tres)): f = (qml.f0((t - tres), eigvals, gamma00) - qml.f1( (t - 2 * tres), eigvals, gamma10, gamma11)) else: f = pdfs.expPDF(t - tres, -1 / roots, areas) return f