HS-1040: Minimization of Internal Rosenbrock Function

Learn how to register a Compose/OML or python function in HyperStudy using the Preference file (.mvw), and then use the registered function for output response evaluation in the study.

The Rosenbrock function is defined as a python or OML script and registered in HyperStudy.

The example defines two input variables labeled x and y, respectively. The objective of the optimization is to minimize f(x,y)= 100*(y-x^2)^2 + (1-x)^2. The range for x and y is set to [-2 ; -2] , and the start point is [-1 ; -1].

Define the Rosenbrock Function

In this step you will define the Rosenbrock function with Compose or Python.

  • Define the Rosenbrock function with Compose.
    1. Start Compose.
    2. From the menu bar, click File > New > OML File.
    3. In the editor, enter the following OML commands:
      function f = ros_eval(x,y)
      f = 100.0*(y-x^2)^2 + (1-x)^2
    4. From the menu bar, click File > Save As.
    5. In the Save As dialog, navigate to your working directory and save the file as rosenbrock_function.oml.
    6. Quit Compose by clicking File > Exit from the menu bar.
    Tip: Avoid the subsequent preference file steps when using the Register Function … feature in Compose with OML functions. Highlight the function name, then right-click to access this feature on the context menu.
  • Define the Rosenbrock function with Python.
    1. In your favorite text editor, enter the following python commands:
      def ros_eval(x, y):
          return 100*(y-x*x)*(y-x*x) + (1-x)*(1-x)
    2. From the menu bar, click File > Save As.
    3. In the Save As dialog, navigate to your working directory and save the file as rosenbrock_function.py.

Add the Function to a Preference File

In this step you will add the OML/python function to a Preference file.

  • Add the OML function to the Preference file.
    1. In a text editor, enter the following OML registration function:
      *Id("HyperGraph v11.0")
          *BeginDefaults()
              *BeginPlotDefaults()
                  *SetOMLRootDir("C:/Program Files/Altair/2019/Compose2019")
                  *RegisterOMLFunction("ros_eval",”<path>/rosenbrock_function.oml",2)
              *EndPlotDefaults()
          *EndDefaults()
    2. Replace <path> with the actual location of the file.
    3. Modify the *SetOMLRootDir statement to point to the appropriate location.
    4. Save the file as a preference file with the name rosenbrock_prefs.mvw file.
    5. Close the text editor.
  • Add the python function to a Preference file.
    1. In a text editor, enter the following python registration function:
      *Id("HyperStudy v14.0")
          *BeginDefaults()
              *BeginPlotDefaults()
                  *RegisterPythonFunction("ros_eval","<path>/rosenbrock_function.py",2)
              *EndPlotDefaults()
          *EndDefaults()
    2. Replace <path> with the actual location of the .py file.
    3. Save the file as a preference file with the name rosenbrock_prefs.mvw file.
    4. Close the text editor.

Perform the Study Setup

  1. Start HyperStudy.
  2. Set the Preference file.
    1. From the menu bar, click File > Use Preferences File.
    2. In the HyperStudy - Set Preference File dialog, open the rosenbrock_prefs.mvw file.
  3. Start a new study in the following ways:
    • From the menu bar, click File > New.
    • On the ribbon, click .
  4. In the Add Study dialog, enter a study name, select a location for the study, and click OK.
  5. Go to the Define Models step.
  6. Add an Internal Math model.
    1. Click Add Model.
    2. In the Add dialog, select Internal Math and click OK.
  7. Go to the Define Input Variables step.
  8. Add input variables.
    1. Click Add Input Variable twice.
    2. In the work area, label the input variables x and y.
    3. Change both input variable's lower, initial and upper bounds to the values indicated in Figure 1.
    Figure 1.


Perform Nominal Run

  1. Go to the Test Models step.
  2. Click Run Definition.
    An approaches/setup_1-def/ directory is created inside the study Directory. The approaches/setup_1-def/run__00001/m_1 directory contains the input file, which is the result of the nominal run.

Create and Evaluate Output Responses

  1. Go to the Define Output Responses step.
  2. Click Add Output Response.
  3. In the Expression column of Response 1, click .
  4. In the Expression Builder, click the Functions tab.
  5. From the list of available functions, select ros_eval.
  6. Click Insert Varname.
    The function ros_eval() appears in the Evaluate Expression field.
  7. Click the Input Variables tab.
  8. In the work area, select the input variables x and y.
  9. Click Insert Varname.
    Figure 2.


    The input variables appear in the expression as ros_eval(var_1, var_2).
    Figure 3.


  10. Click OK.
  11. Click Evaluate.
    The expression ros_eval(var_1, var_2) changes to 404.

Run Optimization

  1. Add an Optimization.
    1. In the Explorer, right-click and select Add from the context menu.
    2. In the Add dialog, select Optimization.
    3. For Definition from, select Setup and click OK.
  2. Go to the Optimization > Definition > Define Output Responses step.
  3. Click the Objectives/Constraints - Goals tab.
  4. Add an objective to Response 1.
    1. Click Add Goal.
    2. In the Type column, select Minimize.
    Figure 4.


  5. Go to the Optimization > Specifications step.
  6. In the work area, set the Mode to Adaptive Response Surface Method (ARSM).
    Note: Only the methods that are valid for the problem formulation are enabled.
  7. Click Apply.
  8. Go to the Evaluate step.
  9. Click Evaluate Tasks.
  10. Optional: Click the Iteration Plot tab to monitor the progress of the optimization.
    The iteration history shows a significant reduction in the objective value. The Rosenbrock function has a global minimum that is difficult for any optimizer to find due to its flatness in the area of the true optimum, and ARSM has not found the theoretical solution at (x,y)=(1,1).
    Figure 5.