Parrondo’s Paradox

September 7, 2009 | Math | By: Mark VandeWettering

earl53_1909pennyfront2webI was reading Nahin’s Digital Dice, which I bought a while ago but which I didn’t really dive into deeply, and he had a nice exposition of Parrondo’s Paradox, which is very neat. Here’s the idea:

  1. We are going to play two different coin tossing games. In each case, if we win, we gain one unit. If we lose, we lose one unit.
  2. In Game A, we will toss a coin, and if it comes up heads, we win, otherwise we lose. Unfortunately for us, the coin is not a fair coin, it is more likely to come up tails than heads. Let’s call the probability of winning this game as 0.5 – ε. Clearly, this game is a losing one for ε > 0.
  3. In Game B, we have two coins. One is clearly biased against us: the chance of winning is just 0.1 – ε, the second is biased for us, and has probability of winning as 0.75 – ε. Here’s the wrinkle: if our bankroll is an exact multiple of three, we toss coin the first coin, otherwise we toss the second coin.

Game B is a bit harder to analyze, but let’s give it a try (it’s wrong, but it’s not too far wrong): 1/3 of the time, we gain one unit wth probability 0.1-ε and 2/3 of the time, we gain one unit with probability 0.75-ε. This means that our probability of winning is 8/15 – ε. If we set ε to be 0.005, we maintain a narrow advantage.

Or do we? Let’s go ahead and simulate this. I wrote some Python code that played both games for one million rounds. The results from a typical round:

GAME A: played 1000000 rounds, started with 0, ended with -8642
GAME B: played 1000000 rounds, started with 0, ended with -8532

So, here’s the first thing issue: Game B appears to be a loser as well. Why would that be? (Think about it).

But if we accept the fact that Game A and Game B are losing propositions, let’s play a new game called the combination game. It’s very simple, we randomly pick (perhaps by tossing a fair coin) which of the games we want to play in each round. If we simulate this game, we get the following (again, from a run of 1000000):

COMBINATION: played 1000000 rounds, started with 0, ended with 16620

What’s this about? We’re alternating between two losing games, and yet, we emerge as winners? What’s going on here?

Enjoy!

Addendum: Here’s some python code that I wrote to simulate the game.

#!/usr/bin/env python
#
# $Id$
# parrondo.py 
#

import random

def play_game_a(capital, eps):
    return random.uniform(0, 1) < (0.5 - eps)

def play_game_b(capital, eps):
    if capital % 3 == 0:
	return random.uniform(0, 1) < 0.1 - eps
    else:
	return random.uniform(0, 1) < 3.0/4.0 - eps

def play_game_combo(capital, eps):
    if random.randint(0, 1):
	return play_game_a(capital, eps)
    else:
	return play_game_b(capital, eps)


def play(name, f, n, icap, eps):
    cap = icap
    for i in range(n):
	if f(cap, eps):
	    cap = cap + 1 
	else:
	    cap = cap - 1 
    print "%s: played %d rounds, started with %d, ended with %d" % (name, n, icap, cap)


play("GAME A", play_game_a, 1000000, 0, 0.005)
play("GAME B", play_game_b, 1000000, 0, 0.005)
play("COMBINATION", play_game_combo, 1000000, 0, 0.005)

Dennis Ritchie Home Page

September 5, 2009 | General | By: Mark VandeWettering

Using Stumble Upon!, I, well, stumbled upon Dennis Ritchie’s page. He’s famous as the creator of C and an early influential developer of Unix. Back when I was in school, we all learned C by reading Kernighan and Ritchie’s The C Programming Language. His homepage has some nice papers about the history of Unix, as well as some others on topics like cryptography and programming language design. Great stuff.

Dennis Ritchie Home Page.

Nomograms

September 5, 2009 | General | By: Mark VandeWettering

For some reason, I found myself looking at a rather pedestrian page about slide rules today, and it once again rekindled my interest in the closely related nomograms and nomography. I’ve mentioned them once or twice on this blog in the past, but in case you don’t know, nomograms are a computational aid from the past which were used for computation. In their most common form, they are a diagram with three separate scales, and by connecting a line between two variables, you can read off the third. They are an interesting and mostly forgotten relic from the past.

Now, I’ve particularly when interested in old technology, I imediately surf over to archive.org and see if they have any books for downoad about the subject. And, of course, they do!

Internet Archive: A first course in nomography.

You could also surf over to the PyNomo website and get their software for designing and printing nomograms.

Another interesting question of probability…

September 4, 2009 | General | By: Mark VandeWettering

I was reading Kraitchik’s Mathematical Recreations book (a very nice little Dover volume) and ran across this interesting puzzle on pg. 140:

21, A man stakes 1/m of his fortune on each play of a game whose probability is 1/2. He tries again and again, each time staking 1/m of what he possesses. After 2n games, he has won n times, and lost n times. What is his result?

This isn’t very hard to analyze. Let’s assume that n = 1 to try to gain some insight. There are two ways we can win 1 and lose 1 game, but both end up with the same: (1 – 1/m2) times our original stake. A tiny bit more head scratching will (maybe) convince you that for n > 1, we get (1 – (1/m2))n. It should be obvious that both of these expressions are strictly less than one (you lose money, and the greater the fraction you bet, the quicker you lose). The only way to preserve your bankroll in this game, well, not to play it.

There are a couple of interesting things about this puzzle which Kraitchik didn’t elaborate, but which I think are interesting.

Somewhat trivially, the payout of this puzzle actually doesn’t depend at all on what the probability of winning an individual round is. When the game is fair (probability of winning is 1/2) then the most likely outcome (although as n gets larger, an increasingly unlikely one) is for an even number of wins and losses to occur. In some sense, this outcome is the “fairest” of all fair outcomes: it is the most likely to occur, you bet a constant fraction of your total bankroll, and you get the fairest outcome: the same number of heads and tails. And yet, you lose money every time. Guaranteed.

This obviously has something to do with fractional betting. If, instead of betting a fraction of your total bankroll, you instead bet a constant amount (say 1 unit), then after n losses and n wins, you’d be even.

Ponder it some more.

Addendum: Think of this another way. Consider this game to be a drunkards walk, where you win and lose with equal probability. Each step, you wager a fraction of your bankroll, and if you win, collect your money and take a step to the right. If you lose, you pay out and take a step to the left. You can read more about random walks here on Wikipedia. In these one dimensional random walks, you will cross the start point (and in fact any other point as well) an infinite number of times as you repeatedly play the game. And yet, every time you pass your start point, you will have won and lost the same number of games, and you will always be behind. Similarly, no matter what you bankroll, if you bet a constant amount, you will always be ruined playing a fair game if you play long enough.

These results are counter to many of the intuitions that we have about gambling, where one might imagine that in a “fair” game, if we have a large enough stake we might think we could play forever.

Anyway, just fun to think about.

Kelly most famously studied fractional betting systems. They hold a few surprises.

Tom Duff on Reading code from top to bottom

September 3, 2009 | Computer Science, General | By: Mark VandeWettering

Matt pointed to an interesting article by Tom Duff on writing code. It actually clearly elucidates some of the principles that I use in writing my own code. As a caveat, I suspect that I am the original authors of at least one of the code fragments that Tom critiques. 🙂

Reading code from top to bottom

Cheap Arduino Wireless Communications

August 30, 2009 | General | By: Mark VandeWettering

As part of my slow, arduous march toward doing a high altitude balloon launch, I acquired some super cheap wireless modules from sparkfun.com. Sadly, I haven’t had time to play with them much, but here’s someone who has. I am more interested in using these tiny transmitters as back up beacons, but the information is still quite useful.

Hobby Robotics » Cheap Arduino Wireless Communications.

Micro-Rendering for Scalable, Parallel Final Gathering

August 29, 2009 | Computer Graphics, General | By: Mark VandeWettering

Thanks to Kevin Bjorke for pointing out this paper. It combines a couple of interesting features to create a point-based renderer that efficiently uses the GPU to render scenes with global illumination. I’ll have to read it more carefully when I have time.

Micro-Rendering for Scalable, Parallel Final Gathering.


httpv://www.youtube.com/watch?v=Z9u8EdFbmiI

A little statistics puzzle…

August 27, 2009 | General | By: Mark VandeWettering

I hand you a deck of cards, which you shuffle, and deal me a random 5 card poker hand. I announce that I have an ace in my hand. What are the odds that I have a second ace in my hand?

Now, play the game, and deal me another hand. I announce that I have the ace of spades in my hand. Now, what are the odds that I have a second ace in my hand?

Explain.

Addendum: This is known as the “paradox of the second ace”. It is usually expressed as a bridge problem, with 13 card hands, but I misremembered it, so here it is a poker problem. Solve the bridge problem if you like.

Addendum2: The paradox is easier to understand if you limit the size of hands (say to two cards) and the number of suits.

Computer Vision: Algorithms and Applications

August 25, 2009 | General | By: Mark VandeWettering

Microsoft researcher Richard Szeliski has a text on computer vision available for download. Szeliski has written countless papers on computer graphics, including lots of papers on creating panoramas from images. Good stuff, bookmarked for later consumption.

The telescope turns 400 today…

August 25, 2009 | Astronomy | By: Mark VandeWettering

glassesOn this day in history, 400 years ago Galileo Galilei demonstrated his telescope to a group of Venetian lawmakers. In March of the following year, he would publish his most famous work, Siderius Nuncius (commonly rendered in English as The Starry Messenger). This invention ushered in the modern era of astronomy, and quite literally changed our view of the universe and humanity’s place in it.

While Galileo’s telescope would be considered relatively crude by modern standards, it had an influence for hundreds of years. On the right I have a pair of field glasses that are actually a pair of Galileian telescopes paired together, dating back to roughly the start of the 20th century (I think). As binoculars, they basically suck (very narrow field of view) but they are a cool relic to have on your desk.

Another HTML 5 video test…

August 24, 2009 | General | By: Mark VandeWettering

This is just a test. If you are running Firefox 3.5, you should get a video window that allows you to watch a Superman cartoon encoded in Ogg Theora. If you aren’t running it, but have a Java enabled browser, you should get an applet which plays the same video. If you have neither, you should get a message lamenting your condition.



P.S. I haven’t verified that Java playback works. Safari on my Macbook tries to load the Theora video, but appears to fail (Safari appears to only support h264 encoded video, retarded).

Addendum: Ah, it does work on Safari, but only if you install these Quicktime components. Kind of annoying, but it’s nice to see that it does work.

Addendum2: Shifted the clip to be one I made of my betta fish. It’s shorter, and will thrash my server less.

A simple, short puzzle

August 24, 2009 | Puzzles | By: Mark VandeWettering

How many coins do you need to remove so that the centers of all remaining coins form no equilatoral triangles?

How many coins do you need to remove so that the centers of all remaining coins form no equilatoral triangles?

Here is a simple puzzle that came from Martin Gardner’s The Colossal Book of Short Puzzles and Problems. Here we see ten circles arranged in the classic triangle bowling configuration. The question is “what is the minimum number of circles that can be removed such that there is no equilateral triangle formed by the centers of the remaining circles?”

I was originally having difficulty convincing myself of the optimality of my answer, but I am reasonably certain of it now. Still, it took a bit of pondering to justify. I’ll let you all sit on it for a day or two, then give my reasoning through it.

Addendum: If you found that easy, try to answer the same question for the triangle with sides of length 5. And then length 6.

Random bits…

August 18, 2009 | Math | By: Mark VandeWettering

Well, pseudo-random, but reportedly cryptographically strong.

01110 10011 01100 01000 11101 11001 11010 10011 00000 10011 11111 11001
10101 11100 10011 10110 01010 01100 01000 00010 11110 01100 11010 11000
00011 11111 10001 00111 01011 00101 00011 00111 01000 11111 10011 01001
10000 10101 10001 01011 11111 00100 11010 10000 00110 11111 10111 11011
00011 11001 11111 00011 11010 01001 01011 00010 10101 10101 10010 10100
11010 00010 01010 11110 01011 01001 11101 11100 00100 11011 00010 01110
01010 00100 10001 10001 00000 00100 10010 10000 10001 10110 10010 10101
10100 11000 10001 10000 00001 01001 00100 00100 11001 11010 01110 10000
01111 00100 11111 01010 01001 01100 01000 10010 10110 01000 00000 11001
01001 10011 11100 10010 00111 11001 10100 01011 01010 00110 11001 10001
10011 01110 00010 01111 10101 01111 10110 10101 00010 10000 11010 11001
00001 01101 00100 10010 00000 10000 01011 00011 00110 00110 01011 10111
01100 01010 11011 11010 10001 01000 00010 10010 00100 01011 11001 01011
01111 11111 01110 11100 10101 01110 01010 10100 00110 11111 11101 00100
01111 01011 10001 00000 10010 01111 11110 00100 11100 11001 10001 10011
01001 11101 11100 00110 01100 01011 00100 10000 10110 00000 10100 00001
01100 11111 00010 11000 00111 11101 10110 10101 11110 00110 10101 10100
10001 01101 11011 11000 10001 10111 00100 11000 01010 10111 01010 01010
01001 00110 11111 01110 01100 11110 10100 01011 01000 00100 10010 11000
01101 10001 11100 00100 00100 01001 10100 01100 11000 11100 01101 10111
00011 11101 11001 10010 10111 10000 11000 10100 01000 10101 11010 01001
10101 11011 11101 00000 11100 01011 11100 11110 01101 00110 10111 11100
01001 11000 11101 11110 01100 10101 11011 01110 00111 10101 01000 11111
11010 11000 00100 00111 01001 11011 01100 01101 11000 11101 00010 00011
10101 00011 10000 10000 11000 00111 01010 01000 01111 10101 01011 01110
01111 01001 11011 11000 01011 10110 10100 00001 11110 00011 00111 10011
11111 11101 01000 11100 01010 01000 00010 01111 10101 11101 11010 01100
11100 11101 01100 11101 11101 11010 01100 01101 00110 11100 11011 01001
01001 01110 10100 01011 00000 11110 00101 00000 10111 00101 10101 00111
10011 11111 11100 11011 00101 10100 11001 10110 01011 10010 00000 10100
10001 01110 11000 11010 11110 01010 10011 11011 00010 01010 11011 00011
10111 00010 10010 00001 11110 11000 00011 01001 00110 00010 10000 01000
00100 11000 10000 10110 11010 11011 00010 00001 10100 00101 01011 00000
00001 10000 10000 10111 10110 10111 01110 00010 00101 01001 10110 11000
00001 10001 01101 00111 01010 00001 11100 11110 11111 10001 10110 01111
01001 00010 10011 10100 00011 10101 01100 00001 00000 01111 10111 11010
00110 01110 10001 00010 11111 11000 01100 11010 10011 11000 01000 00101
10000 00011 00001 10110 10001 00000 10001 00101 10010 00110 01101 00011
10110 00110 00101 00110 11100 11101 00011 10010 01011 01011 01000 11100
10100 11001 00110 00101 10110 10011 11001 01110 00111 00110 00000 11010
10011 00010 10000 10110 00000 01101 01111 10111 10010 11010 10001 01101
11000 01010 01011 00011 01010 01110 00011 01011 11010 00110 00101 10011
00110 10001 10001 10101 00110 11011 01111 11100 00111 00011 11001 11010
11000 11101 00000 10101 00110 01110 00110 01110 01100 00001 01001 01011
10100 01110 10000 10101 00001 10101 00101 11010 00100 10101 00111 00111
00110 11001 10110 00101 11111 01011 11110 10101 00001 11000 00011 01011
11111 01110 00011 01110 00110 10111 01111 01111 00011 01000 01101 11010
00110 11110 10000 00101 11111 11001 10111 10100 01010 01111 10010 11101
11110 01100 10101 01100 00000 10101 10110 11110 10110 11001 11001 00000
01111 10101 01000 10001 10000 11101 01001 01100 11100 11001 11010 00011

Interesting number theory underlies this: check out this wikipedia entry for the Blum Blum Shub random number generator.

Something fishy going on here…

August 17, 2009 | Computer Graphics, My Projects | By: Mark VandeWettering

Another of my attempts to make pictures from volume data…

carp

HF Reference Material

August 16, 2009 | Amateur Radio | By: Mark VandeWettering

From a thread on qrz.com, here’s a nice list of 1000 utility stations which broadcast on HF. Nifty.

HF Reference Material