0
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.

Sopon
  • 1
  • 2
  • It seems odd that in `f_prob` you have a loop over `j` but `j` does not appear in the expression in the loop. Also: do you have `proc optmodel`? – Leo Jan 06 '17 at 04:31
  • Oops i have made the changes to include j in the loop. Thanks for pointing it out. Does Proc optmodel work better? – Sopon Jan 06 '17 at 06:31
  • I have tried, but i m using sas ue and it does not have Proc optmodel – Sopon Jan 06 '17 at 08:25
  • Whether OPTMODEL or IML work better depends on what you are trying to do. Usually the OPTMODEL syntax is closer to what you might sketch on the board. – Leo Jan 06 '17 at 12:04

1 Answers1

0

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.

Rick
  • 1,210
  • 6
  • 11
  • Hi, i have made some minor changes to my code and added in your suggestion but i m still having this "ERROR: (execution) Invalid operand to operation." problem. What might be the cause of this error? Really appreciate the help. – Sopon Jan 06 '17 at 08:32
  • In general, you should not edit your question to incorporate the answer. It makes it difficult for future readers to see the original problem and vote up answers. You now have a different problem, probably an error in an arithmetic computation. The SAS log should show you the line number where the error occurs. – Rick Jan 07 '17 at 16:49