eso.ESO¶
The top-level orchestrator. Pass the path of a JSON settings file. Call run(). The data preparation, baseline training, evolution loop, and evaluation stages are all driven from inside this class.
A typical invocation looks like:
What run() does¶
The run() method is a thin wrapper that walks the full pipeline.
| Step | Method called | Description |
|---|---|---|
| 1 | _load_settings |
Validate the JSON against eso.utils.settings. |
| 2 | _setup_logging |
Configure file and TensorBoard loggers. |
| 3 | _prepare_data |
Build the preprocessed and unprocessed mel-spectrogram datasets. |
| 4 | _train_baseline |
Train the baseline CNN on the preprocessed dataset. Record its F1 and parameter count. |
| 5 | _initialise_population |
Create a random population of chromosomes. |
| 6 | optimize() |
Iterate max_generations of selection, mutation, crossover, and reproduction. |
| 7 | evaluate() |
Run sliding-window inference on the test set with the best chromosome. |
The methods marked as private (prefixed with _) are filtered out of the public reference below, but the public surface (run, optimize, evaluate) is documented in full.
Settings¶
ESO(settings_path=...) is the only required argument. The JSON file is parsed into the dataclass hierarchy in eso.utils.settings. See Configuration for every field.
Reference¶
ESO
¶
ESO(
settings,
stop_event=None,
logger=None,
population_file_path=None,
log_level=0,
log_path=None,
tensorboard_log_dir=None,
results_path="results",
progress_handler=None,
)
The main class for the ESO algorithm.
This class is responsible for training the baseline model and performing the genetic algorithm to find the optimal band positions and heights. The ESO class is initialized with a settings file. The settings file is a json file that contains all the parameters for the algorithm, or a dictionary containing the parameters. The settings file must contain the following parameters: - data: The parameters for the data - preprocessing: The parameters for the preprocessing - model: The parameters for the model - chromosome: The parameters for the chromosome - gene: The parameters for the gene - population: The parameters for the population - selection_operator: The parameters for the selection operator - genetic_operator: The parameters for the genetic operator - algorithm: The parameters for the algorithm
Check the documentation for the parameters of each class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
str or dict
|
The path to the settings file or a dictionary containing the parameters |
required |
stop_event
|
Event
|
The event to stop the algorithm, by default None. Used if run from the GUI. |
None
|
logger
|
Logger
|
The logger to use, by default None. If None, a logger is created. |
None
|
population_file_path
|
str
|
The path to the population file, by default None. If None, a new population is created. |
None
|
log_level
|
int
|
The log level to use, by default 0. Check the logging module for the different log levels. |
0
|
log_path
|
str
|
The path to the log file, by default None. If None, the log is not saved to a file. |
None
|
tensorboard_log_dir
|
str
|
The directory to log to tensorboard, by default None. If None, tensorboard is not used. |
None
|
results_path
|
str
|
The path to save the results, by default "results" |
'results'
|
progress_bar
|
tkinter progress bar
|
The progress bar to update, by default None. Only used if run from the GUI. |
required |
progress_bar_training
|
tkinter progress bar
|
The progress bar to update during training, by default None. Only used if run from the GUI. |
required |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the baseline.json file exists but could not be loaded. |
ValueError
|
If max_generations is not specified in the settings file or as an argument to the method |
ValueError
|
If the sum of mutation_rate, crossover_rate and reproduction_rate is not 1 |
ValueError
|
If the number of new chromosomes does not match the population size |
Examples:
>>> from eso import ESO
>>> eso = ESO(settings="settings.json")
>>> eso.opimize(max_generations=100)
Source code in eso/eso.py
logger
instance-attribute
¶
logger = setup_logger(logger=logger, log_path=log_path, log_level=log_level, name="eso")
evolution_logger
instance-attribute
¶
evolution_logger = setup_logger(
logger=None,
log_path=log_path,
log_level=log_level,
name="evolution",
add_stream_handler=False,
)
population_logger
instance-attribute
¶
population_logger = setup_logger(
logger=None,
log_path=log_path,
log_level=log_level,
name="population",
add_stream_handler=False,
)
run
¶
Source code in eso/eso.py
optimize
¶
Perform Genetic Algorithm to find optimal band positions and heights.
This method will first train the baseline model and then perform the genetic algorithm to find the optimal band positions and heights. At each epoch, the population is trained and then evolved. The best chromosome is logged to tensorboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_generations
|
int
|
The maximum number of generations to run the algorithm for, by default None |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_generations is not specified in the settings file or as an argument to the method |
ValueError
|
If the sum of mutation_rate, crossover_rate and reproduction_rate is not 1 |
ValueError
|
If the number of new chromosomes does not match the population size |
Source code in eso/eso.py
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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
evolve_population
¶
Evolve the population using the genetic operator and selection operator
Creates new chromosomes using the genetic operator and replaces the old population with the new one.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sum of mutation_rate, crossover_rate and reproduction_rate is not 1 |
ValueError
|
If the number of new chromosomes does not match the population size |
Source code in eso/eso.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
evaluate
¶
evaluate(
test_type="simple",
overlap=0.25,
nb_to_group=2,
threshold=0.8,
save_name=None,
force_calc_spectrograms=False,
)