Skip to content

Branin4

arturluis edited this page Feb 17, 2021 · 3 revisions

Here, we will show how to use HyperMapper to optimize a four-dimensional Branin function (Branin4) with different parameter types. We look for minimizing the value of this function given four parameters x1, x2, x3, and x4.

The Objective Function

In this example, we want to minimize the Branin4 function value and energy estimation. We define the value of the Branin4 simply as the product of two Branin functions. We begin by defining the standard Branin function:

def Branin(x1, x2):
    a = 1.0
    b = 5.1 / (4.0 * math.pi * math.pi)
    c = 5.0 / math.pi
    r = 6.0
    s = 10.0
    t = 1.0 / (8.0 * math.pi)
    y_value = a * (x2 - b * x1 * x1 + c * x1 - r) ** 2 + s * (1 - t) * math.cos(x1) + s
    return y_value

Then, we define our objective function combining two Branin functions:

def Branin4(X):
    x1 = X['x1']
    x2 = X['x2']
    x3 = X['x3']
    x4 = X['x4']
    f1_value = Branin(x1, x2)
    f2_value = Branin(x3, x4)
    y_value = f1_value*f2_value
    return y_value

An example of this code can be found in branin4.py.

The JSON Configuration File

The following is what needs to be specified as a json syntax to run Branin4:

{
    "application_name": "branin4",
    "optimization_objectives": ["Value"],
    "optimization_iterations": 50,
    "input_parameters" : {
        "x1": {
            "parameter_type" : "real",
            "values" : [-5, 10],
            "parameter_default" : 0
        },
        "x2": {
            "parameter_type" : "real",
            "values" : [0, 15],
            "parameter_default" : 0
        },
        "x3": {
            "parameter_type" : "integer",
            "values" : [-5, 10],
            "parameter_default" : 0
        },
        "x4": {
            "parameter_type" : "integer",
            "values" : [0, 15],
            "parameter_default" : 0
        }
    }
}

Note that "input_parameters" specifies the four parameters that define our serch space. To showcase different parameter types, we use both "real" (x1, x2) and "integer" (x3, x4) parameters, which are real/integer values in the interval defined by the "values" field. You can find all parameter types supported by HyperMapper here.

You can find this json in branin4_scenario.json.

Run HyperMapper

In order to run this example, we use:

python3 example_scenarios/synthetic/branin4/branin4.py

An example of stdout output can be found here.

The result of this script is a csv file called branin4_output_dse_samples.csv. You can find all the samples explored by HyperMapper during the design space exploration (DSE) in this file.

Other examples

See the CurrinExp example provided to see other parameter types supported by HyperMapper.

See HyperMapper's json syntax page for more information on the supported parameter types.

Clone this wiki locally