SAS Proc IML Optimization

485 views Asked by At
proc iml;  
start f_prob(beta) global(one_m_one, pone_m_one);

p = nrow(one_m_one);
td = j(p,3,0.);
a = 1;
do i = 1 to p;
    td[i,1] = exp((one_m_one[i,1])*(beta[1]) + (one_m_one[i,2])*(beta[2]) + (one_m_one[i,3])*(beta[3]) + (one_m_one[i,4])*(beta[4]) + (one_m_one[i,5])*(beta[5]) + (one_m_one[i,6])*(beta[6]) + (one_m_one[i,7])*(beta[7]) + (one_m_one[i,8])*(beta[8]) + (one_m_one[i,9])*(beta[9]) + (one_m_one[i,10])*(beta[10]));
    do j = a to 11+a;
        td[i,2] = td[i,2] + exp((pone_m_one[j,1])*(beta[1]) + (pone_m_one[j,2])*(beta[2]) + (pone_m_one[j,3])*(beta[3]) + (pone_m_one[j,4])*(beta[4]) + (pone_m_one[j,5])*(beta[5]) + (pone_m_one[j,6])*(beta[6]) + (pone_m_one[j,7])*(beta[7]) + (pone_m_one[j,8])*(beta[8]) + (pone_m_one[j,9])*(beta[9]) + (pone_m_one[j,10])*(beta[10]));
    end;
    a = a + 12;
end;
td[,3] = td[,1]/td[,2];
f = 1;
do i = 1 to p;
    f = f*td[i,3];
end;
return(f);

finish f_prob;

/* Set up the constraints: sum(x)=0 */
/*     x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 SIGN VALUE */
con = {.  .  .  .  .  .  .  .  .  .   .    .,  /* specify lower bounds */
       .  .  .  .  .  .  .  .  .  .   .    .,  /* specify upper bounds */
       1  1  1  1  1  1  1  1  1  1   0    0}; /* constraints */


beta0 = j(1,10,0);
optn = {1,4};

call nlpnra(rc, result, "f_prob", beta0, optn) blc=con;

Hi, I am trying to optimise the function f that has 10 parameters in it with a constraint of all 10 parameters sum up to zero.

Can anyone suggest how can I write the code for the last part so that i can optimise f and get the results i want? Thanks in advance.

1

There are 1 answers

2
Rick On

The documentation provides an example of how to specify a linear constraint matrix. For your example, use a 3 x 12 matrix.

  • On the first row (columns 1:10) put any lower-bound constraints for the parameters.
  • On the second row (columns 1:10) put any upper-bound constraints for the parameters.
  • On the third row, put all ones in columns 1:10. Put a 0 in column 11 to indicate the EQUAL sign. Put 0 in the 12th column to indicate the value of the constraint.

The code looks like this:

/* Set up the constraints: sum(x)=0 */
/*     x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 SIGN VALUE */
con = {.  .  .  .  .  .  .  .  .  .   .    .,  /* specify lower bounds */
       .  .  .  .  .  .  .  .  .  .   .    .,  /* specify upper bounds */
       1  1  1  1  1  1  1  1  1  1   0    0}; /* constraints */
call nlpnra(rc, result, "f_prob", beta, optn) blc=con;

The last line specifies the coefficients of the matrix expression c*x = 0, where c = {1 1 ... 1} contains the of the third row.