The OPTLSO Procedure

Example 3.7 Using External Data Sets

This example illustrates the use of external data sets that are specified in the OBJECTIVE= option. The Bard function (Moré, Garbow, and Hillstrom, 1981) is a least squares problem that has $ n=3$ parameters and $ m=15$ functions $ f_ k,$

\[  f(x) = \frac{1}{2} \sum _{k=1}^{15} f_ k^2(x) , \quad x = (x_1,x_2,x_3)  \]

where

\[  f_ k(x) = y_ k - \left( x_1 + \frac{k}{v_ k x_2 + w_ k x_3} \right)  \]

with $v_ k=16-k$, $ w_ k=\min (u_ k, v_ k)$, and

\[  y= (0.14, 0.18, 0.22, 0.25, 0.29, 0.32, 0.35, 0.39, 0.37, 0.58, 0.73, 0.96, 1.34, 2.10, 4.39)  \]

The minimum function value $f(x^*)$ = 4.107E–3 occurs at the point $(0.08,1.13,2.34)$. In this example, the additional variable bounds $-1000 \le x_ i \le 1000$ for $i=1,2,3$ are added.

There are three approaches to specifying the objective function. The first approach assumes that the necessary data are stored within the FCMP function. In this case, you can specify the objective function without using an external data set, as follows:

data vardata;
   input _id_ $ _lb_ _ub_ ;
   datalines;
x1  -1000 1000
x2  -1000 1000
x3  -1000 1000
;

data objdata;
   input _id_ $ _function_ $ _sense_ $;
   datalines;
f   bard     min
;

proc fcmp outlib=sasuser.myfuncs.mypkg;
   function bard(x1, x2, x3);
      array y[15] /nosym (0.14 0.18 0.22 0.25 0.29
                          0.32 0.35 0.39 0.37 0.58
                          0.73 0.96 1.34 2.10 4.39);
      fx = 0;
      do k=1 to 15;
         vk = 16 - k;
         wk = min(k,vk);
         fxk = y[k] - (x1 + k/(vk*x2 + wk*x3));
         fx = fx + fxk**2;
      end;
      return (0.5*fx);
   endsub;
run;

options cmplib = sasuser.myfuncs;
proc optlso
   primalout = solution
   variables = vardata
   objective = objdata;
   performance nthreads=2;
run;

proc print data=solution;
run;

Output 3.7.1 shows the output from running these steps.

Output 3.7.1: Using External Data Sets

The OPTLSO Procedure

Performance Information
Execution Mode Single-Machine
Number of Threads 2

Problem Summary
Problem Type NLP
   
Objective Definition Set OBJDATA
Variables VARDATA
   
Number of Variables 3
Integer Variables 0
Continuous Variables 3
   
Number of Constraints 0
Linear Constraints 0
Nonlinear Constraints 0
   
Objective Definition Source OBJDATA
Objective Sense Minimize

Solution Summary
Solution Status Function convergence
Objective 0.0041074398
Infeasibility 0
Iterations 77
Evaluations 6438
Cached Evaluations 263
Global Searches 1
Population Size 120
Seed 1

Obs _sol_ _id_ _value_
1 0 _obj_ 0.00411
2 0 _inf_ 0.00000
3 0 x1 0.08240
4 0 x2 1.13259
5 0 x3 2.34411
6 0 f 0.00411


This approach is cumbersome if the size of the required data increases. A second approach for medium-sized data sets is to use the READ_ARRAY statement within the FCMP function definition. Because the environment might be distributed, PROC OPTLSO requires a list of all data sets that are used in FCMP function definitions to ensure that the corresponding data sets are available. This list should be specified by using the READARRAY statement.

data barddata;
   input y @@;
   datalines;
0.14 0.18 0.22 0.25 0.29
0.32 0.35 0.39 0.37 0.58
0.73 0.96 1.34 2.10 4.39
;

data vardata;
   input _id_ $ _lb_ _ub_ ;
   datalines;
x1  -1000 1000
x2  -1000 1000
x3  -1000 1000
;

data objdata;
   input _id_ $ _function_ $ _sense_ $;
   datalines;
f   bard     min
;

proc fcmp outlib=sasuser.myfuncs.mypkg;
   function bard(x1, x2, x3);
      array y[15] /nosym;
      rc = read_array('barddata', y);
      fx = 0;
      do k=1 to 15;
         dk  = (16-k)*x2 + min(k,16-k)*x3;
         fxk = y[k] - (x1 + k/dk);
         fx = fx + fxk**2;
      end;
      return (0.5*fx);
   endsub;
run;

options cmplib = sasuser.myfuncs;
proc optlso
   primalout = solution
   variables = vardata
   objective = objdata;
   readarray barddata;
run;

proc print data=solution;
run;

Output 3.7.2 shows the output from running these statements.

Output 3.7.2: Using External Data Sets (II)

The OPTLSO Procedure

Performance Information
Execution Mode Single-Machine
Number of Threads 4

Problem Summary
Problem Type NLP
   
Objective Definition Set OBJDATA
Variables VARDATA
   
Number of Variables 3
Integer Variables 0
Continuous Variables 3
   
Number of Constraints 0
Linear Constraints 0
Nonlinear Constraints 0
   
Objective Definition Source OBJDATA
Objective Sense Minimize

Solution Summary
Solution Status Function convergence
Objective 0.0041074398
Infeasibility 0
Iterations 77
Evaluations 6438
Cached Evaluations 263
Global Searches 1
Population Size 120
Seed 1

Obs _sol_ _id_ _value_
1 0 _obj_ 0.00411
2 0 _inf_ 0.00000
3 0 x1 0.08240
4 0 x2 1.13259
5 0 x3 2.34411
6 0 f 0.00411


The preceding approach can be prohibitive if the size of the data set is large. As a third approach to specifying the objective function, PROC OPTLSO provides an alternate data input gateway that is described in the OBJECTIVE= data set, as shown in the following statements:

data vardata;
   input _id_ $ _lb_ _ub_ ;
   datalines;
x1  -1000 1000
x2  -1000 1000
x3  -1000 1000
;

data barddata;
   k = _n_;
   input y @@;
   datalines;
0.14 0.18 0.22 0.25 0.29
0.32 0.35 0.39 0.37 0.58
0.73 0.96 1.34 2.10 4.39
;
data objdata;
   input _id_ $ _function_ $ _sense_ $ _dataset_ $;
   datalines;
fx   bard     min  barddata
;

proc fcmp outlib=sasuser.myfuncs.mypkg;
   function bard(x1, x2, x3, k, y);
      vk = 16 - k;
      wk = min(k,vk);
      fxk = y - (x1 + k/(vk*x2 + wk*x3));
      return (0.5*fxk**2);
   endsub;
run;

options cmplib = sasuser.myfuncs;
proc optlso
   primalout = solution
   variables = vardata
   objective = objdata;
   performance nodes=2 nthreads=8;
run;


proc print data=solution;
run;

Output 3.7.3 shows the output from running these statements.

Output 3.7.3: Using External Data Sets (III)

The OPTLSO Procedure

Problem Summary
Problem Type NLP
   
Objective Definition Set OBJDATA
Variables VARDATA
   
Number of Variables 3
Integer Variables 0
Continuous Variables 3
   
Number of Constraints 0
Linear Constraints 0
Nonlinear Constraints 0
   
Objective Definition Source OBJDATA
Objective Sense Minimize
Objective Data Set barddata

Solution Summary
Solution Status Function convergence
Objective 0.0041074398
Infeasibility 0
Iterations 77
Evaluations 6438
Cached Evaluations 263
Global Searches 1
Population Size 120
Seed 1

Performance Information
Host Node << your grid host >>
Execution Mode Distributed
Grid Mode Symmetric
Number of Compute Nodes 2
Number of Threads per Node 8