Running a gams model N times for a random subset of the initial set

Problems with syntax of GAMS
Post Reply
teo21r
User
User
Posts: 2
Joined: 4 weeks ago

Running a gams model N times for a random subset of the initial set

Post by teo21r » 4 weeks ago

Hello everyone,

How can I create N random subsets from my initial set of observations and run my Gams model for each of these subsets? To better explain what I want to do I provide the following example:

SETS i /1*100/
j 'outputs and inputs' /y, x1, x2/
outp(j) /y/
inp(j) /x1,x2/
$CALL GDXXRW.EXE firms.xlsx par=data rng=sheet1!A1:C101
Parameter data(i,j);
$GDXIN firms.gdx
$LOAD data
$GDXIN
display data;
PARAMETERS
.......;
EQUATIONS
.....;
MODEL SP1 /.../;
SOLVE SP1 USING NLP MAXIMIZING Z;


Using the code above I have loaded a data set in GAMS that contains 100 observations and 3 variables. I know how to specify parameters and variables, assign the data to specific variables, and generate equations to be used in the solve statement. My question is how can I make GAMS generate, for example, 10 random subsets of let's say 50 observations each and run the model separately for each of these subsets.

Thank you in advance for your help.

Theo

User avatar
bussieck
Moderator
Moderator
Posts: 465
Joined: 3 years ago

Re: Running a gams model N times for a random subset of the initial set

Post by bussieck » 4 weeks ago

The following code should help you:

Code: Select all

SETS i /1*100/
j 'outputs and inputs' /y, x1, x2/
outp(j) /y/
inp(j) /x1,x2/;
Parameter data(i,j);
data(i,j) = uniform(0,1);
variable obj,x1,x2,dp(i),dn(i);
positive variable dp,dn;
equation e(i), defobj;
set ii(i);
e(ii).. data(ii,'y') =e= x1*data(ii,'x1') + x2*data(ii,'x1') +dp(ii) -dn(ii);
defobj.. obj =e= sum(ii, sqr(dp(ii))+sqr(dn(ii)));

model m /all/;
set k /k1*k10/; scalar ordi;
parameter rep;
loop(k,
* sample 50 observations
  option clear=ii;
  while(card(ii)<50,
     ordi = uniformInt(1,card(i));
     ii(i)$(ord(i)=ordi) = yes;
  );
  solve m us qcp min obj;
  rep(k,'x1') = x1.l;
  rep(k,'x2') = x2.l;
);
display rep;
-Michael

teo21r
User
User
Posts: 2
Joined: 4 weeks ago

Re: Running a gams model N times for a random subset of the initial set

Post by teo21r » 3 weeks ago

Michael,

Thank you, I really appreciate your help.

Theo

Post Reply