Пример #1
0
def eG(string):
    """ Creates missed-events likelihood from specific strings """
    from dcprogs.likelihood import MissedEventsG
    string = string.lower().rstrip().lstrip()
    if 'transpose' in string:
        return eG(string.replace('transpose', '')).transpose()

    if string == "classic": return MissedEventsG(QMat(string), 1e-4)
    if string == "ch82": return MissedEventsG(QMat(string), 0.2)
    if string == "cb": return MissedEventsG(QMat(string), 0.2)
    if string == "cks": return MissedEventsG(QMat(string), 0.2)
    else: raise Exception("Unknown eG model {0}".format(string))
Пример #2
0
def step(context, n, tau, nmax):
    from dcprogs.likelihood.random import qmatrix as random_qmatrix
    from dcprogs.likelihood import MissedEventsG
    qmatrices, Gs, i = [], [], 10 * n
    while len(Gs) != n:
        i -= 1
        if i == 0:
            raise AssertionError('Could not instanciate enough likelihoods.')
        qmatrix = random_qmatrix()
        G = MissedEventsG(qmatrix, tau, nmax)
        try:
            G = MissedEventsG(qmatrix, tau, nmax)
        except:
            continue
        else:
            Gs.append(G)
            qmatrices.append(qmatrix)
    if not hasattr(context, 'qmatrices'): context.qmatrices = []
    if not hasattr(context, 'likelihoods'): context.likelihoods = []
    context.qmatrices.extend(qmatrices)
    context.likelihoods.extend(Gs)
Пример #3
0
def step(context, tau, nmax):
    from dcprogs.likelihood import MissedEventsG
    if not hasattr(context, "likelihoods"): context.likelihoods = []
    for i, qmatrix in enumerate(context.qmatrices):
        if qmatrix is None:
            context.likelihoods.append(None)
            continue
        try:
            context.likelihoods.append(MissedEventsG(qmatrix, tau, nmax))
        except ArithmeticError:
            context.likelihoods.append(None)
            context.qmatrices[i] = None
            continue
        except:
            print(qmatrix)
            raise
Пример #4
0
from numpy import all, abs, arange
from dcprogs.likelihood import QMatrix, DeterminantEq, MissedEventsG

# Define parameters.
qmatrix = QMatrix([ [-3050,        50,  3000,      0,    0], 
                    [2./3., -1502./3.,     0,    500,    0], 
                    [   15,         0, -2065,     50, 2000], 
                    [    0,     15000,  4000, -19000,    0], 
                    [    0,         0,    10,      0,  -10] ], 2)
tau = 1e-4
 
# Create eG from prior knowledge of roots
determinant_eq = DeterminantEq(qmatrix, tau)
af_roots = [( -3045.285776037674, 1), (-162.92946543451328, 1)]
fa_roots = [(-17090.192769236815, 1), (-2058.0812921673496, 1), (-0.24356535498785126, 1)]
eG_from_roots = MissedEventsG(determinant_eq, af_roots, determinant_eq.transpose(), fa_roots)

# Create eG automaticallye
eG_automatic = MissedEventsG(qmatrix, tau)

# Checks the three initialization are equivalent at tau
assert all(abs(eG_from_roots.af(tau) - eG_automatic.af(tau)) < 1e-8)
assert all(abs(eG_from_roots.fa(tau) - eG_automatic.fa(tau)) < 1e-8)

# Checks the three initialization are equivalent at different times
# The functions can be applied to arrays. 
times = arange(tau, 10*tau, 0.1*tau)
assert eG_from_roots.af(times).shape == (len(times), 2, 3)
assert eG_from_roots.fa(times).shape == (len(times), 3, 2)
assert all(abs(eG_from_roots.af(times) - eG_automatic.af(times)) < 1e-8)
assert all(abs(eG_from_roots.fa(times) - eG_automatic.fa(times)) < 1e-8)
Пример #5
0
from dcprogs.likelihood import QMatrix, IdealG, MissedEventsG

# Define parameters.
qmatrix = QMatrix([ [-3050,        50,  3000,      0,    0], 
                    [2./3., -1502./3.,     0,    500,    0], 
                    [   15,         0, -2065,     50, 2000], 
                    [    0,     15000,  4000, -19000,    0], 
                    [    0,         0,    10,      0,  -10] ], 2)
tau = 1e-4
 
eG = MissedEventsG(qmatrix, tau)
idealG = IdealG(qmatrix)

tcritical = 5e-3

print("Equilibrium Occupancies\n"            \
      "=======================\n\n"          \
      "Ideal Likelihood\n"                   \
      "----------------\n\n"                 \
      "  * initial: {ideal_initial!r}\n"     \
      "  * final: {ideal_final!r}\n\n\n"     \
      "Missed-events Likelihood\n"           \
      "------------------------\n\n"         \
      "  * initial: {equi_initial!r}\n"      \
      "  * final: {equi_final!r}\n\n\n\n"    \
      "CHS Occupancies\n"                    \
      "===============\n\n"                  \
      "Missed-events Likelihood\n"           \
      "------------------------\n\n"         \
      "  * tcritical: {tcritical}\n"         \
      "  * initial: {chs_initial!r}\n"       \
Пример #6
0
from numpy import all, abs, arange
from dcprogs.likelihood import QMatrix, DeterminantEq, MissedEventsG

# Define parameters.
qmatrix = QMatrix([[-3050, 50, 3000, 0, 0], [2. / 3., -1502. / 3., 0, 500, 0],
                   [15, 0, -2065, 50, 2000], [0, 15000, 4000, -19000, 0],
                   [0, 0, 10, 0, -10]], 2)
tau = 1e-4

# Create eG from prior knowledge of roots
determinant_eq = DeterminantEq(qmatrix, tau)
af_roots = [(-3045.285776037674, 1), (-162.92946543451328, 1)]
fa_roots = [(-17090.192769236815, 1), (-2058.0812921673496, 1),
            (-0.24356535498785126, 1)]
eG_from_roots = MissedEventsG(determinant_eq, af_roots,
                              determinant_eq.transpose(), fa_roots)

# Create eG automaticallye
eG_automatic = MissedEventsG(qmatrix, tau)

# Checks the three initialization are equivalent at tau
assert all(abs(eG_from_roots.af(tau) - eG_automatic.af(tau)) < 1e-8)
assert all(abs(eG_from_roots.fa(tau) - eG_automatic.fa(tau)) < 1e-8)

# Checks the three initialization are equivalent at different times
# The functions can be applied to arrays.
times = arange(tau, 10 * tau, 0.1 * tau)
assert eG_from_roots.af(times).shape == (len(times), 2, 3)
assert eG_from_roots.fa(times).shape == (len(times), 3, 2)
assert all(abs(eG_from_roots.af(times) - eG_automatic.af(times)) < 1e-8)
assert all(abs(eG_from_roots.fa(times) - eG_automatic.fa(times)) < 1e-8)