Skip to main content

Continuous global optimization with non-convex constraints.

Project description

This module solves black-box global optimization problems with non-convex constraints.
Target and constraint implementations assumed to be Lipschitz continuous functions.

Install with pip:

pip install Puffball

Only Windows x64 distribution is available yet.

Example:

from Puffball import Problem
from math import fabs, sin

def f(x):
	return (fabs((x[0]-0.2)**2+(x[1]-0.3)**2-0.2)
			-sin((x[0]-x[1])*15)*0.1
			-(x[0]+2*x[1])*0.1)

problem = Problem(
	bounds = [0,1,0,1],
	target = f,
)

result = problem.Minimize(
	stop_tests = 150,
	local_vs_global = 1,
)

print(result)


Seconds: 0
Tests: 150

GLOBAL MINIMUM:
Index: 0
Value: -0.27822506557686955
Coordinate: (0.39595726499557055, 0.7042844093990224)
Categorical:
Radius: 0.01878891300532774\


For Problem definition specify:

  • bounds — Sequence of min and max limits for each dimension. Flattened. Its size divided by two defines problem dimensionality.

  • target — Target function to minimize. A callable taking tuple of floating-point coordinates and returning floating-point value. Implementation must represent Lipschitz continuous function.

  • constraints — Sequence of optional constraints. Each is a callable taking tuple of floating-point coordinates and returning floating-point value. Order matters a lot. Keep in mind that next one is not tested if previous one has failed. Constraint is assumed satisfied if its value is less than zero. Implementation must represent Lipschitz continuous function.

  • categorical - Optional sequence of integers. Each value represents number of levels for additional categorical parameter. E.g. (2,3) means two categorical parameters, one with two levels (0 and 1) and the other with three levels (0, 1, and 2), which gives six unique categorical combinations to search together with continuous coordinates. If this is specified then constraint/target functions should be defined as f(x,c) where x is tuple of floating-point continuous coordinates and c is tuple of integers representing categorical parameters combination.

For Problem.Minimize call you should specify at least one stop condition:

  • stop_seconds — Stop after specified number of seconds spent.

  • stop_tests — Stop after specified number of tests performed.

  • stop_value — Stop if target value is less than specified.

  • stop_radius — Stop if estimated global minimum coordinate precision achieved.

Other parameters:

  • overestimation — Multiplier for Lipschitz constant estimation. The bigger it gets the more exhaustive the search. Default is 2.0.

  • local_vs_global — Proportion of local tests performed vs global. Global tests give exploration. Local tests give faster convergence to current best optimum. Default is 0.1 (meaning 1 local per 10 global tests). For "simple" functions maybe set 1.0 (meaning 1 to 1 proportion).

Result is a structure:

  • result.seconds — Seconds spent.

  • result.tests — Number of tests performed.

  • result.minimum.index — Minimum point function index. If no constraints specified, then it is always zero. Otherwise target goes last with maximum index. If algorithm failed to find a point where all constraints are satisfied, then index shown is of the failed constraint with maximum index. In this last case minimal value is again shown for the failed constraint with maximum index.

  • result.minimum.value — Minimal value found.

  • result.minimum.coordiate[] — Coordinates of the test with minimal value.

  • result.minimum.categorical[] — Categorical combination of the test with minimal value.

  • result.minimum.radius — Estimated precision for the minimum point coordinates found.

  • result.locals — All the local minimums found (up to 10) ordered by value. Each is the same structure as result.minimum.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

Puffball-0.0.6-cp39-cp39-win_amd64.whl (328.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

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