IOptimization
Bases: ABC
The IOptimization
interface serves as a base for all optimization classes to inherit from.
It encompasses the following principles:
- It provides fundamental functionalities shared by all optimizations.
- Non-abstract methods and properties are generally not meant to be overridden.
- Methods and properties marked as 'final' should not be overridden.
- Strict adherence to data types is expected.
- The batch input and output dataclass types are primarily for typing purposes and can accommodate various data types. However, it's essential to have the specified required arguments available.
Source code in wt_ml/optimizer/base/optimizer_base.py
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 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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
add_loss(name, loss)
Add the following loss function for tracking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the loss function. |
required |
loss |
CalculatedMetric
|
The loss function that will be evaluated. |
required |
Source code in wt_ml/optimizer/base/optimizer_base.py
365 366 367 368 369 370 371 372 |
|
add_metric(name, metric)
Add the following metric function for tracking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the metric function. |
required |
metric |
CalculatedMetric
|
The metric function that will be evaluated. |
required |
Source code in wt_ml/optimizer/base/optimizer_base.py
374 375 376 377 378 379 380 381 |
|
all_losses(batch)
Returns a dict of all losses. This property can be overriden if you have a custom dict of losses you track.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
OptimizationInput
|
Optimization input that contains |
required |
Returns:
Type | Description |
---|---|
dict[str, float]
|
dict[str, CalculatedMetric]: Dict of computed losses. |
Source code in wt_ml/optimizer/base/optimizer_base.py
383 384 385 386 387 388 389 390 391 392 |
|
all_metrics(batch)
Returns a dict of all metrics. This property can be overriden if you have a custom dict of metrics you track.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
OptimizationInput
|
Optimization input that contains |
required |
Returns:
Type | Description |
---|---|
dict[str, float]
|
dict[str, CalculatedMetric]: Dict of computed metrics. |
Source code in wt_ml/optimizer/base/optimizer_base.py
394 395 396 397 398 399 400 401 402 403 |
|
constraints()
Returns list of constraints used for optimization.
Source code in wt_ml/optimizer/base/optimizer_base.py
223 224 225 |
|
create_result(location_type, dataset_factory, encodings, return_dataframe=True)
Returns results of current optimized state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_type |
str
|
The location type ("wholesaler", "state", "region") the results should be in. |
required |
dataset_factory |
DatasetFactory
|
A generator that returns |
required |
encodings |
dict[str, Any]
|
Encodings to decode the values in dataset. |
required |
return_dataframe |
bool
|
Return a dataframe instead of dict. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
dict[str, dict[tuple[str, ...], dict[str, float]]] | DataFrame
|
dict[str, dict[tuple[str], dict[str, float]]] | pd.DataFrame: The results of the current state of optimizer.
If |
Source code in wt_ml/optimizer/base/optimizer_base.py
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 |
|
get_constraints()
Function to apply and gather all the constraints.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Stacked constraints applied on vehicle_spends. |
Source code in wt_ml/optimizer/base/optimizer_base.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
hyperparameters()
Hyperparameters used.
Source code in wt_ml/optimizer/base/optimizer_base.py
227 228 229 |
|
optimize(dataset_factory, epochs, **_kwargs)
abstractmethod
Optimize for the given number of epochs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_factory |
DatasetFactory
|
A generator that returns |
required |
epochs |
int
|
Number of epochs to optimize. |
required |
Source code in wt_ml/optimizer/base/optimizer_base.py
252 253 254 255 256 257 258 259 |
|
simulate(batch)
abstractmethod
For the given batch
input simulate the impacts received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
OptimizationInput
|
Optimization input that contains |
required |
Returns:
Type | Description |
---|---|
Type[OptimizationOutput]
|
Type[OptimizationOutput]: The impacts for the given investment amounts. |
Source code in wt_ml/optimizer/base/optimizer_base.py
238 239 240 241 242 243 244 245 246 247 |
|
vehicle_spends()
The vehicle investments variable which is being optimized. Investment amounts for each batch (location*product), time and vehicle.
Source code in wt_ml/optimizer/base/optimizer_base.py
231 232 233 234 235 236 |
|
OptimizationInput
dataclass
Bases: ABC
This is an abstract OptimizationInput class that is mainly used for typing. It is not mandatory that your Input must be a dataclass. It can be a NamedTuple or any other class that resembles a dataclass. Only ensure that the following attributes below exists.
Source code in wt_ml/optimizer/base/optimizer_base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
OptimizationOutput
dataclass
Bases: ABC
This is an abstract OptimizationOutput class that is mainly used for typing. It is not mandatory that your Output must be a dataclass. It can be a NamedTuple or any other class that resembles a dataclass. Only ensure that the following attributes below exists.
Source code in wt_ml/optimizer/base/optimizer_base.py
116 117 118 119 120 121 122 123 124 125 126 127 128 |
|