Goldstein-Price Function

The Goldstein-Price function is a two-dimensional function with several local minima. This function is one of test functions or artificial landscapes to evaluate optimization algorithms. The formulation of the function is:

\[\begin{split} \begin{align} f(x, y) = &\left[ 1 + (x + y + 1)^2 \left( 19 - 14x + 3x^2 - 14y + 6xy + 3y^2 \right) \right] \\ \nonumber &\cdot \left[ 30 + (2x - 3y)^2 \left( 18 - 32x + 12x^2 + 48y - 36xy + 27y^2 \right) \right], \end{align} \end{split}\]

and the function yields the global minimum \(f(x, y) = f(0, -1) = 3\). A two-dimensional landscape of \(f(x, y)\) in log scale is shown below.

Here is an example of black-box optimization for the Goldstein Price function (this function is considered a black-box for evaluation purpose). The Goldstein-Price function is prepared in Amplify-BBOpt as goldstein_price_function.

Objective function and variables

from datetime import timedelta

from amplify import FixstarsClient
from amplify_bbopt import (
    DatasetGenerator,
    KernelQAOptimizer,
    RealVariable,
    blackbox,
    plot_history,
)
from amplify_bbopt.objective_example import goldstein_price_function


@blackbox
def blackbox_func(
    x: float = RealVariable(bounds=(-3, 3), nbins=301),
    y: float = RealVariable(bounds=(-3, 3), nbins=301),
) -> float:
    ret = goldstein_price_function(x, y)
    print(f"{x=}, {y=}, {ret=:.3e}")
    return ret

Initial training data

# Generate initial training dataset with 10 samples
data = DatasetGenerator(objective=blackbox_func).generate(num_samples=10)
Hide code cell output
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #0/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=2.12, y=0.8200000000000003, ret=1.602e+03
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #1/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=0.06000000000000005, y=-1.38, ret=5.788e+02
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #2/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=-1.16, y=-2.76, ret=1.093e+06
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #3/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=-2.56, y=-2.92, ret=8.763e+04
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #4/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=-1.96, y=1.88, ret=7.347e+05
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #5/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=0.8999999999999999, y=2.4800000000000004, ret=7.498e+05
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #6/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=0.020000000000000018, y=0.6400000000000001, ret=7.477e+03
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #7/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=2.84, y=1.38, ret=1.135e+04
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #8/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=0.8000000000000003, y=0.26000000000000023, ret=1.142e+03
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #9/10 initial data for blackbox_func
amplify-bbopt | 2024/10/04 05:54:31 | INFO | - [obj]: x=0.3599999999999999, y=2.62, ret=9.195e+05

Optimizer

# Set up solver client
client = FixstarsClient()
client.parameters.timeout = timedelta(milliseconds=2000)  # 2 seconds
# client.token = "xxxxxxxxxxx"  # Enter your Amplify AE API token.

# Instantiate an optimizer
optimizer = KernelQAOptimizer(data=data, objective=blackbox_func, client=client)

print(optimizer)
Hide code cell output
num variables: 2
num elemental variables: 2
num amplify variables: 600
optimizer client: FixstarsClient
objective weight: 1.0
--------------------
trainer class: ModelKernelTrainer
model class: ModelKernel
model params: {beta: 0.0, gamma: 0.0}
reg_param: 1
# Perform optimization for [num_cycles] optimization cycles
optimizer.optimize(num_cycles=20)
Hide code cell output
amplify-bbopt | 2024/10/04 05:54:31 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:31 | INFO | #1/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:32 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:35 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:54:35 | INFO | - [obj]: x=2.88, y=0.6400000000000001, ret=5.920e+03
amplify-bbopt | 2024/10/04 05:54:35 | INFO | y_hat=5.920e+03, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:35 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:35 | INFO | #2/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:35 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:37 | INFO | num_iterations: 28
amplify-bbopt | 2024/10/04 05:54:37 | INFO | - [obj]: x=-3.0, y=-1.38, ret=3.643e+05
amplify-bbopt | 2024/10/04 05:54:37 | INFO | y_hat=3.643e+05, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:37 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:37 | INFO | #3/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:37 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:42 | INFO | num_iterations: 20
amplify-bbopt | 2024/10/04 05:54:42 | INFO | - [obj]: x=2.84, y=0.26000000000000023, ret=2.334e+04
amplify-bbopt | 2024/10/04 05:54:42 | INFO | y_hat=2.334e+04, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:42 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:42 | INFO | #4/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:42 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:45 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:54:45 | INFO | - [obj]: x=0.06000000000000005, y=0.6400000000000001, ret=6.785e+03
amplify-bbopt | 2024/10/04 05:54:45 | INFO | y_hat=6.785e+03, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:45 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:45 | INFO | #5/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:45 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:48 | INFO | num_iterations: 23
amplify-bbopt | 2024/10/04 05:54:48 | INFO | - [obj]: x=2.12, y=0.6400000000000001, ret=6.499e+02
amplify-bbopt | 2024/10/04 05:54:48 | INFO | y_hat=6.499e+02, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:48 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:48 | INFO | #6/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:48 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:53 | INFO | num_iterations: 22
amplify-bbopt | 2024/10/04 05:54:53 | INFO | - [obj]: x=2.84, y=0.8200000000000003, ret=8.613e+02
amplify-bbopt | 2024/10/04 05:54:53 | INFO | y_hat=8.613e+02, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:53 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:53 | INFO | #7/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:53 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:54:57 | INFO | num_iterations: 21
amplify-bbopt | 2024/10/04 05:54:57 | INFO | - [obj]: x=0.8000000000000003, y=-1.38, ret=5.090e+03
amplify-bbopt | 2024/10/04 05:54:57 | INFO | y_hat=5.090e+03, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:54:57 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:54:57 | INFO | #8/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:54:57 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:00 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:00 | INFO | - [obj]: x=-3.0, y=-3.0, ret=1.583e+04
amplify-bbopt | 2024/10/04 05:55:00 | INFO | y_hat=1.583e+04, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:55:00 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:00 | INFO | #9/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:55:00 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:07 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:07 | INFO | modifying solution (11, is_frequent=False), {'x': -3.0, 'y': -3.0} --> {'x': -1.3399999999999999, 'y': 1.9000000000000004}.
amplify-bbopt | 2024/10/04 05:55:07 | INFO | - [obj]: x=-1.3399999999999999, y=1.9000000000000004, ret=7.766e+05
amplify-bbopt | 2024/10/04 05:55:07 | INFO | y_hat=7.766e+05, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:55:07 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:07 | INFO | #10/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:55:07 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:09 | INFO | num_iterations: 23
amplify-bbopt | 2024/10/04 05:55:09 | INFO | - [obj]: x=0.06000000000000005, y=0.26000000000000023, ret=1.154e+03
amplify-bbopt | 2024/10/04 05:55:09 | INFO | y_hat=1.154e+03, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:55:09 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:09 | INFO | #11/20 optimization cycle, constraint wt: 2.19e+06
amplify-bbopt | 2024/10/04 05:55:09 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:12 | INFO | num_iterations: 26
amplify-bbopt | 2024/10/04 05:55:12 | INFO | modifying solution (1, is_frequent=False), {'x': -3.0, 'y': -3.0} --> {'x': 1.0200000000000005, 'y': -3.0}.
amplify-bbopt | 2024/10/04 05:55:12 | INFO | - [obj]: x=1.0200000000000005, y=-3.0, ret=1.444e+06
amplify-bbopt | 2024/10/04 05:55:12 | INFO | y_hat=1.444e+06, best objective=5.788e+02
amplify-bbopt | 2024/10/04 05:55:12 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:12 | INFO | #12/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:12 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:15 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:15 | INFO | - [obj]: x=0.06000000000000005, y=-0.6000000000000001, ret=1.625e+02
amplify-bbopt | 2024/10/04 05:55:15 | INFO | y_hat=1.625e+02, best objective=1.625e+02
amplify-bbopt | 2024/10/04 05:55:15 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:15 | INFO | #13/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:15 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:17 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:17 | INFO | - [obj]: x=0.06000000000000005, y=-0.94, ret=4.639e+00
amplify-bbopt | 2024/10/04 05:55:17 | INFO | y_hat=4.639e+00, best objective=4.639e+00
amplify-bbopt | 2024/10/04 05:55:17 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:17 | INFO | #14/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:17 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:20 | INFO | num_iterations: 23
amplify-bbopt | 2024/10/04 05:55:20 | INFO | - [obj]: x=0.06000000000000005, y=-0.2799999999999998, ret=5.080e+02
amplify-bbopt | 2024/10/04 05:55:20 | INFO | y_hat=5.080e+02, best objective=4.639e+00
amplify-bbopt | 2024/10/04 05:55:20 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:20 | INFO | #15/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:20 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:25 | INFO | num_iterations: 23
amplify-bbopt | 2024/10/04 05:55:25 | INFO | - [obj]: x=0.06000000000000005, y=-0.8199999999999998, ret=2.235e+01
amplify-bbopt | 2024/10/04 05:55:25 | INFO | y_hat=2.235e+01, best objective=4.639e+00
amplify-bbopt | 2024/10/04 05:55:25 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:25 | INFO | #16/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:25 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:27 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:27 | INFO | - [obj]: x=0.06000000000000005, y=-1.04, ret=5.436e+00
amplify-bbopt | 2024/10/04 05:55:27 | INFO | y_hat=5.436e+00, best objective=4.639e+00
amplify-bbopt | 2024/10/04 05:55:27 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:27 | INFO | #17/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:27 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:32 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:32 | INFO | - [obj]: x=0.06000000000000005, y=-0.98, ret=3.824e+00
amplify-bbopt | 2024/10/04 05:55:32 | INFO | y_hat=3.824e+00, best objective=3.824e+00
amplify-bbopt | 2024/10/04 05:55:32 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:32 | INFO | #18/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:32 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:35 | INFO | num_iterations: 30
amplify-bbopt | 2024/10/04 05:55:35 | INFO | modifying solution (1, is_frequent=False), {'x': -3.0, 'y': -3.0} --> {'x': -0.6400000000000001, 'y': 2.16}.
amplify-bbopt | 2024/10/04 05:55:35 | INFO | - [obj]: x=-0.6400000000000001, y=2.16, ret=5.945e+05
amplify-bbopt | 2024/10/04 05:55:35 | INFO | y_hat=5.945e+05, best objective=3.824e+00
amplify-bbopt | 2024/10/04 05:55:35 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:35 | INFO | #19/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:35 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:38 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:38 | INFO | - [obj]: x=0.06000000000000005, y=-0.8999999999999999, ret=7.464e+00
amplify-bbopt | 2024/10/04 05:55:38 | INFO | y_hat=7.464e+00, best objective=3.824e+00
amplify-bbopt | 2024/10/04 05:55:38 | INFO | ----------------------------------------
amplify-bbopt | 2024/10/04 05:55:38 | INFO | #20/20 optimization cycle, constraint wt: 2.89e+06
amplify-bbopt | 2024/10/04 05:55:38 | INFO | model corrcoef: 1.000, beta: 0.0
amplify-bbopt | 2024/10/04 05:55:40 | INFO | num_iterations: 24
amplify-bbopt | 2024/10/04 05:55:40 | INFO | - [obj]: x=0.06000000000000005, y=-1.0, ret=3.999e+00
amplify-bbopt | 2024/10/04 05:55:40 | INFO | y_hat=3.999e+00, best objective=3.824e+00

Result

# Solution (optimal input to the black-box objective function)
print(f"{optimizer.best_solution=}")

# Corresponding objective function value
print(f"{optimizer.best_objective=:.3e}")

# Optimization history
plot_history(optimizer.fetch_history(), log_scale=True)
optimizer.best_solution={'x': 0.06000000000000005, 'y': -0.98}
optimizer.best_objective=3.824e+00