Mixer
influpaint.datasets.mixer
dataset_mixer.py - Epidemic Data Augmentation and Frame Construction
Combines multiple epidemic surveillance datasets into a unified training corpus for diffusion models. Addresses common challenges in epidemic modeling:
- Dataset Rebalancing: Uses multipliers to weight data sources
- Temporal Completeness: Ensures all frames have complete weekly coverage (1-53)
- Spatial Completeness: Fills missing location-season combinations
- Gap Handling: Fills missing weeks and locations
- Peak Scaling: Scales epidemic curves to target peak intensities
Key Components:
- Multiplier Calculation: Compute dataset weights for target proportions
- Frame Construction: Build complete epidemic frames for training
- Gap Filling: Handle missing data intelligently
- Peak Scaling: Scale frames to realistic epidemic intensities
Typical Usage:
Step 1: Combine datasets into hierarchical structure
all_datasets_df = pd.concat([fluview_df, nc_df, smh_traj_df])
Step 2: Configure dataset inclusion, weighting, and scaling
config = { "fluview": {"proportion": 0.7, "total": 1000, "to_scale": True}, # 70% + scaling "smh_traj": {"proportion": 0.3, "total": 1000, "to_scale": False} # 30% + no scaling }
Step 3: Define scaling distribution for peak intensities
scaling_dist = np.array([1000, 2000, 3000, 5000, 8000, 12000]) # US peak values
Step 4: Build complete frames with configurable location handling and scaling
frames = build_frames(all_datasets_df, config, season_axis, fill_missing_locations="zeros", scaling_distribution=scaling_dist)
Alternative: Use explicit multipliers instead of proportions
config = { "fluview": {"multiplier": 2, "to_scale": True}, # Include twice + scaling "smh_traj": {"multiplier": 1, "to_scale": False} # Include once + no scaling } frames = build_frames(all_datasets_df, config, season_axis, scaling_distribution=scaling_dist)
Peak Scaling:
When "to_scale": True is specified for a dataset: - Each frame gets independently scaled to a random peak from scaling_distribution - Scaling preserves epidemic curve shape while adjusting intensity - US peak = max(weekly_sum_across_all_locations) is used as scaling reference - Origin tracking includes scaling target: "[scaled_to_X.X]" - Provides realistic intensity variation for training data augmentation
Output Format:
Each frame is a complete epidemic season with:
- All weeks (1-53) represented
- All locations covered
- Consistent data structure for array conversion
- Optional peak scaling applied
- Full provenance tracking in 'origin' column
Enables training on heterogeneous surveillance data while maintaining epidemiological structure and realistic intensity distributions.
build_frames(all_datasets_df, config, season_axis, fill_missing_locations='error', scaling_distribution=None)
Build complete epidemic frames from hierarchical dataset structure.
Handles 4-level hierarchy: H1 → H2 → Season → Sample and creates complete frames while preserving dataset origins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_datasets_df
|
DataFrame
|
Combined dataset with required columns:
- datasetH1: Top-level dataset category (e.g., 'fluview', 'smh_traj') |
required |
config
|
dict
|
Configuration for dataset inclusion and weighting: - Keys: H1 dataset names (must exist in datasetH1 column) - Values: Either {"multiplier": int} or {"proportion": float, "total": int} - Optional: {"to_scale": bool} to enable frame scaling |
required |
season_axis
|
SeasonAxis
|
Season axis object providing location definitions |
required |
fill_missing_locations
|
str
|
Strategy for handling missing locations: - "error": Fail if any expected location is missing (default) - "zeros": Fill missing locations with zeros - "random": Fill missing locations with random other season data - "skip": Skip frames with missing locations |
'error'
|
scaling_distribution
|
ndarray
|
Array of values to draw from for scaling. Required if any dataset in config has "to_scale": True |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Complete epidemic frames, where each frame contains: - All weeks (1-53) for all expected locations (based on season_axis) - Origin column tracking source: "H1/H2/season/sample" - Replicated datasets as specified by config |
Example
config = { "fluview": {"multiplier": 1, "to_scale": True}, "smh_traj": {"proportion": 0.7, "total": 1000, "to_scale": False} } scaling_dist = np.array([1000, 2000, 3000, 5000, 8000]) # Peak values to scale to frames = build_frames(all_datasets_df, config, season_axis, fill_missing_locations="zeros", scaling_distribution=scaling_dist)
Notes
- If H1 dataset is included, ALL H2s and seasons within it are included
- Minimum frames = sum(n_H2 * n_seasons) for each included H1
- Samples are replicated, not created (e.g., sample_1_copy1, sample_1_copy2)
- Location completeness is enforced based on season_axis.locations
Source code in influpaint/datasets/mixer.py
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 | |