turn on suggestions

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

Showing results for

Find a Community

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2013 02:09 PM

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!

Accepted Solutions

Solution

07-02-2013
03:12 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ahappel

07-02-2013 03:12 PM

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.

All Replies

Solution

07-02-2013
03:12 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ahappel

07-02-2013 03:12 PM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

07-02-2013 05:05 PM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ahappel

07-03-2013 06:35 AM

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;