API reference
iup
iup.CoverageData
Bases: Data
Source code in iup/__init__.py
iup.CumulativeCoverageData
Bases: CoverageData
Source code in iup/__init__.py
iup.CumulativeCoverageData.to_incident(groups)
Convert cumulative to incident coverage data.
Because the first report date for each group is often rollout, incident coverage on the first report date is 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
List[str,] | None
|
Names of the columns of grouping factors, or None. If |
required |
Returns:
| Type | Description |
|---|---|
IncidentCoverageData
|
Incident coverage on each date in the input cumulative coverage data. |
Source code in iup/__init__.py
iup.Data
Bases: DataFrame
Abstract class for observed data and forecast data.
Source code in iup/__init__.py
iup.Data.assert_in_schema(names_types)
Verify that columns of the expected types are present in the data frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names_types
|
dict[str, DataTypeClass]
|
Column names and types mapping. |
required |
Source code in iup/__init__.py
iup.IncidentCoverageData
Bases: CoverageData
Source code in iup/__init__.py
iup.IncidentCoverageData.to_cumulative(groups, prev_cumulative=None)
Convert incident to cumulative coverage data.
Cumulative sum of incident coverage gives the cumulative coverage. Optionally, additional cumulative coverage from before the start of the incident data may be provided. Even if no groups are specified, the data must at least be grouped by season.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
List[str,] | None
|
Names of the columns of grouping factors, or None. If |
required |
prev_cumulative
|
DataFrame | None
|
Cumulative coverage from before the start of the incident
data, for each group, or None. If |
None
|
Returns:
| Type | Description |
|---|---|
CumulativeCoverageData
|
Cumulative coverage on each date in the input incident coverage data. |
Source code in iup/__init__.py
iup.PointForecast
Bases: QuantileForecast
Class for forecast with point estimate A subclass when quantile is 50% For now, enforce the "quantile50" to be "estimate"
Source code in iup/__init__.py
iup.QuantileForecast
iup.SampleForecast
Bases: Data
Class for forecast with posterior distribution. Save for future.
Source code in iup/__init__.py
iup.models
iup.models.LPLModel
Bases: CoverageModel
Subclass of CoverageModel for a mixed Logistic Plus Linear model. For details, see the online docs.
Source code in iup/models.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
iup.models.LPLModel.__init__(data, forecast_date, params, quantiles, date_column='time_end')
Initialize with a seed and the model structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
CumulativeCoverageData
|
Cumulative coverage data for fitting and prediction. |
required |
forecast_date
|
date
|
Date to split fit and prediction data. |
required |
params
|
dict[str, Any]
|
All parameters including parameter names and values to specify prior distributions, Control parameters for MCMC fitting, and season start month and day |
required |
quantiles
|
list[float]
|
Posterior sample quantiles |
required |
date_column
|
str
|
Name of the date column in the data. Defaults to "time_end". |
'time_end'
|
Source code in iup/models.py
iup.models.LPLModel.fit()
Fit a mixed Logistic Plus Linear model on training data.
If grouping factors are specified, a hierarchical model will be built with group-specific parameters for the logistic maximum and linear slope, drawn from a shared distribution. Other parameters are non-hierarchical.
Uses the data, groups, model_params, and mcmc_params specified during initialization.
Returns:
| Type | Description |
|---|---|
Self
|
Self with the fitted model stored in the mcmc attribute. |
Source code in iup/models.py
iup.models.LPLModel.predict()
Make projections from a fit Logistic Plus Linear model.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Sample forecast data frame with predictions for dates after forecast_date. |
Source code in iup/models.py
iup.eval
iup.eval.eos_abs_diff(obs, pred, grouping_factors)
Calculate the absolute difference between observed data and prediction for the last date in a season.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
DataFrame | LazyFrame
|
Observed data. |
required |
pred
|
DataFrame | LazyFrame
|
Predicted data. |
required |
grouping_factors
|
List[str]
|
Grouping factor column names (must include 'season'). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Data frame with absolute difference scores for end-of-season dates. |
Source code in iup/eval.py
iup.eval.mspe(obs, pred, grouping_factors)
Mean square prediction error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
DataFrame | LazyFrame
|
Data frame with columns |
required |
pred
|
DataFrame | LazyFrame
|
Data frame columns |
required |
grouping_factors
|
List[str]
|
Grouping factor column names. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Data frame with scores. |
Source code in iup/eval.py
iup.utils
iup.utils.date_to_season(date, season_start_month, season_start_day=1)
Extract the overwinter disease season from a date.
Dates in year Y before the season start (e.g., Sep 1) are in the second part of the season (i.e., in season Y-1/Y). Dates in year Y after the season start are in season Y/Y+1. E.g., 2023-10-07 and 2024-04-18 are both in "2023/2024".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Expr
|
Dates in an coverage data frame. |
required |
season_start_month
|
int
|
First month of the overwinter disease season. |
required |
season_start_day
|
int
|
First day of the first month of the overwinter disease season. |
1
|
Returns:
| Type | Description |
|---|---|
Expr
|
Seasons for each date. |