BookmarkSubscribeRSS Feed
sasuser2417
Calcite | Level 5

I am trying to do an optimization and it's taking too long (around 150 mins), on the other hand implementation in R takes only 10 mins approx. Here is the SAS code; I guess there might be an efficient way of implementing it.

SAS Code:

*************

proc optmodel;

num n = &n; number ysq = &mysq; number y{1..n};

read data ret into [_n_] y;

var omega init 3.442868e-07, alpha init -4.391689, beta init 9.766483e-01, theta init -3.954835e-03,

delta init 5.340570e-03, lambda0 init 2.626132e-02, rho init 9.763934e-01, gamma init 9.025426e-01,

alphaj init -6.635340e-04, alphan init -9.694536e+00, alphanj init  -1.194563e-01, mu init 2.360808e-04, v init 8.541275;

impvar pars {i in 1..n, j in 1..27} =

(if (i =1 and j = 1) then lambda0 / (1-rho)

else if (i =1 and j = 2) then 0

else if (i =1 and j = 3) then ysq

else if (i=1 and 4 <= j <= 24) then (gamma(0.5*(v+1))) * (1/(gamma(0.5*v)*sqrt(3.141592653*v*(pars[i,3]+(j-4)*(delta)**2)))) * (1 + ((y-(mu-theta*(pars[i,1]-(j-4))))**2)/(v*(pars[i,3]+(j-4)*(delta)**2)))**(-0.5*(v+1))

else if (i=1 and j = 25) then sum{k in 1..21}(pars[i,(k+3)]* pars[i,1]**(k-1) * exp(-pars[i,1])/fact((k-1)) )

else if (i=1 and j = 26) then sum{k in 1..21}((k-1)*pars[i,(k+3)]* pars[i,1]**(k-1) * exp(-pars[i,1])/fact((k-1)) )

else if (i=1 and j = 27) then pars[i,26]/pars[i,25]

else if (i <> 1 and j = 1) then lambda0 + rho*pars[(i-1),1] + gamma * pars[(i-1),27]

else if (i <> 1 and j = 2 and (y[(i-1)]-mu < 0 )) then exp(alpha + (alphaj + alphanj)*pars[(i-1),26] + alphan)

else if (i <> 1 and j = 2 and (y[(i-1)]-mu >= 0 )) then exp(alpha + alphaj*pars[(i-1),26])

else if (i <> 1 and j = 3) then omega + pars[i,2]*(y[(i-1)]-mu)**2 + beta*pars[(i-1),3]

else if (i <> 1 and 4 <= j <= 24) then (gamma(0.5*(v+1))) * (1/(gamma(0.5*v)*sqrt(3.141592653*v*(pars[i,3]+(j-4)*(delta)**2)))) * (1 + ((y-(mu-theta*(pars[i,1]-(j-4))))**2)/(v*(pars[i,3]+(j-4)*(delta)**2)))**(-0.5*(v+1))

else if (i <> 1 and j = 25) then sum{k in 1..21}(pars[i,(k+3)]* pars[i,1]**(k-1) * exp(-pars[i,1])/fact((k-1)) )

else if (i <> 1 and j = 26) then sum{k in 1..21}((k-1)*pars[i,(k+3)]* pars[i,1]**(k-1) * exp(-pars[i,1])/fact((k-1)) )

else if (i <> 1 and j = 27) then pars[i,26]/pars[i,25] - pars[i,1] );

max z = sum{k in 1..n}(log(pars[k,25]));

omega.lb = 1e-12; alpha.lb = -100; beta.lb = -100; theta.lb=-100; delta.lb=1e-06; lambda0.lb=1e-06; rho.lb=0;

gamma.lb=0; alphaj.lb = -100; alphan.lb = -100; alphanj.lb = -100; mu.lb = -1; v.lb = 3+1e-06;

omega.ub = 1-1e-06; alpha.ub = 100; beta.ub = 100; theta.ub=100; delta.ub=100; lambda0.ub=30; rho.ub=1-1e-06;

gamma.ub=1-1e-06; alphaj.ub = 100; alphan.ub = 100; alphanj.ub = 100; mu.ub = 1; v.ub = 1800;

con c: rho >= gamma;

solve with NLP / tech=IP ; print omega; print alpha; print beta; print mu; print v; print lambda0; print rho;

print gamma; print alphan; print alphaj; print alphanj; print theta; print delta;

quit;

1 REPLY 1
RobPratt
SAS Super FREQ

Can you please attach the ret data set?

Note that <> is the MAX operator, so your IMPVAR declaration is not doing what you want.  Instead, use ne or ~= or ^= for not equals.

Also, I suspect that replacing the IMPVAR with explicit variables and constraints will reduce the solve time.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 735 views
  • 0 likes
  • 2 in conversation