The Black-Box Optimization Solver
Example 10.4 Using External Data Sets
This example illustrates the use of external data that are required in order to evaluate the objective function. The Bard function (Moré, Garbow, and Hillstrom 1981) is a least squares problem that has parameters and
functions
where
The minimum function value = 4.107E–3 occurs at the point
. In this example, the additional variable bounds
for
are added.
The following example code shows two approaches to specifying the objective function. The first approach assumes that the necessary data are stored within the FCMP function that defines the objective. In this case, you can specify the objective function without using an external data set, as follows:
proc fcmp outlib=work.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 = work.myfuncs;
proc optmodel;
var x {1..3} >= -1000 <= 1000;
min f = bard(of x[*]);
solve with blackbox / nthreads=2;
print x;
quit;
Output 10.4.1 shows the output from running these steps.
Output 10.4.1: Using External Data Sets
| Problem Summary | |
|---|---|
| Objective Sense | Minimization |
| Objective Function | f |
| Objective Type | Nonlinear |
| Number of Variables | 3 |
| Bounded Above | 0 |
| Bounded Below | 0 |
| Bounded Below and Above | 3 |
| Free | 0 |
| Fixed | 0 |
| Number of Constraints | 0 |
| Constraint Coefficients | 0 |
| Solution Summary | |
|---|---|
| Solver | Black-Box |
| Objective Function | f |
| Solution Status | Function Convergence |
| Objective Value | 0.0041074408 |
| Infeasibility | 0 |
| Random Seed Used | 1 |
| Evaluations | 4589 |
| Cached Evaluations | 55 |
| Iterations | 53 |
| Presolve Time | 0.00 |
| Solution Time | 0.09 |
| [1] | x |
|---|---|
| 1 | 0.082419 |
| 2 | 1.133250 |
| 3 | 2.343536 |
The preceding approach can be prohibitive if the data set is large. As a second approach to specifying the objective function, you can define data in a SAS data set, read the data set into PROC OPTMODEL, and then use the values from that data set as part of the objective computation. This approach is shown in the following statements:
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
;
proc fcmp outlib=work.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 = work.myfuncs;
proc optmodel;
set KSET;
num y {KSET};
read data barddata into KSET=[k] y;
var x {1..3} >= -1000 <= 1000;
min f = sum {k in KSET} bard(of x[*], k, y[k]);
solve with blackbox / nthreads=2;
print x;
quit;
Output 10.4.2 shows the output from running these statements.
Output 10.4.2: Using External Data Sets (II)
| Problem Summary | |
|---|---|
| Objective Sense | Minimization |
| Objective Function | f |
| Objective Type | Nonlinear |
| Number of Variables | 3 |
| Bounded Above | 0 |
| Bounded Below | 0 |
| Bounded Below and Above | 3 |
| Free | 0 |
| Fixed | 0 |
| Number of Constraints | 0 |
| Constraint Coefficients | 0 |
| Solution Summary | |
|---|---|
| Solver | Black-Box |
| Objective Function | f |
| Solution Status | Function Convergence |
| Objective Value | 0.0041074408 |
| Infeasibility | 0 |
| Random Seed Used | 1 |
| Evaluations | 4589 |
| Cached Evaluations | 55 |
| Iterations | 53 |
| Presolve Time | 0.00 |
| Solution Time | 0.09 |