Last week I spoke for 20 minutes at CASSIS, the Cascadia Symposium of Statistics in Sport, in Vancouver, BC. The other speakers were outstanding, and among the things I gained was a renewed appreciation for geography and the making of maps and graphics. It's something I'm very poor at, and I would very much like to make some contacts that are good at visual analytics. I also got to meet one of the co-creators of nhlscrapr, who has just make a similar program for American football called nflscrapr.
My talk was about the supposed tendency for hockey teams in the NHL to, when tied in the last ten minutes of regulation time, play very conservatively. That is, defensive strategies are adopted by both teams during this time that reduce the number of goals scored for either side, and generally make for very boring play.
At least that was my research hypothesis: fewer goals, shots, and shot attempts in tied situations compared to similar situations where one team is winning.
Why would this happen? Because teams behave rationally. The winning team in a National Hockey League game is awarded 2 points towards earning a place in the playoffs at the end of the season. The losing team, however, is awarded 0 points if the game ends after regulation play (60 minutes), or 1 point if they game ends in overtime or the shootout. That means there are 2 points distributed between the teams in a regulation game, and 3 points in an overtime or shootout game. Assuming the winner of an overtime game is essentially determined by a coin toss, a team that is tied can expect 1.5 points for remaining tied after 60 minutes.
From the 1.5 point perspective, the potential downside of breaking this tie is 3 times as large as the potential upside. We can assume that a team is already doing everything it can to maximize the chance that it scores the next goal simply because winning is better than losing. In other words, if there was a way a team could influence the game to score more goals while preventing the other team from doing the same, they would already be doing it. However, we can't necessarily assume they are doing everything they can to reduce or increase the rate of goal scoring in general.
So my assumption is that teams DO exert this sort of influence on the game.
Consider the rate of goal scoring in the last two years of the 'zero-sum' era, before the extra overtime point was introduced. The black dotted line for tied games follows the same pattern as the rest of the games, up until the last minute or two when teams that are behind by 1 goal tend to pull their goalie for an extra attacker.
In the first two years after the overtime loss point is introduced, we see a divergence, in which tied games show less scoring in the last 10 minutes.
Likewise, we see this again five years later in the first two years after the shootout in introduced, but less pronounced.
But these are old graphs. Is this the same divergence happening now, a decade into the shootout era? Here's the raw goals per hour for the most recent 3 seasons, which is measuring the same thing as the above graphs, but with less smoothing.
Without the smoothing, the empty net effect is concentrated on the last minute of play. For the team that's behind by a goal, it climbs to 8 goals per hour. For the team ahead by one, it climbs to 18 goals per hour.
The divergence between the tied teams and the rest has disappeared into the minute-by-minute noise. Maybe it will show up elsewhere. We can also get the shots and shot attempts per hour, like in this next graph.
With the shot attempts, we see a divergence, but not the one we would have expected from teams necessarily trying to preserve a tie. The worse situation a team is in, the more shot attempts they make. Even tied teams play very aggressively in the last minute. The team that's ahead makes fewer shot attempts, but has higher quality shots. The extreme case of this is in the last minute when the losing team has pulled their goalie - anything that would qualify as a shot is a goal against an empty net. It's possible that teams that are ahead are playing more conservatively because they have less to lose from a tie than the losing team has to gain, but that wasn't the hypothesis at the start.
With the newer data, not only can we get shots and shot attempts, but we can also isolate out the time and events in which a goalie was out of net, or when a team was on the powerplay. The following graphs show the goals and shot attempts for those situations. It's essentially the same story, except for the last minute. The one-ahead and one-behind lines can't be trusted in the last minute because there are very few times when the behind team didn't pull their goalie.
So are there 50 regulation minutes of action in an NHL game or 60? My personal grudge against the asymmetry introduced of the overtime loss rule makes me want to say 50, but I can't seem to back that up with recent data. File this one under negative results.
Statistical education, publishing, sports analytics, and game theory - everything that makes math useful in real life. Now carbon negative!
Featured post
Textbook: Writing for Statistics and Data Science
If you are looking for my textbook Writing for Statistics and Data Science here it is for free in the Open Educational Resource Commons. Wri...
Friday, 30 September 2016
Sunday, 28 August 2016
Why Chess? Part 1: Smaller Boards
Chess fascinates me; it's a
very pure board game, and it has existed in some recognizable form
for centuries. There's a couple of general questions I have about
chess that I return to occasionally, but haven't formally approached
until now.
1) Why is the game that
we consider chess the orthodox game and not some variant or
alternative?
2) How robust is existing
artificial intelligence to changes in chess?
Chess, at least in the
western world, fills a niche in the game market. It's a competitive
game between two players with no random chance and no physical
requirement. The rules of the game take an hour to learn, a day to
understand, a lifetime to master. In game design terms, chess has a
great deal of depth, but limited complexity.
It's not the only such game.
The game of Go, for example, has fewer rules, comparable depth, and
an effective and convenient method to handicap.
Also, what about variants of
chess? Would the game be less interesting or deep if the knight moved
in a 3-and-1 jump instead of a 2-and-1 jump? What if the board
dimensions were different? Chess has changed before, however slowly.
Is it just an accident of history that this is the particular game we
got, or is there something optimal about it?
I've been playing games of
different variations of chess starting with those available on the
Android app Chess Variants. Several of the variants avialable in this
app are games that use the same kinds of pieces as orthodox chess but
fewer of them, and on a smaller, simpler board. One clear pattern has
emerged after 50 plays across 3 variants: I'm horrible. I am
embarrassingly bad at chess compared to a computer opponent.
Mini chess (original).
The first variant I tried
was Martin Gardner's 5x5 variant, made in 1969. I played as white
(first) against an AI opponent (to be discussed in part 2) about 20
times. The result was 0 wins, 2 draws, and a heap of losses. The app
allows you to play as black, or even as both for local play, but I'm
stubborn.
The layout, shown in Figure
1, suggests a major advantage to black to a naive player like myself.
There are 7 possible moves white can make at the beginning of the
game. All of these moves let a piece be captured right away. What
else could explain my tremendous defeat?
Figure 1 – Martin Garner's
original Minichess
I looked up the game to see
if my suspicions on white's disadvantage were correct. They were not.
It turns out the Gardner's 1969 version of 5x5 chess is a weakly
solved problem. Each player can play perfectly and always draw or
win. If both are playing perfectly, the game ends in a draw.
Furthermore, the perfect play algorithm (also called the 'oracle'),
is a mere ~10 pages of if-then instructions.
The "weakly" in
weakly solved refers to the fast that a perfect strategy exists and
is known from the starting position of the game, but not necessarily
every position. So if you play sub-optimally to start a game, the
'oracle' doesn't necessarily cover your situation.
A paper by Mhalla, M., &
Prost, F. (2013) outlines this perfect strategy and talks about the
winning rates of each side in a sample of historical correspondence
games. The white player won slightly more of these games than black
did.
Mini chess (updated).
This is a 1989 update to
Gardner's 5x5 chess. It is identical except that the knight and
bishop have been swapped on the black side.
I played 5 games on this
version after playing the 1969 version. Games lasted longer and were
closer, but with a small sample and an experience confound, I'm not
confident in explaining why.
Micro Chess
This seems to be as minimal
as chess gets without being a chess puzzle instead of a game. The
layout, shown in Figure 2, only has one pawn per side. The pawn can
be moved two squares in its first move. However, the pawn cannot be
promoted to a queen. This seems reasonable as no player starts with a
queen.
There is a one move
checkmate for black:
White bishop to C2
Black knight to C3
White is in checkmate.
I was unable to win any
match at this (again as white) either, but I did reach a draw quite
often. My suspicion is that the knight is the most powerful piece,
and that this change in the relative strength of pieces could cause
an AI opponent to make poor trades if it was using piece valuations
from classic chess. No such luck.
The Alpha-Beta Algorithm
The AI used in this app
employs the alpha-beta tree algorithm, which is good for quick
computation, like on a phone, because it eliminates large sets of
possible actions quickly. It's also non-deterministic; it will choose
different actions in identical situations if there is no single
obviously best solution.
The alpha-beta algorithm is
not specific to chess. It could be used for any discrete choice
system, like Shogi or Go. However, it relies on a heuristic scoring
system. To use the algorithm, an AI needs a way to evaluate how good
or bad a consequence of that action is. Last time, I talked about
throwing off the AI by assuming it would under-value a knight. That
is, I was assuming that the value assigned to the consequence "lose
your knight" would be copied over from classic chess to micro
chess, and that this value could be exploited.
The Alpha-Beta algorithm
also has some tuning parameters that determine the quality of the
decisions made by it. By changing the number or depth (turns removed
from the current situation) of the possibilities that the algorithm
will evaluate. These parameters can be manipulated indirectly in the
Chess Variants app by a difficulty setting with four options: easy,
medium, hard, and fast.
The last setting, fast, was
the one I was using. In this case, the algorithm will evaluate
solutions until 1 second of processor time has been used. This means
the algorithm becomes harder to beat when it is provided more
processing power, so I can blame my equipment for my losses. The AI
may have been playing a close-to-perfect game on the simplified
boards, because the space of possible states was much smaller. I also
noticed that in orthodox chess matches, the AI got better as the game
progressed and pieces were removed from the board. I could frequently
take the opponent's queen without a sacrifice only to be crushed in
the end-game.
For existing pieces, the
value of retaining each piece, and having them in various positions
relative to an opposing king is well established by humans. That, I
suspect, is why Jocli, the platform used to make all these chess
variants online, only has variants that use pieces that exist in
orthodox chess and which alter the board - because the heuristics for
these (combinations of) pieces are well-established.
Next, I intend to look into
Chess 960, which is a variant played on an 8x8 board in which the
starting positions of non-pawn pieces are randomized. There are 960
possible starting arrangements that fit the restrictions (King is
between rooks, bishops are on opposite colours, black mirrors white,
etc. ), hence the name.
An AI may not be able to
adapt a few opening strategies from orthodox chess to chess 960, but
it fares well by treating any starting as a game already in progress
(even if that progress was impossible). If you introduced a common
chess puzzle piece, such as the grasshopper or princess, would an
entirely new set of heuristics be needed?
Relevant links:
Mhalla, M., & Prost, F.
(2013). Gardner’s minichess variant is solved. ICGA Journal,
36(4), 215-221.
https://jocly.com
The platform used for the Chess Variants app. Also playable in a web
browser.
https://en.wikipedia.org/wiki/Minichess
including Gardner's Minichess, and Microchess.
https://en.wikipedia.org/wiki/Fairy_chess_piece
list of unorthodox chess pieces used in puzzles and variants.
Still to explore:
Onitama
The Duke
Nightmare Chess
Alice Chess
The Encyclopedia of Chess
Variants, by David Pritchard
The Classified
Encyclopedia of Chess Variants, by
John Derek Beasley
Friday, 22 July 2016
The Globalization of Baseball
As I write this, pro baseball player Ichiro Suzuki is on the verge of getting his 3,000th big-league hit*.
There's a big asterisk there because Ichiro has nearly 3,000 hits in the North American leagues (Major League Baseball, MLB), but has about 4,300 if you include his hits in the professional Japanese leagues (Nippon Pro Baseball, NPB) as well. Ichiro came from Japan when that was a lot rarer, and perhaps at an older age (27), so it's hard to compare him fairly to players anywhere, other to say he's a global all-star.
Baseball is a global game, and it's becoming more international quickly. Here are some trends I've seen that show increasing ties between baseball in North America and the rest of the world. My hope is for more MLB exhibition games overseas, and eventually overseas inter-league play, especially with Nippon Pro Baseball.
1. The World Baseball Classic
In 2006, 2009, and again in 2013, the USA hosted a world tournament modeled after the FIFA World Cup. The tournaments themselves are a sign that international baseball is strong enough to continue without the support of the Olympics, but the results are an even stronger sign. The team from Japan won the 2006 and 2009 WBCs and placed third in 2013. Cuba won second place in 2006. The USA has not yet placed higher than fourth.
The next World Baseball Classic will be in 2017.
In 2006, the team from Cuba was only allowed entry to the United States because other countries refused to play without them.
2. The end of the Cuban embargo
Earlier this year, the United States officially ended its cold war remnant embargo on Cuba. Cuba has been a source of baseball talent for many years, but in order to play for MLB during the embargo, a player would need to defect to the United States, leaving their old life behind completely. Most of Cuba's world-class superstars may have already done this before the embargo was removed, but what about the ones that could have been professional baseball players, but didn't invest the training time because of the risks and costs involved in defection?
We will see many more Cuban professional players, but it will take a couple of years.
3. Twenty-20 Cricket
Until 2005, professional cricket matches lasted either eight hours, or up to five days. The Twenty20 format of cricket changed that by introducing a three-hour game. This change makes individual cricket matches a lot more appealing to North American sports fans, whom are already used to Football, Soccer, Hockey, and Baseball games which all last about three hours including non-play time.
There are substantial differences between cricket and baseball, but the skill sets are related. Both games focus their action on a single ball thrower and ball hitter, with the remaining play happening among the fielders (9 in baseball, 11 in cricket).
With time and television, this could lead to flow of talent between the sports, with amateur players trying to increase their play time and career prospects by being involved in both sports.
4. The precedent of Inter-League Play
Major League Baseball is split into two leagues of 15 teams each. This is a more meaningful break than that between conferences in hockey or basketball. The two leagues in MLB play by different sets of rules. There are several minor differences, and one big one: the designated hitter. In the American League (which includes the Toronto Blue Jays), there is a designated hitter whose only role is to bat. In the National League, there is no designated hitter, and the pitcher (thrower, like a bowler), must also bat.
Despite this rule difference, American and National League teams play against each other regularly. The game is played by the rules of the home team. Play between MLB and Japanese NPB would likely work the same way, and having the precedent of playing by the home team's rules makes that inter-league play simpler to establish.
5. The video appeal system
According to [2], the Japanese style is for umpires to huddle together and make a call through consensus; American decisions are made by the official in the best physical place to witness the event in question.
Starting in the 2016 season in MLB, when a call is appealed, the video footage is reviewed by a central panel of officials in New York and an ultimate decision is made there. This new system making the most important or contentious calls are made by consensus. This reduces the distance between the two styles.
6. The Posting System
Since 1998, MLB and NPL have used an agreement called the Posting System regarding NPL players leaving Japan and playing in MLB instead. The merits or weaknesses of this system are beyond me, but at least it sets a precedent of coordination between to the two league systems. Ichiro was the second player to join the MLB under the Posting System. See [3] for more.
7. Interleague play with Major League Soccer
European soccer has lots of interaction between leagues. The best of each of the English Premier League, Spain's La Liga, Germany's Bundesliga, and others earn places in the UEFA Champion's League. Back in North America, Major League Soccer (MLS) has been more isolated, but that is changing.
There is a growing trend of star players from UEFA teams playing in MLS when their best years are over. They're still competitive in MLS, and names like Kaka and David Beckham bring in crowds.
There are also more games happening between MLS teams and those from the English Premier League. This month, the Vancouver Whitecaps FC tied 2-2 against Crystal Palace, and the Seattle Sounders beat West Ham 3-0.
Any commercial success from these matches is a signal to Major League Baseball that they could do the same, and that there is fan interest in the overseas matches.
[1] Japanese Baseball Rules and Customs
http://factsanddetails.com/japan/cat21/sub141/item771.html
[2] On the cultural distances in baseball
http://www.umich.edu/~wewantas/brooke/differences.html
[3] The Posting System, which describes how players are transferred between leagues
https://en.wikipedia.org/wiki/Posting_system
There's a big asterisk there because Ichiro has nearly 3,000 hits in the North American leagues (Major League Baseball, MLB), but has about 4,300 if you include his hits in the professional Japanese leagues (Nippon Pro Baseball, NPB) as well. Ichiro came from Japan when that was a lot rarer, and perhaps at an older age (27), so it's hard to compare him fairly to players anywhere, other to say he's a global all-star.
Baseball is a global game, and it's becoming more international quickly. Here are some trends I've seen that show increasing ties between baseball in North America and the rest of the world. My hope is for more MLB exhibition games overseas, and eventually overseas inter-league play, especially with Nippon Pro Baseball.
1. The World Baseball Classic
In 2006, 2009, and again in 2013, the USA hosted a world tournament modeled after the FIFA World Cup. The tournaments themselves are a sign that international baseball is strong enough to continue without the support of the Olympics, but the results are an even stronger sign. The team from Japan won the 2006 and 2009 WBCs and placed third in 2013. Cuba won second place in 2006. The USA has not yet placed higher than fourth.
The next World Baseball Classic will be in 2017.
In 2006, the team from Cuba was only allowed entry to the United States because other countries refused to play without them.
2. The end of the Cuban embargo
Earlier this year, the United States officially ended its cold war remnant embargo on Cuba. Cuba has been a source of baseball talent for many years, but in order to play for MLB during the embargo, a player would need to defect to the United States, leaving their old life behind completely. Most of Cuba's world-class superstars may have already done this before the embargo was removed, but what about the ones that could have been professional baseball players, but didn't invest the training time because of the risks and costs involved in defection?
We will see many more Cuban professional players, but it will take a couple of years.
3. Twenty-20 Cricket
Until 2005, professional cricket matches lasted either eight hours, or up to five days. The Twenty20 format of cricket changed that by introducing a three-hour game. This change makes individual cricket matches a lot more appealing to North American sports fans, whom are already used to Football, Soccer, Hockey, and Baseball games which all last about three hours including non-play time.
There are substantial differences between cricket and baseball, but the skill sets are related. Both games focus their action on a single ball thrower and ball hitter, with the remaining play happening among the fielders (9 in baseball, 11 in cricket).
With time and television, this could lead to flow of talent between the sports, with amateur players trying to increase their play time and career prospects by being involved in both sports.
4. The precedent of Inter-League Play
Major League Baseball is split into two leagues of 15 teams each. This is a more meaningful break than that between conferences in hockey or basketball. The two leagues in MLB play by different sets of rules. There are several minor differences, and one big one: the designated hitter. In the American League (which includes the Toronto Blue Jays), there is a designated hitter whose only role is to bat. In the National League, there is no designated hitter, and the pitcher (thrower, like a bowler), must also bat.
Despite this rule difference, American and National League teams play against each other regularly. The game is played by the rules of the home team. Play between MLB and Japanese NPB would likely work the same way, and having the precedent of playing by the home team's rules makes that inter-league play simpler to establish.
5. The video appeal system
According to [2], the Japanese style is for umpires to huddle together and make a call through consensus; American decisions are made by the official in the best physical place to witness the event in question.
Starting in the 2016 season in MLB, when a call is appealed, the video footage is reviewed by a central panel of officials in New York and an ultimate decision is made there. This new system making the most important or contentious calls are made by consensus. This reduces the distance between the two styles.
6. The Posting System
Since 1998, MLB and NPL have used an agreement called the Posting System regarding NPL players leaving Japan and playing in MLB instead. The merits or weaknesses of this system are beyond me, but at least it sets a precedent of coordination between to the two league systems. Ichiro was the second player to join the MLB under the Posting System. See [3] for more.
7. Interleague play with Major League Soccer
European soccer has lots of interaction between leagues. The best of each of the English Premier League, Spain's La Liga, Germany's Bundesliga, and others earn places in the UEFA Champion's League. Back in North America, Major League Soccer (MLS) has been more isolated, but that is changing.
There is a growing trend of star players from UEFA teams playing in MLS when their best years are over. They're still competitive in MLS, and names like Kaka and David Beckham bring in crowds.
There are also more games happening between MLS teams and those from the English Premier League. This month, the Vancouver Whitecaps FC tied 2-2 against Crystal Palace, and the Seattle Sounders beat West Ham 3-0.
Any commercial success from these matches is a signal to Major League Baseball that they could do the same, and that there is fan interest in the overseas matches.
[1] Japanese Baseball Rules and Customs
http://factsanddetails.com/japan/cat21/sub141/item771.html
[2] On the cultural distances in baseball
http://www.umich.edu/~wewantas/brooke/differences.html
[3] The Posting System, which describes how players are transferred between leagues
https://en.wikipedia.org/wiki/Posting_system
Monday, 18 July 2016
Annual Report to Stakeholders 2015-16
As a grad student, I had to submit an annual report on my academic activities and the progress I was making in the PhD.
This year, I neglected to submit one, but since it's a good exercise in perspective, I’m doing a more general one here for myself and the major stakeholders in my life.
Executive Summary (informally, the ‘TL;DR’):
The two most important things of this year were meeting Gabriela and defending my PhD thesis. Both of those successes owe a great deal to the development and effort of the previous years than anything particular I did this year.
Personal:
This year I enjoyed a lot more success in making personal connections than professional progress; a year and a day ago I met Gabriela and we are very much in love. This may seem sappy and out of place in an annual report, but this is a life report and it’s easy to understate these sort of things because they’re difficult to quantify. Gabi is extremely important to me, and she deserves to be mentioned here. Establishing a relationship of this quality takes a lot of effort, but it has been tremendously rewarding.
Education (Learning):
They say completing a doctorate is a marathon, not a sprint. If that’s true, mine felt like the Boston Marathon; some parts crossed the finish line a lot sooner than others. The spirit of the thesis was done a year ago - written, submitted, and with a defense scheduled. This year, I added a new short chapter, and added a new layer of proofreading to the old chapters, but that’s it. While writing this extra chapter, which was an application of my new method to a database, I learned enough about the Canadian legal system to spark an appetite for more (so, very little).
For projects and curiosity, I’ve learned about meta-analysis, validation, item response theory, web-crawling, copy editing, and an introductory amount about the statistical method INLA.
Duolingo says I’m now about 20% fluent in Portuguese. In the near-term future, I hope to push that higher at a rate of 10% per month.
In the short/mid-term, I hope to gain more depth in using SAS (and take more SAS certification exams to solidify this), and to learn more about the law (and to take the LSAT, likewise).
Education (Teaching):
In the spring I lectured Stat 302 to about 300 students. I’ve already talked about this in detail in my postmortem. Student evaluations rated my teaching higher than both the school and faculty average in almost every category. Also, I got applause, so 2/2 there.
Only 10-20% of the material was able to be recycled from Stat 203 and from other notes. However, that means a LOT of new notes and assignments and assignments were added to my personal corpus of notes.
One of the two courses I’m teaching in the fall, Stat 305, will recycle 50% of its material from 302 and 203. Of the other half, I already have the notes of five lectures completed.
I also have been doing some assignment design for a 400-level course on big data methods that Luke Bornn is teaching in the fall, and I did a guest lecture for the 400-level Statistics of Sport course.
Research:
Lots of little scattered things.
Harsha, Tim, and I wrote another cricket paper. Rajitha, Tim, and I wrote a hockey paper. Kurt Routley (in Computer Science) and I co-presented a talk on data mining in hockey. A health sciences paper linking depression and sexually risky behaviour in South Africa was published after years of delay.
Not really shown in the thesis was the additional development of the Approximate Bayesian Computation work that Steve Thompson and I made in the last year. Very recently we got some coveted data from the CDC that we can use to revive some analyses from 2014-5.
I’ll be presenting some hockey research on the overtime loss rule at the Cascadia Sports Conference in Vancouver in September, and Paramjit and I will be reviving a old paper on this with some new depth.
I’ve met with at least five other groups about other research projects all across the board, but without any deliverables that I can mention here.
Publishing:
4 papers were refereed: 3 for the Open Journal of Statistics, 1 for the Canadian Journal of Statistics.
6 papers were copy-edited: 3 for networking purposes, 1 that did the analysis for as well, 1 at the request of a faculty member, and 1 as a skill test for the Canadian Journal of Statistics.
26 blog posts were made and kept, not including this one.
Game Design:
I haven’t posted the details here, but a very basic (pre-alpha) working prototype of Scrabble Dungeon on PC. A player place tiles in a crossword grid from a designated starting tile to an ending point in order to win the game. Wall tiles, pre-placed tiles, and gem pickups are functioning. Boards of any layout and size can be loaded into the game that contain these elements. Parts of the card system are working, and two of the cards (life relic and meta relic) are included.
The goal is to eventually get the game onto the Android Play Store, but I may also settle for a PC version if it’s less of a headache.
Friday, 24 June 2016
Thesis Defence Notes - Approximate Bayesian Computation
These are notes from the slides that were given during my defense. I've clarified some points since then.
The other half of the notes, on the cricket simulator, are found here.
------------------
Approximate Bayesian Computation (ABC) is a method of estimating the distribution of parameters when the likelihood is very difficult to find. This feature makes ABC applicable to a great variety of problems.
Step 1: Select a prior joint distribution F(theta) for the parameters of interest.
Step 3: Compute T(s), a statistic, or set of statistics, from the sample.
In
Figure 2, we see sample B's effect. This sample's statistic is close to
that of the observed sample. Therefore, point B is close to the line.
The conditional density is much steeper around sample B's parameter
value. This is because the probability density increases and decreases a
lot along the blue line.
The other half of the notes, on the cricket simulator, are found here.
------------------
Approximate Bayesian Computation (ABC) is a method of estimating the distribution of parameters when the likelihood is very difficult to find. This feature makes ABC applicable to a great variety of problems.
The classical ABC
method can be summarized as:
Step 1: Select a prior joint distribution F(theta) for the parameters of interest.
Step 2: Observe a
sample s from the population you wish to characterize.
Step 3: Compute T(s), a statistic, or set of statistics, from the sample.
Step 4: Repeat the
following many times
4A: Generate random
parameter values p from F(theta)
4B: Use the values
p to simulate a sample s'
4C: Compute the
distance between T(s') and T(s), the statistics taken from the
simulated and observed samples, respectively.
4D: If the
difference is less than some tuning value, epsilon, then accept the
values p.
Step 5: The
collection of values p from all accepted values is taken as the
posterior distribution of the parameters of interest.
Step 6: If the
parameters of interest are continuous, a smoothing method is applied
to this collection to produce a continuous posterior distribution.
The distance between
two statistics can be determined by Manhattan or Euclidean distance,
or a weighted distance if deviations between some statistic values
are more important than others.
The tuning parameter
epsilon determines the balance between accuracy and computational
efficiency. A small epsilon will ensure that only generated samples
that are very similar to the observed sample will be used. That is,
only samples that produce statistics very close to the real sample's
statistics. However, many samples will be rejected.
A large epsilon will
ensure that many samples will be produced, but some of those samples
will have statistics that deviate from the observed sample. Since the
process of producing new samples could be time-consuming, depending
on the application, this may be a worthwhile trade-off.
Compared to
classical Approximate Bayesian Computation method, I made some
modifications.
- Instead of having
an accept-reject rule, I opted to use every sample but assign weights
to the parameters behind each sample based on the distance between
T(s') and T(s).
- The weights and
smoothing mechanism are determined through a Kernel Density Estimator
(KDE)
Specifically, every
generated sample is gets treated as a point mass in a space across
the statistic values and parameter values.
Consider the example in
the following MS-Paint diagrams.
In Figures 1-3, we have a sample with a
single statistic value, T(s), vertical, and a single parameter of
interest, theta, horizontal. We don't know the parameter value of the
observed sample, so we represent the observed sample as a blue
horizontal line.
Points
A and B represent the statistic and parameter values from each of two
generated samples (also A and B, respectively). These are points instead
of lines because these samples are simulated using known parameter
values.
The
gray area at the bottom of each figure is the conditional density of
the parameter of the observed sample. The thin lines around points A and
B are the contour lines of the probability density, with peaks at the
points and decreasing outwards.
![]() |
| Figure 1: A generated sample that's far from the observed sample. |
In
Figure 1, we see the effect of generated sample A on the parameter
estimate. The statistic from sample A is far from the statistic of the
observed sample, so point A is far from the line. As a result, the
probability density does increase or decease much along the line, and
therefore the conditional density of the parameter estimate is diffuse,
as shown by the shallow gray hill.
![]() |
| Figure 2: A generated sample that's close to the observed sample. |
![]() |
| Figure 3: The combined estimate from both samples. |
In
Figure 3, we see the cumulative effect of both samples. The conditional
density from both resembles that from generated sample B. This is
because sample B's effect was given more weight. Generated samples that
more closely resemble the observed sample contribute more to the
parameter estimate.
I used this method
on two applications
1. A theoretical
network based on a network of sexual partners in Africa.
2. A real network of
precedence citations between decisions of the Supreme Court of
Canada.
The theoretical
dataset was based on a respondent driven sample. An initial seed of
people was selected, presumably by a simple random process. Members
of this seed were polled about the number of sexual partners they had
in the previous year, their HIV status, and their sexual orientation.
For each reported partner, contact information was taken in order to
recruit these partners into the sample as well. If the recruitment
pool was exhausted before the desired number of respondents, new seed
members were found.
Like the basis
dataset, we assumed that the sample we were given contained the
mentioned covariates of those polled, including the number of
partnerships, and we assumed that only the partnerships that led to
successful recruitment were available. This implies that large parts
of the network could be hidden to us, such as partnerships that 'lead
back' into the sample already taken.
Consider these two
figures.
Figure 4 is from
a sample of a network with identifying information about every
reported partnership is given. Figure 5 is from
the same sample, where only the partnerships that led to recruitment
are known. Notice that Figure 4 includes lines going out to points that we did not sample directly. Notice also that Figure 4 includes cycles, in which you could go from one point to itself by following the lines and without backtracking.
We don't see these cycles in Figure 5, the recruitment-only network, because a person cannot be recruited if they are already in the sample. A cycle might be a triangle between persons J, K, and L, where all three are connected. Person J can recruit both K and L through those connections, but K cannot recruit L, so we never see the K-L connection. What we see is one person, J, with two distinct partners instead of the whole picture.
Socially, the K-L connection is key information, and mathematically this lack of cycles makes estimation of anything about this network a lot harder.
![]() |
| Figure 4: A network with identifying information from the sample. |
![]() |
| Figure 5: A network with only recruitment information from the sample. |
Nevertheless, I used ABC to estimate some features (parameters) of the population that this sample came from.
The parameters of
interest were:
- The number of
members in the population, (prior: geometric, mean 2000, truncated
minimum 400)
- The probability of
an HIV infection passing along a partnership, (prior: uniform 0 to
0.3)
- The proportion of
this network that was already infected before any of these
partnerships (prior: uniform 0 to 0.5)
- The 'closeness
preference', a parameter governing the propensity to select partners
that are similar to oneself. Zero is no preference, 10 is a strong preference, and a negative number represents a general dislike for those similar to you. (prior: uniform -2 to 10)
I conducted two rounds of Approximate Bayesian Computation by producing 500 and 2500 samples, respectively.
The results are here. The yellow and red represent regions of high conditional probability. ABC allows us to narrow down the likely value of the real parameters to these yellow and red regions.
Parameter sets at points all across these graphs were tried, but only those in the non-blue regions produced samples that were anything like the observed sample.
![]() |
| Figure 6: Coloured contour maps of conditional densities, social network data. |
From these, we can calculate marginal means to get our parameter estimates.
| Parameter | True Value | Mean (Initial Round) | Mean (Final Round) |
| Population Size | 1412 | 2049 | 2094 |
| Initial Infection Rate | 0.467 | 0.399 | 0.374 |
| Transmission Chance | 0.093 | 0.175 | 0.201 |
| Closeness Preference | 7.298 | 6.753 | 9.352 |
The second
application was on the precedence citations of decisions in the
Supreme Court of Canada (SCC). Because this is real data, I am not
able to find the ground truth with which to compare my results, but I
can showcase how the method behaves with real data.
When this data was
collected, there were 10623 documents produced by the SCC, 9847 of
which are cases (e.g. disputes between two parties). These decisions
are among the more than 3,000,000 cases and other documents recorded
in the Canadian Legal Information Institute (CanLII). Figure 7 shows part of the network of SCC cases.
![]() |
| Figure 7: Induced subgraph of cases and citations in Supreme Court of Canada |
Cases span from 1876
to 2016, with more recent cases represented as points near the top.
The larger points are those that have been cited often in Canadian
law. Lines between points represent citations between SCC cases. Only
1000 cases are shown here, so the true network between SCC cases has
roughly 10 times as many nodes and 100 times as many links.
My general interest in this dataset is to identify the features that make a law prone to being obscure over a long time.
I modelled each SCC case as 'vendor' that was trying to 'sell' citations to future Canadian legal cases. Each SCC case had an attractiveness a, where
I modelled each SCC case as 'vendor' that was trying to 'sell' citations to future Canadian legal cases. Each SCC case had an attractiveness a, where
and where
βirrel
: Parameter determining the
decay in attractiveness over time (per 5 years without a citation).
βpa
: Parameter determining a
preferential attachment factor, assuming that a case becomes more
well-known whenever it is cited.
βcorp
, βcrown
, βdis
: Parameters
determining increased/decreased attractiveness based on whether a
case involved a corporation, the crown, or dissent between Supreme
Court Judges, respectively.
what I found was less clear that in was in the synthetic data case, as shown in Figure 8.
![]() |
| Figure 8: Coloured contour maps of conditional densities, Supreme Court of Canada data. |
It's impossible to read the variable names in this figure, I'm afraid. The jist, however, is that...
- a case that is not cited in five or more is less and less likely to receive citations over time.
- a case that is cited often is more likely to receive citations in the next five years.
- a case that involves a corporation is less likely to be cited.
- a case that involves the crown is more likely to be cited.
- a case that had dissenting opinions by some of the judges is more likely to be cited.
I read this: Spatial and Spatio-Temporal Bayesian Models with R-INLA
Spatial and Spatio-temporal Bayesian Models with R-INLA, by Marta Blandiardo and Michela Cameletti is a short textbook that introduces INLA (Integrated nested Laplace approximations) and some preliminaries, and works through the math and R-code of a variety of problems that the R-INLA package can tackle. Several non-spatial regression models are also covered in enough detail to get you started on R-INLA in general.
Tuesday, 21 June 2016
Thesis Defence Notes - Cricket Simulator
These are notes from the 'lost slides' on cricket that I didn't have time to cover in my PhD defense, which I completed two weeks ago.
The other half of the notes, on approximate Bayesian computation (ABC) for networks, is found here.
------------------
Cricket is a sport popular in the emerging economies of the Indian subcontinent. Most of my cricket work has focused on the Twenty20 format of Cricket, in which matches are designed to last only three hours, roughly the same time as matches in other popular team sports. This format has only been played professionally for about 10 years, and it growing quickly in terms of spectator and commercial interest. The intricacies of this format are also poorly understood, which provides many good research opportunities.
In the Twenty20 format, each team is allowed one innings to score runs. (Yes, 'innings', not 'inning') That inning is over if either...
1) 10 of the 11 players are dismissed (a dismissal is also called an 'out' or a 'wicket'), or
2) 120 'fair' balls are thrown. A group of 6 throws is called an 'over', making 20 overs per innings. Hence the name Twenty20.
A small number (typically fewer than 10) of throws per innings do not count against the limit of 120 because they were not thrown in a prescribed manner. A small number of throws also incur a one-run penalty that is added to the These cases are similar to 'balls' and 'hits-by-pitch' in baseball, respectively.
Each of these 120+ throws has a discrete result that we simplified into six categories: Wicket, 0 Runs, 1 Run, 2-3 Runs, 4-5 Runs (Ground Rule Double), and 6 Runs (Home Run). Cases where 3 runs and 5 runs occurred were rare, so we treated them as a fixed proportion of 2-3 runs (~6.4%) and 4-5 (~1.5%) runs respectively. Likewise, throws not counting against the 120 limit, and those resulting in a penalty run, were treated as a fixed proportion of each of the six categories.
Here is table of a team's batting and bowling summaries of a recent T20I match from ESPN CricInfo.
All of these metrics, such as 'Strike Rate', are based solely on the number of events (e.g. balls faced, times dismissed, runs scored), without respect to when they happened. The inherit weakness of all these metrics is that they treat each throw as an identical event, independent of the number of wickets and throws remaining. For the baseball crowd, consider the difference between overall batting average, and the batting average with runners in scoring position.
Reality is more complex. Consider this:
This is a heat map of the empirical chance of any throw/ball/pitch ending as a six (a home run in baseball terms) as a function of overs and wickets taken. All games start in the upper-left corner, with 20 overs and 10 wickets remaining. From there, plausible game situations 'fan out', where games with situations following the top of the fan are those where relatively few batters are dismissed by the time most of the overs are used.
In these games, many sixes occur in the late game. Scoring a six involves hitting the ball with great power, which involves taking a greater risk of a dismissal. Since in these low-dismissal games, remaining throws are a more precious resource than remaining wickets, this high-risk, high-reward strategy is rational.
Here's the raw probability of scoring a four, which is similar to a ground rule double in baseball. This is a ball that touches the ground in bounds, but bounces or rolls out of bounds. As such, the fielders have an effect on the outcome that they cannot usually have on sixes. Notice that the general pattern of fours are similar to those of the sixes, except for the major drop at between the 6th and 7th overs. From the 7th over onwards, the players in the field are more restricted, and so more balls are able to roll out of bounds to score 4 runs
Here's the major confound: A batting player continues to bat until dismissed or until the innings ends. So a starting batter will rarely, if ever, see a situation where there are few wickets remaining. Likewise, a player batting late in the lineup will never enjoy the game situations with many wickets remaining. Therefore, a late-batting player has less opportunity to aim for those sweet, sweet, sixes.
We developed a system for estimating 'situational effects', which are the relative propensities towards a given outcome (i.e. wicket, 0, 1, 2-3, 4-5, 6) holding batter and bowler constant. These effects were estimated by first estimating odds ratios of events between 'adjacent' situations (those differing by one over or one wicket), within individual player records.
The data in these heatmaps are used to find these situational effects, which control for individual player effects.
Having these situational effects in place, we were able to estimate a great deal of additional parameters. First, we estimated the probability of any given player to produce a given outcome at some 'baseline' situation. To do this, we gave each ball faced, or ball thrown for bowlers, a weight. If a six happened in a situation when sixes were more likely (again, controlling for player difference), a small weight was given. If a six happened at a time when sixes were rare, a large weight was given. This way, we could compare batters and bowlers to each other, even we they played under very different situations.
To knit this all together into estimates of a players batting or bowling outcomes at a 'baseline' situation, we used a Metropolis-Hastings within Gibbs sampling method. More specifically, we draw a set of values from a Dirichlet distribution (an extension of the Beta distribution to multinomial cases), and propose those as a player's outcome probabilities at baseline. Then we compute the likelihood of these probabilities given the player's history and the estimated situational effects. Proposals that fit the data better have a higher likelihood, and these are given more weight in the final estimate. The final estimate for a player is an aggregate of thousands of these proposals.
I treated situational effects as normalized multiplicative effects on these baseline probabilities. in the following formula,
the situational effects are the tau owj's and pi70j is a player's ability at the baseline situation (7 overs, 1st wicket). The left-hand part, piowj, represents the probability of any player getting any outcome in any situation (o overs, w wickets). From here, making a simulation was just a matter of making a Markov Chain that followed the rules of the game.
This simulator has been the basis of five published or submitted papers, including the two in the first half of my thesis (bolded)
Silva, R., Davis, J., & Swartz, T. B. (2016). Mismatches in Twenty20 cricket. In submission.
The other half of the notes, on approximate Bayesian computation (ABC) for networks, is found here.
------------------
Cricket is a sport popular in the emerging economies of the Indian subcontinent. Most of my cricket work has focused on the Twenty20 format of Cricket, in which matches are designed to last only three hours, roughly the same time as matches in other popular team sports. This format has only been played professionally for about 10 years, and it growing quickly in terms of spectator and commercial interest. The intricacies of this format are also poorly understood, which provides many good research opportunities.
In the Twenty20 format, each team is allowed one innings to score runs. (Yes, 'innings', not 'inning') That inning is over if either...
1) 10 of the 11 players are dismissed (a dismissal is also called an 'out' or a 'wicket'), or
2) 120 'fair' balls are thrown. A group of 6 throws is called an 'over', making 20 overs per innings. Hence the name Twenty20.
A small number (typically fewer than 10) of throws per innings do not count against the limit of 120 because they were not thrown in a prescribed manner. A small number of throws also incur a one-run penalty that is added to the These cases are similar to 'balls' and 'hits-by-pitch' in baseball, respectively.
Each of these 120+ throws has a discrete result that we simplified into six categories: Wicket, 0 Runs, 1 Run, 2-3 Runs, 4-5 Runs (Ground Rule Double), and 6 Runs (Home Run). Cases where 3 runs and 5 runs occurred were rare, so we treated them as a fixed proportion of 2-3 runs (~6.4%) and 4-5 (~1.5%) runs respectively. Likewise, throws not counting against the 120 limit, and those resulting in a penalty run, were treated as a fixed proportion of each of the six categories.
Here is table of a team's batting and bowling summaries of a recent T20I match from ESPN CricInfo.
All of these metrics, such as 'Strike Rate', are based solely on the number of events (e.g. balls faced, times dismissed, runs scored), without respect to when they happened. The inherit weakness of all these metrics is that they treat each throw as an identical event, independent of the number of wickets and throws remaining. For the baseball crowd, consider the difference between overall batting average, and the batting average with runners in scoring position.
Reality is more complex. Consider this:
This is a heat map of the empirical chance of any throw/ball/pitch ending as a six (a home run in baseball terms) as a function of overs and wickets taken. All games start in the upper-left corner, with 20 overs and 10 wickets remaining. From there, plausible game situations 'fan out', where games with situations following the top of the fan are those where relatively few batters are dismissed by the time most of the overs are used.
In these games, many sixes occur in the late game. Scoring a six involves hitting the ball with great power, which involves taking a greater risk of a dismissal. Since in these low-dismissal games, remaining throws are a more precious resource than remaining wickets, this high-risk, high-reward strategy is rational.
Here's the raw probability of scoring a four, which is similar to a ground rule double in baseball. This is a ball that touches the ground in bounds, but bounces or rolls out of bounds. As such, the fielders have an effect on the outcome that they cannot usually have on sixes. Notice that the general pattern of fours are similar to those of the sixes, except for the major drop at between the 6th and 7th overs. From the 7th over onwards, the players in the field are more restricted, and so more balls are able to roll out of bounds to score 4 runs
Likewise,
the batting team gets really desperate in the last few overs, so they
try reckless moves that frequently end in a wicket (a dismissal of a
batting player). We also see wickets getting more likely when there are very few batters left. This seems counter to the intuitive strategy - that running out of batters would cause the remaining batters to be more cautious. Instead, you're seeing the effect of putting the worst batters on a team last in the batting order - they just get dismissed more often.
Here's the major confound: A batting player continues to bat until dismissed or until the innings ends. So a starting batter will rarely, if ever, see a situation where there are few wickets remaining. Likewise, a player batting late in the lineup will never enjoy the game situations with many wickets remaining. Therefore, a late-batting player has less opportunity to aim for those sweet, sweet, sixes.
We developed a system for estimating 'situational effects', which are the relative propensities towards a given outcome (i.e. wicket, 0, 1, 2-3, 4-5, 6) holding batter and bowler constant. These effects were estimated by first estimating odds ratios of events between 'adjacent' situations (those differing by one over or one wicket), within individual player records.
The data in these heatmaps are used to find these situational effects, which control for individual player effects.
To knit this all together into estimates of a players batting or bowling outcomes at a 'baseline' situation, we used a Metropolis-Hastings within Gibbs sampling method. More specifically, we draw a set of values from a Dirichlet distribution (an extension of the Beta distribution to multinomial cases), and propose those as a player's outcome probabilities at baseline. Then we compute the likelihood of these probabilities given the player's history and the estimated situational effects. Proposals that fit the data better have a higher likelihood, and these are given more weight in the final estimate. The final estimate for a player is an aggregate of thousands of these proposals.
I treated situational effects as normalized multiplicative effects on these baseline probabilities. in the following formula,
the situational effects are the tau owj's and pi70j is a player's ability at the baseline situation (7 overs, 1st wicket). The left-hand part, piowj, represents the probability of any player getting any outcome in any situation (o overs, w wickets). From here, making a simulation was just a matter of making a Markov Chain that followed the rules of the game.
This simulator has been the basis of five published or submitted papers, including the two in the first half of my thesis (bolded)
Davis, J., Perera, H., & Swartz, T. B. (2015). A simulator for Twenty20 cricket. Australian & New Zealand Journal of Statistics, 57(1), 55-71.
Davis, J., Perera, H., & Swartz, B. (2015). Player evaluation in Twenty20 cricket. Journal of Sports Analytics, (Preprint).
Perera, H., Davis, J., & Swartz, T. B. (2016). Optimal lineups in Twenty20 cricket. Journal of Statistical Computation and Simulation, 1-13.
Perera, H., Davis, J., & Swartz, T. B. (2016). Assessing the impact of fielding in
twenty20 cricket. In submission.
twenty20 cricket. In submission.
Silva, R., Davis, J., & Swartz, T. B. (2016). Mismatches in Twenty20 cricket. In submission.
Subscribe to:
Posts (Atom)




















