Statistical programming, matrix languages, and more

Optimizing Pseudo-data not returning correct parameters

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Optimizing Pseudo-data not returning correct parameters

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
SAS Super FREQ
Posts: 3,221

Re: Optimizing Pseudo-data not returning correct parameters

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.

View solution in original post


All Replies
Solution
‎07-02-2013 03:12 PM
SAS Super FREQ
Posts: 3,221

Re: Optimizing Pseudo-data not returning correct parameters

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.

Occasional Contributor
Posts: 10

Re: Optimizing Pseudo-data not returning correct parameters

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.

SAS Super FREQ
Posts: 3,221

Re: Optimizing Pseudo-data not returning correct parameters

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;

Post a Question
Discussion Stats
  • 3 replies
  • 246 views
  • 0 likes
  • 2 in conversation