Optimization
pangadfs.optimize
¶
OptimizeDefault()
¶
Bases: OptimizeBase
Source code in pangadfs/base.py
optimize(ga, **kwargs)
¶
Creates initial pool
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ga
|
GeneticAlgorithm
|
the ga instance |
required |
**kwargs
|
keyword arguments for plugins |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict |
Dict[str, Any]
|
'population': np.ndarray, |
Dict[str, Any]
|
'fitness': np.ndarray, |
Dict[str, Any]
|
'best_lineup': pd.DataFrame, |
Dict[str, Any]
|
'best_score': float |
Source code in pangadfs/optimize.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
OptimizeMultilineup()
¶
Bases: OptimizeBase
Source code in pangadfs/base.py
optimize(ga, **kwargs)
¶
Optimizes for multiple diverse lineups
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ga
|
GeneticAlgorithm
|
the ga instance |
required |
**kwargs
|
keyword arguments for plugins |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict containing: |
Dict[str, Any]
|
'population': np.ndarray, |
Dict[str, Any]
|
'fitness': np.ndarray, |
Dict[str, Any]
|
'best_lineup': pd.DataFrame, # For backward compatibility |
Dict[str, Any]
|
'best_score': float, # For backward compatibility |
Dict[str, Any]
|
'lineups': List[pd.DataFrame], # Multiple lineups |
Dict[str, Any]
|
'scores': List[float], # Corresponding scores |
Dict[str, Any]
|
'diversity_metrics': Dict # Diversity statistics |
Source code in pangadfs/optimize.py
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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
OptimizeMultiOptimizerFieldOwnership¶
The OptimizeMultiOptimizerFieldOwnership
class is an advanced multi-optimizer that balances three key objectives:
- Score optimization: Prioritizes both the best-performing lineups and the overall quality of the entire lineup set.
- Diversity: Ensures that the generated lineups are different from each other, reducing overlap and increasing the chances of a unique lineup winning.
- Field ownership differentiation: Provides a strategic edge by considering the projected ownership of players in the field. This can be used to create contrarian lineups that avoid popular players or to leverage low-owned players with high upside.
Configuration¶
The behavior of the optimizer can be controlled through the ga_settings
in the context object.
Setting | Description | Default |
---|---|---|
target_lineups |
The number of lineups to generate. | 10 |
score_weight |
The weight to give to the score component of the fitness function. | 0.5 |
diversity_weight |
The weight to give to the diversity component of the fitness function. | 0.3 |
field_ownership_weight |
The weight to give to the field ownership component of the fitness function. | 0.2 |
field_ownership_strategy |
The strategy to use for field ownership differentiation. Can be contrarian , leverage , or balanced . |
'contrarian' |
ownership_column |
The name of the column in the player pool CSV that contains the ownership data. | 'ownership' |
top_k_focus |
The number of top lineups to prioritize in the score component. | min(10, target_lineups) |
Example¶
ctx = {
'ga_settings': {
'target_lineups': 20,
'score_weight': 0.5,
'diversity_weight': 0.3,
'field_ownership_weight': 0.2,
'field_ownership_strategy': 'contrarian',
'ownership_column': 'ownership',
'top_k_focus': 5,
# ... other GA settings
}
}
=======
# Optimize Reference
The optimize module provides different optimization strategies for lineup generation.
## Available Optimizers
### OptimizeDefault
The standard single-lineup optimizer that uses a genetic algorithm to find the best possible lineup.
**Use case**: When you need one optimal lineup.
**Key features**:
- Fast convergence to optimal solution
- Proven genetic algorithm implementation
- Suitable for most single-lineup scenarios
### OptimizeMultilineup
Advanced optimizer for generating multiple diverse lineups using a post-processing approach.
**Use case**: When you need multiple diverse lineups (50-150 lineups).
**Key features**:
- Quality-first approach: Runs standard GA first, then selects diverse lineups
- Aggressive diversity selection with configurable thresholds
- Scalable for large lineup sets
- Comprehensive diversity metrics
**Configuration parameters**:
- `target_lineups`: Number of lineups to generate (default: 1)
- `diversity_weight`: Weight for diversity vs quality (default: 0.2)
- `min_overlap_threshold`: Minimum diversity requirement (default: 0.4)
- `diversity_method`: 'jaccard' or 'hamming' similarity (default: 'jaccard')
**Example usage**:
```python
from pangadfs.optimize import OptimizeMultilineup
# Configure for multiple diverse lineups
ga_settings = {
'target_lineups': 100,
'diversity_weight': 0.25,
'min_overlap_threshold': 0.4,
'diversity_method': 'jaccard',
'population_size': 1000,
'n_generations': 150,
# ... other GA settings
}
optimizer = OptimizeMultilineup()
ga = GeneticAlgorithm(ctx={'ga_settings': ga_settings, ...}, optimize=optimizer)
results = ga.optimize()
# Access multiple lineups
lineups = results['lineups'] # List of DataFrames
scores = results['scores'] # List of scores
diversity_metrics = results['diversity_metrics'] # Diversity statistics
Removed Optimizers¶
The following optimizers have been removed to streamline the codebase:
OptimizeMultilineupSets
- Replaced by OptimizeMultilineup's superior post-processing approachOptimizePoolBased
- Removed due to complexity without clear benefitsOptimizeMultiObjective
- Removed as academic approach not suitable for practical use
API Reference¶
pangadfs.optimize
¶
OptimizeDefault()
¶
Bases: OptimizeBase
Source code in pangadfs/base.py
optimize(ga, **kwargs)
¶
Creates initial pool
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ga
|
GeneticAlgorithm
|
the ga instance |
required |
**kwargs
|
keyword arguments for plugins |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict |
Dict[str, Any]
|
'population': np.ndarray, |
Dict[str, Any]
|
'fitness': np.ndarray, |
Dict[str, Any]
|
'best_lineup': pd.DataFrame, |
Dict[str, Any]
|
'best_score': float |
Source code in pangadfs/optimize.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
OptimizeMultilineup()
¶
Bases: OptimizeBase
Source code in pangadfs/base.py
optimize(ga, **kwargs)
¶
Optimizes for multiple diverse lineups
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ga
|
GeneticAlgorithm
|
the ga instance |
required |
**kwargs
|
keyword arguments for plugins |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict containing: |
Dict[str, Any]
|
'population': np.ndarray, |
Dict[str, Any]
|
'fitness': np.ndarray, |
Dict[str, Any]
|
'best_lineup': pd.DataFrame, # For backward compatibility |
Dict[str, Any]
|
'best_score': float, # For backward compatibility |
Dict[str, Any]
|
'lineups': List[pd.DataFrame], # Multiple lineups |
Dict[str, Any]
|
'scores': List[float], # Corresponding scores |
Dict[str, Any]
|
'diversity_metrics': Dict # Diversity statistics |
Source code in pangadfs/optimize.py
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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|