BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
stoffprof
Calcite | Level 5

Can OPTMODEL be used to minimize a function created with PROC FCMP? The documentation for FCMP says functions can be called by PROC NLP and a number of other procedures, but doesn't mention OPTMODEL. Is this correct? If NLP is the legacy procedure I assumed FCMP would be available to the newer procedure.

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

FCMP enablement in PROC OPTMODEL is not documented or supported but has been available as a hidden feature for several releases.  Official support for this functionality is on the roadmap for a coming release.

View solution in original post

7 REPLIES 7
RobPratt
SAS Super FREQ

FCMP enablement in PROC OPTMODEL is not documented or supported but has been available as a hidden feature for several releases.  Official support for this functionality is on the roadmap for a coming release.

stoffprof
Calcite | Level 5

Thanks. Can you give some guidance on the syntax? My attempt isn't working (optmodel can't find the function):

proc fcmp outlib=sasuser.funcs.tester;

  function rosenbrock(x[2]);

     f = 2 * (x[2] - x[1]**2)**2 + (1-x[1])**2;

     return(f);

  endsub;

run;

options cmplib=sasuser.funcs;

proc optmodel;

  var x {1..2};

  min rosenbrock;

  solve;

  print x;

quit;

RobPratt
SAS Super FREQ

  min z = rosenbrock(x);

stoffprof
Calcite | Level 5

Thanks Rob, especially for the super-fast answer (on a Sunday!). I'm trying to minimize a function I created in FCMP that takes only integer values. As far as I can tell, the problem does not fit into a MILP or LP setup, and NLP doesn't seem to allow integers. Is there a way to solve an arbitrary function that takes integers? I thought about modifying my program so it converts real numbers to integers, but I thought that might pose problems for a solver that looks at derivatives because they'd all be quite flat.

RobPratt
SAS Super FREQ

You are correct that the NLP solver does not allow integer variables.

You might be interested in the new OPTLSO procedure, available in SAS/OR 12.3:

http://support.sas.com/documentation/cdl/en/orlsoug/66102/HTML/default/viewer.htm#orlsoug_hplso_toc....

In a later release, this local search solver will also be accessible via OPTMODEL.

If you don't mind, would you please share the function you're trying to minimize?  Do you have any constraints besides integrality of variables?

stoffprof
Calcite | Level 5

Thanks Rob. The only constraints are that the variables are integers bounded by 0 and some integer usually close to 60. (There are about 50-100 such variables.) I don't think there's a straightforward way to share my objective function completely; it's a complicated function of many variables in a dataset. In short, the function is

f(x) = sum over all t of  |a(t) - b(t)|

where a(t) is observable and b(t) = g(x; many parameters), and g() is, as I said, pretty complicated.

I've been minimizing this with a genetic algorithm in IML but am exploring other options with more flexibility. I recently heard about the GA procedure in SAS/OR, and wanted to try that as well. Are you aware of any sample code that shows how to use FCMP with PROC GA? In particular, I'm not clear on whether the functions have to be defined in exactly the same way as they are within GA (the first variable is an array). For example, suppose you wanted to write the function sumsq from this page within FCMP. How would that work, since I'm assuming you can't call ReadMember from FCMP?

RobPratt
SAS Super FREQ

I'm not a PROC GA expert, but I believe for the example you referenced you could define a sum-of-squares function in PROC FCMP:

options cmplib=sasuser.funcs;

proc fcmp outlib=sasuser.funcs.temp;

   function mysum(x

  • );
  •      n = dim(x);

         sum = 0;

         do i = 1 to n;

           sum + x * x;

         end;

         return(sum);

       endsub;

    run;

    And then call it from within the sumsq function in PROC GA:

         /* compute the sum of the squares */

    /*     sum = 0;*/

    /*     do i = 1 to n;*/

    /*       sq = x * x;*/

    /*       sum = sum + sq;*/

    /*     end;*/

         sum = mysum(x);

    Would it be possible for you to share your objective function by posting your actual code and data?

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    Register now!

    Multiple Linear Regression in SAS

    Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

    Find more tutorials on the SAS Users YouTube channel.

    Discussion stats
    • 7 replies
    • 1903 views
    • 3 likes
    • 2 in conversation