Skip to content

HubiRa/gfog

Repository files navigation

GFog Logo

GFog - Gradient-Free Optimization via Gradients

GFog is a gradient-free optimization library using GANs to find solutions to black-box optimization problems — potentially discovering multiple optima. It builds upon and improves the method proposed in the paper A GAN based solver of black-box inverse problems (OptimGan)

Quick Start

To run the example shown below run the following from the GFog base directory (the project uses uv):

# create and activate venv
uv venv
source .venv/bin/activate

# Install dependencies
bash install.sh

# Or, if you want to develop then install as
bash install.sh dev

# Run example for himmelblau function
python examples/testfunctions/example_himmelblau.py

Improvements to OptimGan

GFog introduces two improvements over OptimGan:

  1. Curiosity Loss

    OptimGan frequently stalled before converging, despite expectations that a GAN would explore and potentially uncover multiple solutions. GFog adds a curiosity loss that encourages exploration and often leads to discovering multiple solutions.

  2. Hierarchically Sorted Buffer

    GFog supports multiple objectives using a hierarchically sorted buffer. For example, in a constrained optimization problem, each constraint can define a hierarchy level. This avoids the need to merge objectives of potentially vastly different magnitudes into a single loss It is as easy as letting the function to optimize return multiple values and tell the buffer to expect the number of returned values:

# - the buffer expects two outputs from the function
# - sorting order is determined by the order in the list
# - we can give the levels names to make the targets explicit
buffer = Buffer(
    buffer_size=buffer_size,
    value_levels=Levels(["constraints", "fx"])
)

Examples

Curiosity applied on Himmelblau's function

With Curiosity
With Curiosity Loss
Without Curiosity
Without Curiosity Loss

Comparison showing how curiosity loss helps discover all four minima but also taking more iterations

Constraints applied on Mishra's Bird function

With Constraints
With Constraints
Without Constraints
Without Constraints

Comparison show how adding constraints effect the optimization


Code Example

TODO

How it works

TODO: more detail

  • Generator: Proposes samples
  • Samples are evaluated via the function to be optimized
  • Buffer: Maintains best solutions found so far
  • Discriminator: discriminates between generated samples and samples in the buffer
  • Curiosity Loss: Encourages exploration of unexplored regions

About

Gradient free optimisation via gradients

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors