Skip to main content

Optimization Package (EGL, CMA, and IGL)

This package provides implementations for Enhanced Gradient Learning (EGL), Covariance Matrix Adaptation (CMA), and Iterative Gradient Learning (IGL) algorithms. It includes modules for datasets, distributions, trust regions, normalizers, stopping conditions, and customizable parameters. The minimize function initiates optimization with flexible configurations.

Table of Contents


Installation

pip install egl

Usage

Importing

The package supports the execution of EGL, CMA, and IGL algorithms, each configured with unique datasets, distributions, trust regions, and loss functions.

from egl import EGL, CMA, IGL, minimize

Using the Minimize Function

The minimize function provides an api (that matches scipy's) , with optimized configurations.

result = minimize(
    function=objective_function,
    x0=starting_point,
    args=[use second order optimization, use weighted mean gradient],
    bounds=[(lower_bound, upper_bound)],
    callback=callback_function,
)

Components

Datasets

EGL manages a dataset of tuples based on dataset of sampled points. There are many ways to decide how to couple the points, we provided multiple datasets options and of course you can create your own.

  • TuplesDataset: Utilizes paired data for optimization with enhanced generalization.
  • PairsInRangeDataset: Pair each point with every single point that was sampled in the same epoch.
  • PairsInEpsRangeDataset: Pair every point with every other point within a given epsilon euclidean distance.
  • PairFromDistributionDataset: A wrapper to sample points from distribution based on the points' values.

Distributions

We showed that egl improves results when calculating a weighted mean gradient based on the functions values. The WeightsDistributionBase defines a base class to create weights distributions.

  • SigmoidWeights: Applies a sigmoid function with custom gamma and quantile values to distribute weights.
  • QuantileWeights: Take certain quantile of minimum values, all other values are weight 0.

Trust Regions

We implemented two trust region with different normalizations.

  • TanhTrustRegion: Maps values within a hyperbolic tangent boundary.
  • LinearTrustRegion: Utilizes linear scaling for boundary constraints.

We found that genetic algorithms suffer when using the hyperbolic function to normalize the values.

Normalizers

We created AdaptedOutputUnconstrainedMapping to normalize the function value to ease the convergence of the algorithm. This is only for convergence base algorithm (i.e. EGL, IGL). The normalization is adaptable based on the the observed sampled values. You can modify the adaptation rate and the outliers' value threshold in the class's constructor.

Callbacks

Define callbacks to execute custom actions at various stages by create a callback `AlgorithmCallbackHandler. This class implements 4 methods:

  • on_algorithm_start: Called once when the algorithm initializes.
  • on_epoch_end: Execute actions at the end of each epoch (after each function step of the algorithm).
  • on_algorithm_update: Execute for each trust region update.
  • on_algorithm_end: Execute actions at the end of the algorithm.

You can create custom callback handlers and pass them to the train in the callback_handlers parameter.

egl.train(
    ...
    callback_handlers=[<callback_handlers>]
)

Stop Conditions

Define custom stopping conditions to end algorithm iterations under specific criteria:

  • AlgorithmStopCondition: Implement a condition by overriding the should_stop method to define custom end conditions.
  • Create instance of the class and pass it to the train in the stopping_conditions parameter.

Advanced Usage

Using the Train Function

The train method is essential to start training the EGL, CMA, and IGL models. Its parameters allow for fine-grained control over the exploration process, shrinking strategy, and improvement checks.

egl.train(
    epochs=100,
    exploration_size=50,
    num_loop_without_improvement=5,
    min_iteration_before_shrink=10,
    surrogate_model_training_epochs=60,
    warmup_minibatch=5,
    warmup_loops=6,
    stopping_conditions=[<stop_conditions>],
    callback_handlers=[<callback_handlers>]
)

Key Parameters

  • epochs: The total number of epochs for the training.
  • exploration_size: Number of new points explored each epoch.
  • num_loop_without_improvement: The allowed epochs without improvement before shrinking the trust region.
  • min_iteration_before_shrink: Minimum epochs before the first shrink action.
  • surrogate_model_training_epochs (default 60): Epochs to train the surrogate model.
  • warmup_minibatch and warmup_loops (defaults 5 and 6): Initialize the model with batch samples and warmup loops.
  • stopping_conditions: List of stop conditions for early termination.
  • callback_handlers: List of callback handlers for custom actions post-epoch and during updates.

Examples

Running CMA with Sigmoid Weights and Linear Trust Region

from egl import CMA, SigmoidWeights, LinearTrustRegion

# Set up CMA with Sigmoid distribution and Linear trust region
cma = CMA(
    trust_region=LinearTrustRegion(...),
    distribution=SigmoidWeights(gamma=-10, quantile=80),
    ...
)
result = cma.train(epochs=100, ...)

Running EGL with Pairs Dataset and Tanh Trust Region

from egl import EGL, PairsInRangeDataset, TanhTrustRegion

# Set up EGL with PairsInRangeDataset and Tanh trust region
egl = EGL(
    dataset_type=PairsInRangeDataset(...),
    trust_region=TanhTrustRegion(...),
    ...
)
result = egl.train(epochs=100, ...)

Metadata

Release files for bbo-egl 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bbo-egl 1.1.0
File Size Uploaded
bbo_egl-1.1.0.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bbo-egl 1.1.0
File Interpreter ABI Platform
bbo_egl-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.6 kB

Release files / bbo_egl-1.1.0.tar.gz

Download URL bbo_egl-1.1.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
89b0b2270b6a9d2620967d1ebda8af4525435d4e3c9a0f194936c8ef795b3350
BLAKE2b-256 checksum
How to use checksums
d92a6a1d3aeaee43da9f71189ec1b3d4b651a5cfc5a430382ad50e9dcfb45dde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.

Transparency log

Release files / bbo_egl-1.1.0-py3-none-any.whl

Download URL bbo_egl-1.1.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a68e181845c2cf11305eda95f313d7de97ca7b3b96eef85ddaeae41f24477b0
BLAKE2b-256 checksum
How to use checksums
817a2c955a0ed541ba7e2182d057bad33443c24af3bcf96cdfcee8e595365479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page