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.
The documentation provides an example of how to specify a linear constraint matrix. For your example, use a 3 x 12 matrix.
The code looks like this:
The last line specifies the coefficients of the matrix expression c*x = 0, where c = {1 1 ... 1} contains the of the third row.