Skip to content

Commit e4b3cb3

Browse files
committed
just do it all at once
1 parent 2296d27 commit e4b3cb3

File tree

1 file changed

+21
-42
lines changed

1 file changed

+21
-42
lines changed

ngm/__init__.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,38 @@
1+
from collections import namedtuple
2+
13
import numpy as np
24

5+
NgmSummary = namedtuple(
6+
"NgmSummary", ["r_eff", "infectious_dist", "outcome_dist"]
7+
)
8+
39

410
class CoreGroupNgm:
511
def __init__(
612
self,
7-
num_groups: int,
813
r0_matrix: np.ndarray,
914
# Other parameters go here
1015
):
11-
self.k = self.make_k(num_groups, r0_matrix)
16+
assert (
17+
len(r0_matrix) == 2 and r0_matrix.shape[0] == r0_matrix.shape[1]
18+
), "r0_matrix must be square 2-D matrix"
19+
self.k = self.make_k(r0_matrix)
1220
# Other parameters get stored here
1321
raise NotImplementedError()
1422

15-
def make_k(self, num_groups: int, r0_matrix: np.ndarray):
23+
def make_k(self, r0_matrix: np.ndarray):
1624
raise NotImplementedError()
1725

18-
def calculate_r_eff(self) -> float:
19-
r"""
20-
Compute $R_e$
21-
22-
Returns
23-
-------
24-
float
25-
$R_e$ via the spectral radius of the next generation matrix
26-
"""
27-
# Could consider caching eigenvalues/vectors, but always re-computing feels safer
28-
eval = np.linalg.eig(self.k).eigenvalues
29-
# eval at index (via argmax) of maximum absolute value
30-
# @TODO: do we need to check for imaginary components?
31-
return eval[np.argmax(np.abs(eval))]
32-
33-
def calculate_infectious_distribution(self) -> np.ndarray:
34-
r"""
35-
Compute distribution of infections
36-
37-
Returns
38-
-------
39-
np.ndarray
40-
The PMF on infections, I think?
41-
"""
42-
# evec = np.linalg.eig(self.k).eigenvectors
43-
raise NotImplementedError()
26+
def summarize(self) -> NgmSummary:
27+
raise NotImplementedError
4428

45-
def calculate_severe_outcomes(self, inf_dist: np.ndarray):
46-
r"""
47-
Compute distribution of severe outcomes from the distribution of infections
29+
# eigendecomp = np.linalg.eig(self.k)
4830

49-
Parameters
50-
----------
51-
inf_dist : np.ndarray
52-
Output of self.calculate_infectious_distribution()
31+
# # Index of dominant eigenvalue determines r_eff and infectious distribution
32+
# dom = np.argmax(np.abs(eigendecomp.eigenvalues))
5333

54-
Returns
55-
-------
56-
np.ndarray
57-
The PMF on severe outcomes, I think?
58-
"""
59-
raise NotImplementedError()
34+
# return NgmSummary(
35+
# r_eff=eigendecomp.eigenvalues[dom],
36+
# infectious_dist=None, #TBD: is this just eigendecomp.eigenvectors[dom] / eigendecomp.eigenvectors[dom].sum()?
37+
# outcome_dist=None, #TBD
38+
# )

0 commit comments

Comments
 (0)