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)
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.pyGFog introduces two improvements over OptimGan:
-
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.
-
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"])
)Curiosity applied on Himmelblau's function
Comparison showing how curiosity loss helps discover all four minima but also taking more iterations
Constraints applied on Mishra's Bird function
Comparison show how adding constraints effect the optimization
TODO
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




