|
51 | 51 | # third party |
52 | 52 | import mysql.connector |
53 | 53 | import numpy as np |
| 54 | +from warnings import warn |
54 | 55 |
|
55 | 56 | # first party |
56 | 57 | import delphi.operations.secrets as secrets |
57 | 58 | from delphi.utils.epiweek import delta_epiweeks |
58 | 59 | from delphi.utils.geo.locations import Locations |
59 | 60 |
|
60 | 61 |
|
| 62 | +UNDERDETERMINED_MSG = "system is underdetermined" |
| 63 | + |
61 | 64 | class Database: |
62 | 65 | """Database wrapper and abstraction layer.""" |
63 | 66 |
|
@@ -107,14 +110,7 @@ class Sql: |
107 | 110 | # epiweek. |
108 | 111 | get_known_values = """ |
109 | 112 | SELECT |
110 | | - `region`, `num_ili`, `num_patients`, `num_providers`, |
111 | | - -- TODO |
112 | | - -- `num_age_0`, |
113 | | - -- `num_age_1`, |
114 | | - -- `num_age_2`, |
115 | | - -- `num_age_3`, |
116 | | - -- `num_age_4`, |
117 | | - -- `num_age_5` |
| 113 | + `region`, `num_ili`, `num_patients`, `num_providers` |
118 | 114 | FROM |
119 | 115 | `fluview` |
120 | 116 | WHERE |
@@ -181,24 +177,8 @@ def get_known_values(self, issue, epiweek): |
181 | 177 |
|
182 | 178 | self.cur.execute(Database.Sql.get_known_values, (issue, epiweek)) |
183 | 179 | return { |
184 | | - loc: (n_ili, n_pat, n_prov, |
185 | | - ## TODO |
186 | | - # num_age_0, |
187 | | - # num_age_1, |
188 | | - # num_age_2, |
189 | | - # num_age_3, |
190 | | - # num_age_4, |
191 | | - # num_age_5, |
192 | | - ) |
193 | | - for (loc, n_ili, n_pat, n_prov, |
194 | | - ## TODO |
195 | | - # num_age_0, |
196 | | - # num_age_1, |
197 | | - # num_age_2, |
198 | | - # num_age_3, |
199 | | - # num_age_4, |
200 | | - # num_age_5, |
201 | | - ) |
| 180 | + loc: (n_ili, n_pat, n_prov,) |
| 181 | + for (loc, n_ili, n_pat, n_prov,) |
202 | 182 | in self.cur |
203 | 183 | } |
204 | 184 |
|
@@ -267,7 +247,7 @@ def get_fusion_parameters(known_locations): |
267 | 247 | H = graph[is_known, :] |
268 | 248 | W = graph[is_unknown, :] |
269 | 249 | if np.linalg.matrix_rank(H) != len(atoms): |
270 | | - raise StatespaceException("system is underdetermined") |
| 250 | + raise StatespaceException(UNDERDETERMINED_MSG) |
271 | 251 |
|
272 | 252 | HtH = np.dot(H.T, H) |
273 | 253 | HtH_inv = np.linalg.inv(HtH) |
@@ -320,7 +300,15 @@ def impute_missing_values(database, test_mode=False): |
320 | 300 | known_values["pr"] = (0, 0, 0) |
321 | 301 |
|
322 | 302 | # get the imputation matrix and lists of known and unknown locations |
323 | | - F, known, unknown = get_fusion_parameters(known_values.keys()) |
| 303 | + try: |
| 304 | + F, known, unknown = get_fusion_parameters(known_values.keys()) |
| 305 | + except StatespaceException as e: |
| 306 | + message = str(e) |
| 307 | + if message == UNDERDETERMINED_MSG: |
| 308 | + warn(message) |
| 309 | + else: |
| 310 | + print(message) |
| 311 | + continue |
324 | 312 |
|
325 | 313 | # finally, impute the missing values |
326 | 314 | z = np.array([known_values[k] for k in known]) |
|
0 commit comments