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.1.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

distgfs-1.1.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for distgfs-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0771308c2c3b2f8bd06b2d09e6a945b5db9e0b72e02777a2a215d3c483799afc
MD5 aa72f03a9e0f0e3b2d6ea5211604e4d0
BLAKE2b-256 e8720efb4f5944f44daaf3e6c2a1761d82856b88d60fa06c6a035d8f829e5148

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for distgfs-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a872c8d0b9052ef70b040aafdafa8b7a7f94add19e73ad58ee592552ae514eb
MD5 fc62e2cab96a7e4bf9b1f43bc4d77009
BLAKE2b-256 66e605a74d64406cdd3c8774b2dd551437a6f684bf7898f5728f5faaef20befc

See more details on using hashes here.

Supported by

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