Skip to main content

Distributed global function search via dlib

Project description

distgfs

Distributed computing framework for the Global Function Search (GFS) hyperparameter optimizer from the Dlib library. Based on gfsopt.

Provides the following features:

  • Parallel optimization: Run distributed hyperparameter searches via mpi4py.
  • Save and restore progress: Save/restore settings, parameters and optimization progress to/from HDF5 file.
  • Average over multiple runs: Run a stochastic objective function using the same parameters multiple times and report the average to Dlib's Global Function Search. Useful in highly stochastic domains to avoid biasing the search towards lucky runs.

For theoretical background of GFS, see 'A Global Optimization Algorithm Worth Using' and Malherbe & Vayatis 2017: Global optimization of Lipschitz functions

Example usage

A basic example where we maximize Levi's function with as many parallel processes as there are logical cores, and save progress to file.

import math, distgfs

def levi(x, y):
    """
    Levi's function (see https://en.wikipedia.org/wiki/Test_functions_for_optimization).
    Has a global _minimum_ of 0 at x=1, y=1.
    """
    a = math.sin(3. * math.pi * x)**2
    b = (x - 1)**2 * (1 + math.sin(3. * math.pi * y)**2)
    c = (y - 1)**2 * (1 + math.sin(2. * math.pi * y)**2)
    return a + b + c


def obj_fun(pp, pid):
    """ Objective function to be _maximized_ by GFS. """
    x = pp['x']
    y = pp['y']

    res = levi(0.4*x, y)
    print(f"Iter: {pid}\t x:{x}, y:{y}, result:{res}")
    # Since Dlib maximizes, but we want to find the minimum,
    # we negate the result before passing it to the Dlib optimizer.
    return -res

# For this example, we pretend that we want to keep 'y' fixed at 1.0
# while optimizing 'x' in the range -4.5 to 4.5
space = {'x': [-4.5, 4.5]}
problem_parameters = {'y': 1.}
    
# Create an optimizer parameter set
distgfs_params = {'opt_id': 'distgfs_levi',
                  'obj_fun_name': 'obj_fun',
                  'obj_fun_module': 'example_distgfs_levi_file',
                  'problem_parameters': problem_parameters,
                  'space': space,
                  'n_iter': 10,
                  'file_path': 'distgfs.levi.h5',
                  'save': True,
                 }

distgfs.run(distgfs_params, verbose=True)

For additional examples, see examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

distgfs-1.0.0.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

distgfs-1.0.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file distgfs-1.0.0.tar.gz.

File metadata

  • Download URL: distgfs-1.0.0.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.10 Linux/5.18.10-76051810-generic

File hashes

Hashes for distgfs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 54063f7ce22e898e14395a6ca9a8a8bd4a16ac77eb856228d7d63a1517197574
MD5 4ba9e5f55e84d35d64f6122006197a3a
BLAKE2b-256 31729ec18b981207a1ab0c1ac96ed52d6f42d725b832135d0298e6acc6f5b9e6

See more details on using hashes here.

File details

Details for the file distgfs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: distgfs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.10 Linux/5.18.10-76051810-generic

File hashes

Hashes for distgfs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e70c29e78e387d0582f01a35073ff4233920175b2f426fc93e99011d6627c58
MD5 f0d79f0260f988872f3e020fa77153bf
BLAKE2b-256 fa8889c466aeadfc02597d66d20164512dee9bec3aeeaf743e628c250e0fd88c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page