Home | About | Tournament Winning Decklists | Forums

Bayesian Analysis of Running the Hand


#1

Hello all.
I’ve always wondered about how many times one should run a hand until he/she gives up before not finding an agenda. I did some quick Bayesian analysis using R to find some probabilities. My assumptions that there is a fresh game state, with 49 unknown cards (corp deck size), and 11 agendas left in the deck. These numbers can be easily changed in the code.

I will post the full output (and the code) below, so that you can draw whatever conclusions you’d like from it. I think one of the more interesting things is, given that the corp has 5 cards in hand,

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.42753

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.5723637

so running two additional times without seeing an agenda only increases the likelihood that the corp has no agendas by ~15%.

I am very confident in my math (I am a PhD student in statistics and probability, and I’ve coded this type of thing several times before), but feel free to argue if you think there is a mistake. Also I used R which is a free easy to use and download programming language. Like I said the numbers are easily modifiable to figure out other probablities that you’d like. It is possible that 11 agendas is a high number. It may be interesting to set the deck size to 40 to see what happens in a TWIY FA deck.

Here is the full output: (code is at the end, and forgive the ugliness. You can’t do much with R to make it pretty)

------1 cards in hand------

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 1
probability of 1 agendas in hand given that none were seen
[1] 0

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 1
probability of 1 agendas in hand given that none were seen
[1] 0

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 1
probability of 1 agendas in hand given that none were seen
[1] 0

------2 cards in hand------

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.8135593
probability of 1 agendas in hand given that none were seen
[1] 0.1864407
probability of 2 agendas in hand given that none were seen
[1] 0

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.8971963
probability of 1 agendas in hand given that none were seen
[1] 0.1028037
probability of 2 agendas in hand given that none were seen
[1] 0

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.9458128
probability of 1 agendas in hand given that none were seen
[1] 0.05418719
probability of 2 agendas in hand given that none were seen
[1] 0

------3 cards in hand------

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.6592636
probability of 1 agendas in hand given that none were seen
[1] 0.3085915
probability of 2 agendas in hand given that none were seen
[1] 0.03214494
probability of 3 agendas in hand given that none were seen
[1] 0

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.7528365
probability of 1 agendas in hand given that none were seen
[1] 0.2349277
probability of 2 agendas in hand given that none were seen
[1] 0.01223582
probability of 3 agendas in hand given that none were seen
[1] 0

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.8240929
probability of 1 agendas in hand given that none were seen
[1] 0.1714425
probability of 2 agendas in hand given that none were seen
[1] 0.004464648
probability of 3 agendas in hand given that none were seen
[1] 0

------4 cards in hand------

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.5320373
probability of 1 agendas in hand given that none were seen
[1] 0.3816789
probability of 2 agendas in hand given that none were seen
[1] 0.08120828
probability of 3 agendas in hand given that none were seen
[1] 0.005075518
probability of 4 agendas in hand given that none were seen
[1] 0

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.6185261
probability of 1 agendas in hand given that none were seen
[1] 0.3327939
probability of 2 agendas in hand given that none were seen
[1] 0.04720481
probability of 3 agendas in hand given that none were seen
[1] 0.00147515
probability of 4 agendas in hand given that none were seen
[1] 0

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.6933428
probability of 1 agendas in hand given that none were seen
[1] 0.2797864
probability of 2 agendas in hand given that none were seen
[1] 0.02645735
probability of 3 agendas in hand given that none were seen
[1] 0.000413396
probability of 4 agendas in hand given that none were seen
[1] 0

------5 cards in hand------

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.42753
probability of 1 agendas in hand given that none were seen
[1] 0.4180293
probability of 2 agendas in hand given that none were seen
[1] 0.1363139
probability of 3 agendas in hand given that none were seen
[1] 0.01740177
probability of 4 agendas in hand given that none were seen
[1] 0.0007250739
probability of 5 agendas in hand given that none were seen
[1] 0

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.5024754
probability of 1 agendas in hand given that none were seen
[1] 0.3930475
probability of 2 agendas in hand given that none were seen
[1] 0.09612574
probability of 3 agendas in hand given that none were seen
[1] 0.008180914
probability of 4 agendas in hand given that none were seen
[1] 0.0001704357
probability of 5 agendas in hand given that none were seen
[1] 0

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.5723637
probability of 1 agendas in hand given that none were seen
[1] 0.3581725
probability of 2 agendas in hand given that none were seen
[1] 0.0656974
probability of 3 agendas in hand given that none were seen
[1] 0.003727512
probability of 4 agendas in hand given that none were seen
[1] 3.882825e-05
probability of 5 agendas in hand given that none were seen
[1] 0

And here is the code:

a <- 11 # #agendas in corp deck
N <- 49 # #corp deck size
for(n in 1:5){
  message("")
  message("------",n," cards in hand------")

  for(t in 1:3){ #t is the number of runs without seeing an agenda
    message("")
    message("---",t, " runs without seeing an agenda")
    d <- 0
    for(i in 0:n){
      d <- d+((n-i)/n)^t*dhyper(i,a,N,n) #denominator for bayes theorem
    }
    for(j in 0:n){
      message("probability of ", j, " agendas in hand given that none were seen")
      print( ((n-j)/n)^t*dhyper(j,a,N,n)/d) #numerator / denominator
    }

  }

}

#2

I did the same thing to a lesser extent. Understanding probabilities can definitely be useful for making correct decisions. Thank you for this guide!


#3

you’re welcome! obviously these can’t be calculated during the course of a game, but understanding the fundamentals behind the probabilities can influence choices in a positive way.


#4

This is very awesome, thank you! Any thread that begins with ‘Bayesian Analysis of’ is excellent in my book. :smile:

In this analysis, we took a prior of having an average amount of agendas in the hand, compared to the agenda count and deck size. That is, this represents the probabilities, if the corp has drawn some cards into their hand, and hasn’t played any cards yet.

Of course, there is another level that we can try to reach, where we model how the probabilities change as the corp draws cards and then plays NON agenda cards out of the hand. Or how it changes as agendas get scored.

As cards are drawn and some of them (ice, operations) get played, the agenda density of the remaining cards in the hand increases, and thus our prior for the probability of agendas in the hand would increase as well. If the corp scores an agenda form hand, or the runner hits some cards on R&D and takes the agendas out of them, then the prior will decrease. Strong players intuitively understand this, and will tend to run HQ more if it seems agendas are piling up, or will avoid it if there wasnt a good chance for them to be there.

How do the numbers look with different priors for the agenda hand density?

Thanks!


#5

Let a be the number of agendas remaining and N be the number of unseen cards.

Suppose the corp player played a number of operations and we saw ice and assets perhaps, so that N=40 and a = 11 (still). Then, here are some probabilities for if the corp has 5 cards in hand

—1 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.3571472

—2 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.4334311

—3 runs without seeing an agenda
probability of 0 agendas in hand given that none were seen
[1] 0.5067707

I think 11 is a reasonable number. I looked at the first 4 decklists on the stimhack page, and they had 12, 13, 10, 11 agendas respectively.

Edit: Maybe I can make a graph for various N. I will do that now.


#6

Isnt it actually different than that? N=40, a=11 gives the distribution for a 40 card deck with 11 agendas in it.

But the situation where I draw some cards and then specifically play out the NON-agenda cards that I draw, is a bit different.

For example, I start with 5 cards. I draw 3 cards and play 3.

Now its actually like a case where N=49, a=11, but I have 8 cards in hand (not 5), but three of them cannot be picked from the access! (The hypergeometric distibution probably cant be used to model that?)

Look at it another way:

I draw 5 cards. My deck is 11/49 agendas. My expected value of agendas in hand is 5 * 11/49. And the hypergeometric distribution gives the probabilities.

But now I draw 3 and play 3 non agendas.

My expected value of agendas in hand is now 8 * 11/49. But I still have just 5 cards in hand, so when you go to access your odds have improved a lot.


#7

I’m not sure why it’s 811/49. I would think in that case that it would be 511/46.

I was letting N be the number of unknown cards. So in a new game state, it will be 49. If the corp plays two ice and an operation, now N is 46. If the corp draws three cards on his next turn and discards two, N is still 46. If you run archives to see two non-agenda cards discarded, then N is 44. Each time your distribution will change from a hypergeometric(N=49) to hypergeometric(N= 49-however many cards are now known).

I’m fairly confident that that is how it should be calculated (that’s how it is calculated in poker), but if you still think it’s wrong please let me know because I am curious. Maybe I am misunderstanding your argument.

In any case, I made a graph.

The x-axis is the # of unknown cards. The y-axis is the probability of the corp having 0 agendas given that you ran and didn’t get an agenda. From top to bottom, the graphs are 1 agendas remaining, then 2, etc, with the bottom curve being 13 agendas remaining.

edit: the numbers in the original post with multiple runs may be off a tad, since I realized that I didn’t account for knowing certain cards in the opponent’s hand on the second and third runs. I still think the numbers should be very close to the real values, just off by a percentage or two. It would probably be very time consuming to create a model that accounts for that, however, the ones that include only one run are correct.


#8

This is really neat work in general, Jimmy, but I was going to point this out and then you beat me to it :). “Unique Accesses” is key, and also why R&D pressure works really well. We’ve probably all had those runs where we access Ice Wall from HQ nine or ten times in a row and we’re wondering exactly how many copies there are in there ;).

R&D is at least different every turn!


#9

Let me try to explain differently.

Lets say I spend a whole bunch of turns of the game drawing TWENTY new cards, plus my starting five. I have drawn 25 cards, or half my 49 card deck. Out of the 11 agendas in my deck, the number I have drawn so far will be a probability distribution of hypgeomdist with N=49 (cards in deck), n=25 (draws), a=11 (agendas in deck). Its going to be centered around 5-6.

During that time I play out 20 non-agenda cards that I draw. My hand is now 5 cards. If I have drawn less than 5 agendas, then my hand is X agendas and 5-X other cards. If I have drawn more than 5 agendas, then I discarded the extras into archives (for the sake of this example). What are the chances that a card you access in my hand is an agenda? Its really high. Its NOT simply hypgeomdist(N=29, n=5, a=11). Its NOT the same as if I had drawn 5 random cards out of a 29 card deck with 11 agendas, its actually higher than that! In fact, there is a pretty good chance that my hand is entirely agendas.

Its a hard problem to model, because I have drawn a bunch of cards, and then filtered out the non agendas, and as a result my hand is hoarding the agenda draws of a whole bunch of draws, within just a few cards.

This probability distribution (that I am not exactly sure how to determine) determines the prior for my Bayesian analysis. (That is, I can no longer use a simple hypgeomdist for my prior). Then, as I access cards from that hand and see non-agendas, I update my probabilities that the unseen cards are agendas, based on Bayes’ Law.

Did that make sense?
(Again, this is a more difficult problem than what you were originally going for).


#10

I work in R as well and am using it to dig into the OCTGN data, although I don’t have the same level of stats background as you do (I’m an engineer). So I totally stole your code! I also have a question:

I’ve been working on some multivariate hypergeometric distribution estimates to figure out the odds of drawing 1+ of a certain card given that you also drew 1+ of a different card – for example, the odds of drawing 1+ Biotic Labor given that you drew 1+ AstroScript. I’ve got a cumbersome spreadsheet that does conditional probabilities, which is all well and good, but it would be nice to get something generalizable. Have you ever used the BiasedUrn package for multivariate hypergeometric distribution calculations? If so, I’ll have follow-up questions. :wink:


#11

@Ajar, send me a pm to explain your problem more in detail. I’ve been working all day and my mind is exhausted from too much statistics + probability.

@Alexfrog, on the same note, I do get what you’re saying, but I’m not sure I can process how to deal with it right now. I will think about it and write a better reply tomorrow. It does make sense.


#12

Alex raises a good point. Basically the hand has a higher agenda density than the deck because some ice/operations are played out first. Would something like this work?

Start with the 11/49 assumption. 22.44% of the deck is agendas. Turn 1 hand of 6 cards that is roughly 1.34 agendas. they play two non agendas now they have 1.34/4 agendas in hand right? If you take that 33.67% could you approximate the probabilities with a=15, N=46 using your program?


#13

It’s really difficult to turn this into a definitive guide to how many times you should run HQ, (not that this is what it’s trying to be), based on the game state and how your opponent is playing, how expensive it is to get into HQ, what else you could be spending your time doing, how important is it for them the agenda in their hand. Are your HQ runs going to get cheaper or more expensive? Will running HQ a bunch give them a scoring window? Are they likely stocked up and probably going to bail when they draw Jackson? I’m just going to keep running once or twice every once in a while, when it makes sense. All this math and it can’t even tell me what to do!

Good work though, it’s certainly interesting.


#14

Yeah its difficult. I think that it would be a modification to the bayesian prior, of what is in the hand. (That is, rather than simply being 5 randomly selected cards out of N, with a agendas, that we have to replace that with something else. But I dont know exactly how to replace it).

I htink that the answer MIGHT be that instead of choosing 5 cards out of 49, and seeing how many agendas, that with choose X cards out of 49, where X is more. And then that gives us the chance of different numbers of agendas in the hand. And then we do the same thing we are currently doing in regards to accessing a card from a hand of different sizes.


#15

This tells you one piece of info that you need: What is the expected value of running the hand.

You also need to know the cost of running the hand, and whether its worth it to pay that cost to achieve that expected value.

But it is an important piece of the equation.


#16

For the numbers provided…

   Np     Pa
---   -----
 0    22.4%
14    51.1%
20    86.8%

where Np is the number of cards played or discarded face up and Pa is the probability that a given card in hand is an agenda.

If you allow face down discards to archives, there is no answer to your question. The Bayesian prior can only change in response to new information, and discarding a card face down provides no new information.


#17

Agreed, the face down discards could be agendas, and if these occur and you dont check them then that throws a wrench in things. Also, if the corp is able to discard some things and then Jackson them, our chances of seeing agendas in the hand goes down a lot. (In that case, you should think they probably got rid of unwanted agendas).