|
| 1 | +from collections import namedtuple |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 |
|
| 5 | +NgmSummary = namedtuple( |
| 6 | + "NgmSummary", ["r_eff", "infectious_dist", "outcome_dist"] |
| 7 | +) |
| 8 | + |
3 | 9 |
|
4 | 10 | class CoreGroupNgm:
|
5 | 11 | def __init__(
|
6 | 12 | self,
|
7 |
| - num_groups: int, |
8 | 13 | r0_matrix: np.ndarray,
|
9 | 14 | # Other parameters go here
|
10 | 15 | ):
|
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) |
12 | 20 | # Other parameters get stored here
|
13 | 21 | raise NotImplementedError()
|
14 | 22 |
|
15 |
| - def make_k(self, num_groups: int, r0_matrix: np.ndarray): |
| 23 | + def make_k(self, r0_matrix: np.ndarray): |
16 | 24 | raise NotImplementedError()
|
17 | 25 |
|
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 |
44 | 28 |
|
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) |
48 | 30 |
|
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)) |
53 | 33 |
|
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