Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-02-2013 02:09 PM
(1231 views)

Hello,

I am a graduate student (in ecology, so not a great background in mathematics or coding languages) attempting an optimization for a part of my thesis. Currently I have the coding below in an attempt to get the "program" to work with pseudo-data. This has been constructed based on publications, which use other programming languages, but the functions are "...local minimizer for smooth non-linear functions subject to bound-constrained parameters, and uses a quasi-newton method". Thus I believe the correct call is NLPQN, however when running this I do not get the expected optimization.

Proc IML;

start qfasa(y);

prey={17 41 5, 40 30 25}; /*pseudo-profile of three prey items with 2 variables each*/

predator={13.4, 29.5}; /*pseudo-profile of one predator with 2 variables that are the proportional addition of the prey items*/

predic=(prey#y);

diet=predic[,+];

KL1=((predator-diet)#log10(predator/diet)); /*Kulback-Liebler Distance*/

KL=KL1[+,];

Return(KL); /*currently must be a scalar, possible to get this for each predator column when more are added? (do loops?)*/

finish qfasa;

y={.5 .25 .25}; /* Initial guess at proportions*/

c={0 0 0, 1 1 1}; /*Constraints on parameters*/

optn={0 2};

call nlpqn(rc,xr,"qfasa",y,optn,c) ;

run;

*/Answer should be { .25 .15 .60}*/

Thanks for any help!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

From your starting conditions and your answer, I'm guessing that you expect that the parameters sum to one? (Are they proportions?). You have not constrained the parameter sum.

There are two ways you can do this:

1) Leave the constraint matrix as it is and add a penalty term to the objective function. For example, add

return( KL + 1000*(sum(y)-1)##2)

2) Incorporate the constraints into the matrix:

c={0 0 0 . ., /* 0 <= p1, p2, p3 <=1 */

1 1 1 . .,

1 1 1 0 1}; /* p1 + p2 + p3 = 1 */

See SAS/IML(R) 12.1 User's Guide for specifying constraints.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

From your starting conditions and your answer, I'm guessing that you expect that the parameters sum to one? (Are they proportions?). You have not constrained the parameter sum.

There are two ways you can do this:

1) Leave the constraint matrix as it is and add a penalty term to the objective function. For example, add

return( KL + 1000*(sum(y)-1)##2)

2) Incorporate the constraints into the matrix:

c={0 0 0 . ., /* 0 <= p1, p2, p3 <=1 */

1 1 1 . .,

1 1 1 0 1}; /* p1 + p2 + p3 = 1 */

See SAS/IML(R) 12.1 User's Guide for specifying constraints.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Rick, the constraints issue got it to do what I wanted!

Could you (anyone) give me some starting points on getting this to work column-wise on a dataset? Specifically, I have been trying to get column (sample) specific parameter estimates for the "predator" matrix.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think I would need to see sample data to understand what you mean. It seems like the optimization requires a vector.

If you want to apply this optimization to several predator vectors that are stored in a data base, use the GLOBAL statement so that the predator vector is considered a parameter in the problem:

start qfasa(y) global(predator);

...

finish;

do i = 1 to ncol(big_matrix);

predator = big_matrix[, i];

call nlpqn(rc,xr,"qfasa",y,optn,c) ; /* solve for this column */

/* store or do something with xr */

end;

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.