Monte Carlo methods
easylang.dev
easylang.dev
After a quick wikipedia rabbithole, I now grok the St Petersburg paradox, which is fascinating - https://en.wikipedia.org/wiki/St._Petersburg_paradox - but mostly tells me that the 'expected value' is not a good measure of whether you should bet on something, because games can be constructed in such a way that the expected value is infinite, but the chances of you even getting your stake back even at a $16 buy in are 1/8...
Can you explain how do you derive this?
print 10 * 10000 * (18 / 37 - 19 / 37)
It breaks down into three parts:
1. The wager per round ($10). This is, in the game being simulated, the amount won or lost based on the game's outcome.
2. The number of rounds (10000).
3. The probability of winning minus probability of losing.
Forgetting the number of rounds for a moment, the way to calculate the expected value of a single wager like this is:
E[X] = x1*p1 + x2*p2 + ... + xn*pn
Where each `xN` is the value (amount won or amount lost since we're talking about wagers) of an event and `pN` is the probability of that event. In this case there is an 18/37 chance of winning and 19/37 chance of losing. The value of winning is +10 and the cost of losing is -10. So the expected value of a $10 wager ends up being: 10 * 18/37 - 10 * 19/37
Multiply that by 10,000 for the number of rounds played and you get the expected value of a series of games.Yes, the American version is twice as bad for the player, but it doesn't matter; people are still plenty eager to play it...
Perhaps the MC can help you conceptualize volatility and distribution of results, but once you know that the EV is negative, there's no good (mathematical) reason to participate.
Unless of course you know that the casino is willing to pay you out as part of their marketing budget (based on your ev to them); usually in the form of compensated room, food, and beverage, and sometimes even transportation. At that point your choice to participate becomes vacation planning for the mathematically literate.
https://easylang.dev/ide/#code=n%20%3D%2010000%0Afor%20i%20%...
Related: Norvig's runnable intro probability notebooks at https://github.com/norvig/pytudes#pytudes-index-of-jupyter-i...
https://news.ycombinator.com/item?id=20359100 https://news.ycombinator.com/item?id=29217539 https://news.ycombinator.com/item?id=35927627
The author means "if your total is 17 or less, get another card". But it can easily be interpreted as "keep asking for more cards until you have 17 or more"; almost the same, but different.
Open source radiation transport Monte Carlo code here if you'd like to play around:
Uses react-py. Some effort required to implement tabs and manage lifecycle of Pyodide for separate editors.
For the purposes of teaching Python, I once created something similar---but without the explanations:
https://www.speicherleck.de/iblech/zufall-im-browser/index.e...
All unknown cards are randomly assigned and it just loops a bunch, reasonably easy to implement and actually is reasonably fast.
https://github.com/JohnFarrellDev/PokerMonteCarloAPI/
With the amount of possible outcomes Bayesian statistics just didn't seem reasonable to implement.
Goes without saying this tool is still fairly basic, it shouldn't be used to inform how much to bet or when to fold as it doesn't take into account information such as how much your opponents are betting.
A very efficient function to rank a set of Texas Hold’em hands.
A Monte Carlo situation that gives you the probability of winning each hand from any known amount of information.
It is available here: https://github.com/ghais/poker
I just tried this one which works like a charm (just run the exe from the zip in github releases ; even comes pre-loaded with a wide amount of preflop ranges, which seem to come from a previous solve) : https://github.com/bupticybee/TexasSolver
Searching with "poker solver haskell" only seem to show very immature projects.
Casinos make money on poker play differently, and in a few ways. The simplest is “rake”. They take a fixed percentage of every pot. This is different because it’s not probabilistic. The casino isn’t gambling its own money. It’s just a tax.
Money only comes in from players. So the EV of all players is negative, because a little is flowing out to the casino every hand. The chance players as a whole end up ahead isn’t near zero, it is zero.
If everyone was playing theoretically perfect poker every hand, all individual players EV are also negative. But, no one is playing perfect all the time. So you can get ahead because you’re not beating the odds. You’re beating other players.
Monte Carlo has nothing to do with gambling, historically or in mathematics. Historically it was about playing solitaire and casinos also have cards.
Monte Carlo is more like AI.
It looks at the world and returns with intuitive answers. Except it's intuition is billions of times better than yours.
As an example I proved this HN post wrong using Monto Carlo - The Mystery of the Frog Riddle - https://news.ycombinator.com/item?id=32490611 I've deleted the code but write your own and check.