Help

Problems with syntax of GAMS
Post Reply
jtayers
User
User
Posts: 6
Joined: 1 year ago

Help

Post by jtayers »

I'm trying to display the umpires with the best score for each home and away team. The way I have it set up is a two-dimensional set with home and away teams in the matchup set. The best scores set has all the best scores for each type of home and away team. The scores parameter has a value attached to it. I've been playing around with it for a while but can't figure it out.



set results(home,away);
results(home,away)$(home.ord ne away.ord) = yes;

set best_scores(home,away);
best_scores(index,umpire,home,away)$(home.ord ne away.ord) = yes;

loop(scores(index,umpire,home,away),
if (scores.val(index,umpire,home,away) > best_scores(index,umpire,home,away), results(home,away) = umpire$(scores(index,umpire,home,away)));
);

display matchups;
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Help

Post by bussieck »

Sorry, don't get it. Perhaps, you give some example instead of incomplete and cryptic GAMS code.

-Michael
jtayers
User
User
Posts: 6
Joined: 1 year ago

Re: Help

Post by jtayers »

scores(index, umpire, home, away) is a parameter.
for example: scores(1,'Mike Smith','ATL','LAD') = 1.24
scores has all the data for the last 18000+ MLB games

What I want is all the best umpires for each home and away matchup somehow displayed.

Hopefully that clears things up.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Help

Post by bussieck »

Here is a small complete example program that demonstrates this. Most of the work in generating a random data set. For your question: You basically calculate the best_score using smax and then you go again over the data to find the index and umpire with that score for the home,away pair. GAMS does not have an argmax functionality. That's the way out. With this calculation you might actually end up with more than one umpire per home,away pair if both umpires have the same best score for this combination.

Code: Select all

set teams /t1*t10/; alias (teams,home,away);
set umpire /u1*u20/; set index /1*18000/;
parameter scores(index, umpire, home, away);

* Create some random data
set sample /1*1000/; 
set sd1(sample,umpire,home,away), sd2(index,sample,umpire,home,away), sd3(index,umpire,home,away);
sd1(sample,umpire,home,away)$(not sameas(home,away)) = yes$(uniform(0,1)<0.01);
option sd2(index:sd1), sd3<sd2;
scores(sd3) = uniform(1,10);

* Determine best umpire for home/away combination
parameter bestscore(home,away); set best_umpires(home,away,umpire);
bestscore(home,away)$(not sameas(home,away)) = smax((index,umpire), scores(index,umpire,home,away));
best_umpires(home,away,umpire)$(not sameas(home,away)) = sum(index$(scores(index,umpire,home,away)=bestscore(home,away)), 1);
-Michael
jtayers
User
User
Posts: 6
Joined: 1 year ago

Re: Help

Post by jtayers »

Thanks! That's exactly what I needed. I'm curious about an extension to this problem. What if you weren't given the scores parameter but given several other parameters such as:
correct_calls_above_expected(index,umpire,home,away)
accuracy_above_expected(index,umpire,home,away)
consistency(index,umpire,home,away)
favor_home(index,umpire,home,away)
total_run_impact(index,umpire,home,away)

let's say:
score = correct_calls_above_expected + accuracy_above_expected + consistency - abs(favor_home) - total_run_impact

To build a parameter score, would it be as simple as:

parameter score(index,umpire,home,away);
score(index,umpire,home,away) = correct_calls_above_expected(index,umpire,home,away) + accuracy_above_expected(index,umpire,home,away) + consistency(index,umpire,home,away) - abs(favor_home(index,umpire,home,away)) - total_run_impact(index,umpire,home,away);
jtayers
User
User
Posts: 6
Joined: 1 year ago

Re: Help

Post by jtayers »

I'm having a problem where every single umpire who has umpired that game gets thrown into the best_umpire set. I thought removing the index part would fix that but it did not. Any ideas?

This is what I have right now:

parameter scores(umpire,home,away);

scores(umpire,home,away) = correct_calls_above_expected(umpire,home,away) + accuracy_above_expected(umpire,home,away) + consistency(umpire,home,away) - abs(favor_home(umpire,home,away)) - total_run_impact(umpire,home,away);

parameter bestscore(home,away); set best_umpires(home,away,umpire);
bestscore(home,away)$(not sameas(home,away)) = smax((umpire), scores(umpire,home,away));
best_umpires(home,away,umpire)$(not sameas(home,away)) = sum(index$(scores(umpire,home,away)=bestscore(home,away)), 1);

display best_umpires;
jtayers
User
User
Posts: 6
Joined: 1 year ago

Re: Help

Post by jtayers »

Thanks Michael!

It looks like your code displays all the umpires who umpired that matchup. I believe this is because of the index. Could you repost the last block of code fixing this problem please?
Post Reply