Exemple #1
0
def step(context, name, start, end): 
  from numpy import abs, any, dot
  from dcprogs.likelihood import expm
  times = context.times
  times = times[times < end] 
  times = times[times > start]
  for exact, missed_events_G, qmatrix in zip(context.exact_survivors,
                                             context.likelihoods,
                                             context.qmatrices):
    if missed_events_G is None: continue
    tau = missed_events_G.tau
    if name == "af": factor = dot(qmatrix.af, expm(tau * qmatrix.ff))
    else: factor = dot(qmatrix.fa, expm(tau * qmatrix.aa))
    for t in times:
      try: 
        value = getattr(missed_events_G, name)(t)
        check = dot(getattr(exact, name)(t-tau), factor)
        assert any(abs(value - check) < context.tolerance)
      except:
        print(missed_events_G)
        print("  * tmax: {0}".format(missed_events_G.tmax))
        print("{name}({t}*tau): \n{value}".format(name=name, t=t/tau, value=value))
        print("exact.af({t}*tau) * factor: \n{value}".format(name=name, t=(t-tau)/tau, value=check))
        print("factor:\n{factor}".format(factor=factor))
        raise AssertionError()
Exemple #2
0
def step(context, name, start):
    from numpy import abs, any, dot
    from dcprogs.likelihood import expm
    times = context.times
    times = times[times > start]
    for approx, missed_events_G, qmatrix in zip(context.approx_survivors,
                                                context.likelihoods,
                                                context.qmatrices):
        if missed_events_G is None: continue
        tau = missed_events_G.tau
        if name == "af": factor = dot(qmatrix.af, expm(tau * qmatrix.ff))
        else: factor = dot(qmatrix.fa, expm(tau * qmatrix.aa))
        for t in times:
            try:
                value = getattr(missed_events_G, name)(t)
                check = dot(getattr(approx, name)(t - tau), factor)
                assert any(abs(value - check) < context.tolerance)
            except:
                print(missed_events_G)
                print("  * tmax: {0}".format(missed_events_G.tmax))
                print("{name}({t}*tau): \n{value}".format(name=name,
                                                          t=t / tau,
                                                          value=value))
                print("approx.{name}({t}*tau) * factor: \n{value}"\
                      .format(name=name, t=(t-tau)/tau, value=check))
                print("factor:\n{factor}".format(factor=factor))
                raise
Exemple #3
0
def step(context):
  from numpy import abs, all, dot
  from dcprogs.likelihood import expm
  for idealg, matrix in zip(context.idealgs, context.qmatrices):
    for t in context.times:
      value = dot(expm(t * matrix.ff), matrix.fa)
      try: assert all(abs(idealg.fa(t) - value) < context.tolerance)
      except:
        print(matrix)
        print(t)
        raise
Exemple #4
0
def step(context):
    from numpy import abs, all, dot
    from dcprogs.likelihood import expm
    for idealg, matrix in zip(context.idealgs, context.qmatrices):
        for t in context.times:
            value = dot(expm(t * matrix.ff), matrix.fa)
            try:
                assert all(abs(idealg.fa(t) - value) < context.tolerance)
            except:
                print(matrix)
                print(t)
                raise
Exemple #5
0
def compute_Hfa(qmatrix, tau, tcrit):
  from dcprogs.likelihood import ApproxSurvivor
  from dcprogs.likelihood import expm
  from numpy import exp, dot

  approx = ApproxSurvivor(qmatrix, tau)
  result = None
  # This sums ^{F}R_i tau_i e^(-(tcrit - tau) / tau_i )
  for matrix, root in approx.fa_components: 
    if result is None: result = -matrix / root * exp( root * (tcrit - tau) )
    else: result += -matrix / root * exp( root * (tcrit - tau) )
  # multiply by Q_{FA} e^{Q_AA} 
  return dot(result, dot(qmatrix.fa, expm(tau * qmatrix.aa)))
Exemple #6
0
def compute_Hfa(qmatrix, tau, tcrit):
    from dcprogs.likelihood import ApproxSurvivor
    from dcprogs.likelihood import expm
    from numpy import exp, dot

    approx = ApproxSurvivor(qmatrix, tau)
    result = None
    # This sums ^{F}R_i tau_i e^(-(tcrit - tau) / tau_i )
    for matrix, root in approx.fa_components:
        if result is None: result = -matrix / root * exp(root * (tcrit - tau))
        else: result += -matrix / root * exp(root * (tcrit - tau))
    # multiply by Q_{FA} e^{Q_AA}
    return dot(result, dot(qmatrix.fa, expm(tau * qmatrix.aa)))
Exemple #7
0
from numpy import dot, identity, abs, all
from dcprogs.likelihood import QMatrix, IdealG, expm

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)

idealG = IdealG(qmatrix)
print(idealG)

idealG_fa = dot(expm(2e-4 * qmatrix.ff), qmatrix.fa)
assert all( abs(idealG_fa - idealG.fa(2e-4)) < 1e-8 )

inversion = -0.5 * identity(2) - qmatrix.aa
assert all( abs( dot(inversion, idealG.laplace_af(-0.5)) - qmatrix.af ) < 1e-8 )
Exemple #8
0
from numpy import dot, identity, abs, all
from dcprogs.likelihood import QMatrix, IdealG, expm

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)

idealG = IdealG(qmatrix)
print(idealG)

idealG_fa = dot(expm(2e-4 * qmatrix.ff), qmatrix.fa)
assert all(abs(idealG_fa - idealG.fa(2e-4)) < 1e-8)

inversion = -0.5 * identity(2) - qmatrix.aa
assert all(abs(dot(inversion, idealG.laplace_af(-0.5)) - qmatrix.af) < 1e-8)