In [1]:
%matplotlib notebook
In [2]:
import numpy as np
import matplotlib.pyplot as plt
In [3]:
from numpy import array
from dcprogs.likelihood import QMatrix, DeterminantEq, Asymptotes, find_roots, ExactSurvivor, \
ApproxSurvivor, ApproxSurvivor, MissedEventsG, \
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)
qmatrix = QMatrix([[ -1.639102438935231, 0.9279328542626132, 0, 0.7111695846726181, 0, 0, 0, 0, 0],
[ 7319.818837397022, -7319.818837397022, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, -0.5849255773178983, 0, 0, 0, 0.05800330713458401, 0.5269222701833143, 0],
[ 554.9144283943098, 0, 0, -556.415038972956, 0.670095369096168, 0.8305152095500998, 0, 0, 0],
[ 0, 0, 0, 4445.029004693305, -4445.029004693305, 0, 0, 0, 0],
[ 0, 0, 0, 0.7249830360634507, 0, -0.7855125406770954, 0, 0, 0.06052950461364481],
[ 0, 0, 0.4346782743227515, 0, 0, 0, -3554.307968015994, 0, 3553.873289741671],
[ 0, 0, 0.6916315120151144, 0, 0, 0, 0, -0.6916315120151144, 0],
[ 0, 0, 0, 0, 0, 5390.604449280132, 0.435406457067279, 0, -5391.039855737199]], 3)
transitions = qmatrix
tau = 1e-4
a = DeterminantEq(transitions, tau)
G = MissedEventsG(transitions, tau, 4)
approx = ApproxSurvivor(transitions, tau)
exact = ExactSurvivor(transitions, tau)
factor = np.dot(qmatrix.fa, expm(tau*qmatrix.aa))
#print factor
print(G.fa(tau * 1.31838319649))
print(np.dot(exact.fa(tau * 1.31838319649-tau), factor))
In [4]:
from dcprogs.likelihood import network
from networkx import draw as nx_draw, draw_spectral
graph = network(qmatrix)
nx_draw(graph)
In [5]:
from numpy import outer
from dcprogs.likelihood import Asymptotes, DeterminantEq, eig, inv
eigenvalues, eigenvectors = eig(-qmatrix.matrix)
def get_ci00(i):
return outer(eigenvectors[:, i], inv(eigenvectors)[i, :])[:qmatrix.nopen, :qmatrix.nopen]
s = get_ci00(0)
for i in range(1, len(eigenvalues)):
# if abs(eigenvalues[i]) > 1e-8:
s += get_ci00(i)
print(s)
print(approx.af_components[0][0] + approx.af_components[1][0] + approx.af_components[2][0])
In [6]:
tau, i, j, n = 1e-4, 0, 0, 3
x = np.arange(tau, n * tau, tau / 10.)
fig, ax = plt.subplots(1,1)
ax.plot(x, np.dot(exact.af(x-tau), G.af_factor)[:, i, j], '.', label="exact")
ax.plot(x, np.dot(approx.af(x-tau), G.af_factor)[:, i, j], "-.", label="approx")
ax.plot(x, G.af(x)[:, i, j], '--', label="G")
ax.set_title("Component ${0}$ of the matrix $^{{e}}G_{{af}}$.".format((i, j)))
fig.tight_layout()
#legend()
#display(gcf())
print(G.tmax)
print(x)
In [7]:
from dcprogs.likelihood import DeterminantEq, find_lower_bound_for_roots, eig
a = DeterminantEq([[ -0.9765569699831389, 0, 0, 0, 0, 0, 0.9765569699831388, 0, 0],
[ 0, -21087.12668613774, 0, 0, 0, 4972.429427806393, 9423.400001111493, 0.7672868902249316, 6690.529970329637],
[ 0, 0, -0.02903705186960781, 0, 0.02903705186960781, 0, 0, 0, 0],
[ 0, 0, 0, -8967.619224739678, 0, 0, 0, 8967.455151523045, 0.1640732166323416],
[ 0, 0, 0.2978885248190503, 0, -0.4287224564347299, 0, 0, 0.1308339316156797, 0],
[ 0, 0.7275421797587975, 0, 0, 0, -1.19022223735187, 0, 0.102814653125226, 0.3598654044678464],
[ 0.1209377584689361, 0.05943271459974253, 0, 0, 0, 0, -0.1803704730686787, 0, 0],
[ 0, 0.8265398081401302, 0, 0.6009896070678163, 3588.624442956896, 0.7814141825061616, 0, -3590.83338655461, 0],
[ 0, 0.8191655510502869, 0, 8172.231231533744, 0, 7421.575697898968, 0, 0, -15594.62609498376]], 6, 1e-4)
print(eig(a.H(-126523))[0])
find_lower_bound_for_roots(a)
Out[7]:
In [ ]: