double_gameweek
double_gameweek
¶
Double Gameweek (DGW) detection, timeseries aggregation, and prediction scaling.
A Double Gameweek occurs when a team plays two Premier League fixtures in the same FPL gameweek. From the perspective of the inference pipeline and optimizer, this has two distinct effects:
-
Historical timeseries (training/inference input) The vaastav dataset stores each fixture as a separate row. A DGW player therefore has two rows sharing the same
gameweekvalue. If not aggregated, the HMM will see them as two sequential timesteps with single-game-calibrated emissions, causing the model to misinterpret a large total (e.g. 14 pts from two good games) as a single "Star" observation when it is actually two "Good" observations. -
Forward prediction (next-GW forecast for ILP) When the upcoming gameweek is a DGW, a player plays twice. Their expected FPL points should be approximately 2× the single-game prediction (under independence), and their variance should also scale accordingly.
Usage
from fplx.data.double_gameweek import ( ... detect_dgw_gameweeks, ... aggregate_dgw_timeseries, ... scale_predictions_for_dgw, ... get_fixture_counts_from_bootstrap, ... )
detect_dgw_gameweeks
¶
Return a mapping of {gameweek: n_fixtures} for a single player's timeseries.
A gameweek with n_fixtures > 1 is a Double (or Triple) Gameweek.
| PARAMETER | DESCRIPTION |
|---|---|
timeseries
|
Per-fixture timeseries as returned by
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[int, int]
|
|
Examples:
>>> counts = detect_dgw_gameweeks(player.timeseries)
>>> dgw_gws = [gw for gw, n in counts.items() if n > 1]
Source code in fplx/data/double_gameweek.py
aggregate_dgw_timeseries
¶
Collapse per-fixture rows into one normalised row per gameweek.
This is the single place where Double Gameweek handling lives. All downstream consumers (inference pipeline, enriched predictor, MV-HMM, Kalman Filter) always receive exactly one row per FPL decision period and never need to be aware of DGWs.
For a DGW gameweek (n_fixtures == 2):
- Additive stats (goals, minutes, bonus, …) are summed to reflect the total accumulated across both matches.
- Per-fixture normalisation is applied to
pointsand to every additive stat that forms an inference feature. The normalised column is stored alongside the raw total:
.. code-block:: text
points # raw total (used for scoring / oracle)
points_norm # per-fixture average (used by inference / HMM)
The HMM emission distributions are calibrated on points_norm, so a
DGW observation of 10 total points (points_norm = 5) is correctly
interpreted as an "Average" game rather than misidentified as a "Star"
event (8.5 pts single-game emission mean).
-
Rate / expected stats (xG, xA, …) are averaged — they already represent per-match rates.
-
Context columns (price, opponent) take the last-fixture value.
For a single-fixture gameweek (n_fixtures == 1) the row is returned
unchanged and points_norm == points.
| PARAMETER | DESCRIPTION |
|---|---|
timeseries
|
Raw per-fixture timeseries (may contain duplicate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
One row per gameweek, sorted ascending by |
Source code in fplx/data/double_gameweek.py
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 | |
scale_predictions_for_dgw
¶
scale_predictions_for_dgw(
expected_points: dict[int, float],
variances: dict[int, float],
downside_risks: dict[int, float],
fixture_counts: dict[int, int],
variance_mode: str = "additive",
) -> tuple[
dict[int, float], dict[int, float], dict[int, float]
]
Scale single-game predictions to account for a Double Gameweek.
For a player with n fixtures in the upcoming gameweek:
- Expected points:
E[P_total] = n * E[P_single] - Variance (additive, under independence):
Var[P_total] = n * Var[P_single] - Downside risk:
DR_total = sqrt(n) * DR_single
This is exact under independence of the two match performances. The independence assumption is acceptable because FPL points in different matches are only weakly correlated (shared clean sheet probability for the same game counts for both defenders, but that is captured in the single-game variance estimate).
| PARAMETER | DESCRIPTION |
|---|---|
expected_points
|
Single-game expected points per player id.
TYPE:
|
variances
|
Single-game predictive variance per player id.
TYPE:
|
downside_risks
|
Single-game semi-deviation per player id.
TYPE:
|
fixture_counts
|
Number of upcoming fixtures per player id (1 for SGW, 2 for DGW). Players absent from this dict are assumed to have 1 fixture.
TYPE:
|
variance_mode
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ep_scaled, var_scaled, dr_scaled : tuple of dicts
|
Scaled prediction dicts with the same keys as the inputs. |
Notes
Blank gameweek (BGW) players (n = 0) receive E[P] = 0,
Var[P] = 0.1, DR = 0. The optimizer will naturally exclude them
since their expected points are zero.
Examples:
>>> ep_scaled, var_scaled, dr_scaled = scale_predictions_for_dgw(
... expected_points, variances, downside_risks, fixture_counts
... )
Source code in fplx/data/double_gameweek.py
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 | |
get_fixture_counts_from_bootstrap
¶
Derive per-player fixture counts for a gameweek from FPL bootstrap data.
Parses the fixtures list in the bootstrap-static response to count how
many fixtures each team plays in target_gw. Returns a player-level
mapping derived from each player's team id.
| PARAMETER | DESCRIPTION |
|---|---|
bootstrap
|
Full bootstrap-static API response containing
TYPE:
|
target_gw
|
The gameweek to inspect.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[int, int]
|
|
Source code in fplx/data/double_gameweek.py
get_fixture_counts_from_vaastav
¶
Derive per-player fixture counts for a historical gameweek from vaastav data.
Uses the merged_gw CSV to count how many rows each player has for
target_gw. This is the ground-truth fixture count for backtesting.
| PARAMETER | DESCRIPTION |
|---|---|
loader
|
An initialised loader instance.
TYPE:
|
target_gw
|
Gameweek to inspect.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[int, int]
|
|