đž Archived View for idiomdrottning.org âş sleeping-beauty captured on 2022-01-08 at 13:46:40. Gemini links have been rewritten to link to archived content
âŹ ď¸ Previous capture (2021-12-03)
âĄď¸ Next capture (2023-01-29)
-=-=-=-=-=-=-
In a middle-school math textbook I read about the Monty Hall problem and while it fascinated me, I thought that the explanation they gave made sense. In senior high I got into a lot of arguments and I ended up having to try to write some sort of BASIC script to try to show that it was true. Years later, reading about how vos Savant was treated (at around the same time), I was like âYep! That tracks!â
I went through life cocky af thinking I was so g-d clever.
But for the Sleeping Beauty problem, which I first heard about five years ago, the shoe was suddenly on the other foot. I just couldnât believe that the halfer position wasnât true. I also thought that the problem was particularly frightening, philosophically, because of what it says about how, hmm, pointless our subjective estimations of probability might be.
So I decided to actually run the experiment! All of this was about five years ago but I found this old code on my drive and thought it might be fun to post on this blog, too. Ported to Chicken 5.
Now, Iâve made one change to the original problem because I donât understand Bayesian probability and Elâs the only one besides my dad whoâs ever said âI love you Creedenceâ. Thatâs right folks! Youâve stumbled into the realm of an Dunning-Krugerâlevel armchair philosopher!
In my version, instead of asking âWhatâs your credence that the coin came up heads?â the question is instead âWhat do you think the coin has landed on?â
Also instead of using anesthesia Iâm using the life-changing magic of computer programs.
First, I chose to go under myself. It surely isnât fair to subject Sleeping Beauty to this when Iâm not willing to experiment on myself.
The sleeper canât have any memories of what has gone before. I canât go âtails?â âcorrect!â âOk, then next time itâs gonna be tails again, duh.â I need to actually forget everything.
To simulate that, Iâm just gonna be subjected to a bunch of random awakenings.
(import (chicken random) (srfi 1)) (define (flip) (list-ref '(heads tails) (pseudo-random-integer 2))) (define (calendar) (list-ref '(monday tuesday) (pseudo-random-integer 2))) (define (ask coin day loop) (print "What do you think the coin has landed on?") (let ((guess (read))) (print "You guessed " guess ". The answer was " coin ". You were " (if (eq? coin guess) 'correct 'incorrect) ".") ) (loop (flip) (calendar))) (let loop ((coin (flip)) (day (calendar))) (if (eq? coin 'heads) (if (eq? day 'monday) (ask coin day loop) (loop (flip) (calendar))) ; â heads on a tuesday. let me sleep (if (eq? day 'tuesday) (ask coin day loop) (ask coin day loop))))
The simulation flips the coin randomly and it flips the calendar randomly. It just keeps doing that over and over and over again.
If itâs heads on a Tuesday the experimenters keep me in the cold land called coma. Otherwise they wake me up and asks me, I type in my reply and they reveal if I happened to be right that time. Here are some examples of this running but itâs different every time since itâs flipping random.
What do you think the coin has landed on?
tails
You guessed tails. The answer was tails. You were correct.
What do you think the coin has landed on?
tails
You guessed tails. The answer was tails. You were correct.
What do you think the coin has landed on?
tails
You guessed tails. The answer was tails. You were correct.
What do you think the coin has landed on?
tails
You guessed tails. The answer was tails. You were correct.
What do you think the coin has landed on?
tails
You guessed tails. The answer was heads. You were incorrect.
What do you think the coin has landed on?
tails
You guessed tails. The answer was tails. You were correct.
What do you think the coin has landed on?
tails
You guessed tails. The answer was heads. You were incorrect.
What do you think the coin has landed on?
heads
You guessed heads. The answer was heads. You were correct.
What do you think the coin has landed on?
heads
You guessed heads. The answer was tails. You were incorrect.
What do you think the coin has landed on?
heads
You guessed heads. The answer was tails. You were incorrect.
What do you think the coin has landed on?
heads
You guessed heads. The answer was heads. You were correct.
What do you think the coin has landed on?
heads
You guessed heads. The answer was tails. You were incorrect.
etc etc until I terminate the loop with C-c.
CS nerds can see that the final loop part of the above code can be refactored to
(let loop ((coin (flip)) (day (calendar))) (if (and (eq? coin 'heads) (eq? day 'tuesday)) (loop (flip) (calendar)) ; â heads on a tuesday. let me sleep (ask coin day loop)))
Thatâs a briefer version but has the same probabilites. Upon making that version, my halfer position started to tremble a bit. Executing it works the same as the above.
Itâs tedious to keep track of my own correct guesses and how often Iâm right or wrong and from there try to estimate some kind of reasonable credence. And I had suffered enough. It was time to bring in some other subjects. Bots! I could have one bot that always guessed heads, and one that always guessed tails, and run the experiment hundreds, even millions of times and just tally up how often they were right.
(let heads-guessing-loop ((coin (pseudo-random-integer 2)) (day (pseudo-random-integer 2)) (guesses '()) (times 100)) (if (zero? times) (reduce + 0 guesses) (if (zero? (+ coin day)) (heads-guessing-loop (pseudo-random-integer 2) (pseudo-random-integer 2) guesses times) ; â heads on a tuesday. let them sleep (heads-guessing-loop (pseudo-random-integer 2) (pseudo-random-integer 2) (cons (- 1 coin) guesses) (sub1 times))))) (let tails-guessing-loop ((coin (pseudo-random-integer 2)) (day (pseudo-random-integer 2)) (guesses '()) (times 100)) (if (zero? times) (reduce + 0 guesses) (if (zero? (+ coin day)) (tails-guessing-loop (pseudo-random-integer 2) (pseudo-random-integer 2) guesses times) ; â heads on a tuesday. let them sleep (tails-guessing-loop (pseudo-random-integer 2) (pseudo-random-integer 2) (cons coin guesses) (sub1 times)))))
The heads-guessing-loop ended up being right â of the time and the tails-guessing-loop ended up being right â of the time.