Wednesday, August 31, 2005

How Commoners can beat the Mafia (most of the time)

For those who have never played the party game Mafia, here are the rules:

  1. An arbiter is selected at random from the players. Call the other players "townspeople".
  2. The arbiter uses some random, secret procedure to designate some small fraction (say, 1/4) of the townspeople as Mafia, and the rest as Commoners. One way that works is to take one slip of paper for each player, write down "Mafia" or "Commoner" on each slip, and have players draw from a hat.
  3. All the players to close their eyes. Then, at the arbiter's signal, only the Mafiosi open their eyes and look around, so they know the identities of all the other Mafia.
  4. The play proceeds in rounds. Each round goes as follows:
    1. First, all the players discuss who might be Mafia, and then vote to execute one person as a Mafioso.
    2. The person who gets the most votes is executed. If there is a tie, the arbiter should flip a coin. The dead player leaves the game, at which point the arbiter informs the town whether that person was a Commoner or a Mafioso.
    3. Dead players tell no tales. Once dead, a player may not communicate with living players for the remainder of the game.
  5. Play proceeds until either the entire Mafia is dead, or all the Commoners are dead. The living team wins.

In practice, the Mafia wins as soon as they're a majority, because then they can always outvote the Commoners and execute them all.

What makes this game fun is the social interaction and politicking that goes on when you're deciding whom to execute. The Mafiosi are all trying to influence the voting so that a Commoner gets executed on each round. Meanwhile, the Commoners are trying to detect excessive certainty or bloodlust (which probably indicates a Mafioso --- after all, only Mafia know for certain whom they want executed), so the Mafia can't appear too eager or obvious. It's also a game of teamwork --- a lone clever Commoner can't beat the Mafia unless (s)he can also convince the other suspicious townspeople to trust him/her. A cleverly played game of Mafia will ultimately be won by the Mafia, if they're better actors, or by the Commoners, if they're better at "reading" people. With the right group, this can be lots of fun.

Now I'm going to tell you how to take all the fun out of Mafia. Propose the following strategy to your fellow townspeople:

  1. During the first round of discussion, use some mechanism to produce a random ordering of players. One way that works is for everyone to roll a pair of dice, and sort people from highest to lowest roll, rolling again to break ties. Note: if you use this method, you must decide on the exact method for sorting, including whether you're going from low-to-high or high-to-low, before you actually roll the dice.
  2. Agree that everyone will vote to eliminate the players in order. Anyone who dissents from this plan must be a Mafioso, and becomes the next target of execution instead of the scheduled player.

Why does this work? Notice the victory conditions: the Commoners win when 100% of the Mafia dies; the Mafia wins when when they outnumber the Commoners. Given that the Commoners have a large majority, most random orderings of the townspeople will list 100% of the Mafia before any point where the remaining Mafia outnumber the remaining Commoners.

Proving this claim formally requires some fairly intense math. I looked at it for a few minutes with one of my friends (who was also a computer scientist). We decided it was hard, and just handwaved our way through it.

(If you're curious, here's the handwaving: on average, over all random sortings, you expect the proportion of Mafia and Commoners in the remaining population to remain roughly constant as the population decreases; so the Mafia will usually not attain a majority. Then, once you get down to a small number of remaining players --- say, N, where 1/N is the fraction of Mafiosi in the original population --- then you expect that, on average, there will be 1 Mafioso left out of those N players. The chance that this Mafioso will be the last one standing is 1/N. Since N > 2, the last Mafioso probably doesn't survive.)

So, on average, over a large number of games, this is a winning strategy for the Commoners. Only Mafiosi would dissent from it; but the really cool thing is that they can't do anything about it, because if they dissent then they reveal that they belong to the Mafia. Even if all of them dissent together, they're outnumbered, so the Commoners will just execute them all. And even if the Mafia win --- as they sometimes will --- the win doesn't give them much satisfaction, since it wasn't through the exercise of wit and deception but just a random roll of the dice.

When you play the game by this strategy --- and I have done it once --- the game goes pretty fast. Everyone votes unanimously to execute the next player on the list. There's no discussion, no politicking, no doubt, and the game becomes a rather grimly fatalistic exercise until the arbiter calls the end. On the other hand, as the person who devised this strategy, I enjoyed watching it play out.

The Commoners won, by the way. Ironically, I was on the Mafia team that time.


UPDATE 9:30 p.m.: I got curious, so I wrote a Python script to simulate many games of Mafia in aggregate. Basically, the handwaving analysis above is a decent approximation of the actual results for typical party-sized populations (6-30 people) and small fractions of Mafia. At a population of 25% Mafia, the Mafia wins about 25% of the time. As the number of Mafia increases, however, the results begin to diverge from this analysis, due to the asymmetry in winning conditions: the Mafia win at a rate that exceeds their fraction of the population. At about 39% Mafia, the game becomes 50/50 Commoners v. Mafia.

The source for the script follows. It's a pretty direct interpretation; I haven't tried to do any of the obvious optimizations for simulating games.

#!/usr/bin/env python

import random

TRIALS         = 100000
MAFIA_FRACTION = 0.39
MIN_POP        = 6
MAX_POP        = 30
HIT_VARIANT    = 0

COMMONER = 0
MAFIA    = 1

maf_wins = 0
com_wins = 0

def init_town():
    popsize = random.randint(MIN_POP,MAX_POP)
    town = [COMMONER for j in range(0,popsize)]
    maf_count = int(MAFIA_FRACTION * popsize)
    for j in range(maf_count):
        while 1:
            idx = random.randint(0,popsize-1)
            if town[idx] != MAFIA: break
        town[idx] = MAFIA
    return town

def hit_commoner(town):
    if COMMONER not in town:
        return town
    else:
        com = town.index(COMMONER)
        return town[:com] + town[com+1:]

for i in range(TRIALS):
    town = init_town()
    while len(town) > 0:
        town = town[1:]
        if HIT_VARIANT: town = hit_commoner(town)
        maf_left = town.count(MAFIA)
        pop_left = len(town)
        if maf_left > (pop_left/2):
            maf_wins += 1
            break
        elif maf_left == 0:
            com_wins += 1
            break

print "Commoner wins  : " + str(com_wins)
print "Mafia wins     : " + str(maf_wins)
print ("Mafia fraction : " +
       str(float(maf_wins)/float(maf_wins+com_wins)))

UPDATE 1 Sept: In comments, Andrew and AJ reminded me of a variation of the rules, wherein the Mafia get to secretly "hit" one Commoner in each round, after execution. I've fixed the script so that the HIT_VARIANT flag controls whether to play with this variation. The results are surprising --- see comments for details...

Sunday, August 21, 2005

How Red America thinks

Digby points to one of Rose Aguillar's interviews with Oklahomans. Read the Mary Fowler interview and weep. It may have seemed that I was exaggerating when I wrote about how stupid and blind conservative thinking is; but if anything, I was understating the truth. It is as if some alien creature has eaten Fowler's brain and implanted a little alien worm in her skull to replace it.

Thursday, August 18, 2005

Removing sound from video files

Just got back from a Bay Area trip, visiting my friend MS et al. While I was down there, we visited the world-famous Monterey Bay Aquarium, where, among other things, I found many reasons to play around with the movie recorder on my new digital camera. The results were impressive --- considering it's a camera and not a camcorder, the Canon PowerShot A95 takes really nice-looking videos at 640x480 --- but the ambient sound inside the aquarium was just crowd noise: murmuring strangers, screaming kids, and such. Sort of ruins the mood when you're looking at a video that looks like this:

The PowerShot A95 doesn't have a way to turn off the sound during video recording either. So, I wanted to strip the sound off my video files, without re-encoding the video (which would reduce the image quality).

"Surely," I thought, "this will be easy. The AVI file format stores audio in separate binary chunks from the video --- it's just a matter of erasing the audio chunks. Even if the software that comes with my camera can't do it, there will be multiple freeware utilities that can. Maybe not for Linux, but surely for Windows..."

Ha, ha.

Anyway, to make a long story short, I couldn't find a good free utility to do this under Windows. I found many programs that let me replace the soundtrack to a movie, but for some reason none of them could remove the sound altogether. I didn't feel like dropping a few hundred bucks on Adobe Premiere either. So, the best option turned out to be --- surprise! --- a Unix utility called transcode. I got mine via the freshrpms yum repository for Fedora Core 4, read the manual pages and the wiki, and came up with the following recipe:

transcode -i foobar.avi -P1 -o foobar_nosound.avi -y raw,null

Geeky details: this instructs transcode to read the video from foobar.avi, pass through the video track only, write the output to foobar_nosound.avi, and use raw encoding for the video and null encoding for the audio.

Here's a Python script that makes transcode batch processing easy; just give it a list of filenames of the format foobar.avi, and it will produce a list of silent video files named foobar_nosound.avi:

#!/usr/bin/env python

import os.path
import subprocess
import sys

def splitExtension(filename):
    lastdot = filename.rfind('.')
    return (filename[:lastdot], filename[lastdot:])

infiles = sys.argv[1:]
for infile in infiles:
    (prefix, ext) = splitExtension(infile)
    outfile = prefix + "_nosound" + ext
    idx = 0
    while os.path.exists(outfile):
        idx = idx + 1
        outfile = prefix + "_nosound_" + str(idx) + ext
    print infile + " stripped to:" + outfile
    retcode = subprocess.call(
        ['transcode',
         '-i', infile,
         '-P1',
         '-o', outfile,
         '-y', 'raw,null'])

Saturday, July 30, 2005

Two posts by young members of Free Culture

Lessig Blog has two posts by young members of the Free Culture movement, one depressing and one heartening:

Andy Scudder writes about a student photographer he knows who wanted to be able to control whether people could print out the photos she posted on the Internet. I find this incredibly depressing. I'd taken to believing that the current wave of intellectual property extremism would eventually be overturned by sheer demographic pressure as the next generation came of age and took the reins. But if the hip-hop generation doesn't understand that art exists to be remixed by others, then who will? If, nearly a century after the collages of Picasso and Ernst, educated young artists are sympathizing with totalitarian, centralized control over the tools of creative production, then we're really losing the war.

More hopeful is Nelson Pavlosky's account of his experience growing into the Free Culture movement. Maybe the kids will be alright after all. I guess the lesson here for technologists would be that if we create systems that, like peer-to-peer networks or blogging software, permit creative people to observe the benefits of decentralization and freedom, then they can be awakened.

Splenetic ranting (feel free to ignore)

It's way early Saturday morning and I'm banging around my apartment dealing with a bout of insomnia, so I might as well post this. Fair warning --- I'm going to be writing more about my reactions to this subject than the subject itself. Navel-gazing ahoy.

Nomadic Thoughts has the link rundown for a recent trans-blog dustup, about Jared Diamond's Guns, Germs, & Steel, between Crooked Timber, Brad DeLong, and a bunch of anthropologist types at Savage Minds. I wrote some slightly lengthy comments on the first post in the controversy, though I now realize that this was stupid of me. My summary of the debate:

  • Ozma of Savage Minds writes: "Jared Diamond is wrong, and the reason people like Guns, Germs, & Steel is that they're racists."
  • Brad DeLong writes:: "No, you're confused about Jared Diamond's ideas. And we like the book because it's well-written, and makes a striking argument about an important question."
  • Kerim of Savage Minds writes: "Well, it's stupid and maybe even morally wrong, even to ask that question."
  • Henry of Crooked Timber writes: "No, it's just a different question than the one you'd investigate."
  • Ozma repeats, in comment threads on the above posts, over and over again, that "Jared Diamond is wrong, and the reason people like Guns, Germs, & Steel is that they are racists." She doesn't address any of the objections, evidently subscribing to the theory that vociferous repetition is the key to winning arguments.
  • Kerim repeats, in comment threads on the above posts, that either Diamond's question is immoral, or that he's not really asking a different question, or that the reason people like Diamond is that they mistakenly believe he's asking a different question. His position keeps changing, so that as one position is refuted he moves to another one and claims he held that other position all along; in this fashion, he cannot be proven wrong, nor can anybody engage in productive debate with him.
  • Throughout all of the above, several anthro types insist that (1) Diamond's theories are old hat, and (2) they have been thoroughly debunked. They fail to present evidence or argument for these two points, insisting that they are common knowledge among anthropologists.[0] (Yeah, OK, you supercilious jackasses; we have crackpots in computer science too, but when somebody claims that, for example, they've invented an algorithm that can compress all strings, we can concisely explain exactly why that claim is a crock, in terms that anybody with a little math background can understand; and you should be able to do the same.)

Reading all this got me pretty mad. As those who've known me for a long time can attest, there's almost nothing in the world that makes me madder than bald-faced nonsense. My reaction to nonsensical statements is usually much more intense than, for example, my reaction to immoral or insulting statements. Allow me to elaborate slightly. When I read an argument that's completely unsound (as opposed to one that's wrong, but defensible), it strikes me like a blow to the head. I literally feel a bolt of dull pain pulse between my temples (and I do mean literally, not "metaphorically, but with such intensity that I feel obligated to describe it as literal"). I get a surge of adrenaline-fueled fight-or-flight response, and often feel the need to get up and pace around the room. I find myself wishing that I were omnipotent, solely so that I could obliterate that argument from the face of the Earth, because the very fact that a human being has the effrontery to make such an argument, and to expect other people to believe it, is an insult to all of creation. In short, nonsensical arguments send me completely off the deep end. I'm not claiming that this is a sane reaction, but it's how I react.

Ozma and Kerim's original posts were bad enough, but as I read their replies, and the replies of some others, I could not avoid smacking myself on the forehead, just to make the pain stop. Ozma, especially, seems to embody a perfect storm of rhetorical incompetence: she's unable to understand Diamond's argument, she's unable to coherently explain her objections to (her mangled understanding of) Diamond's argument, and she's unable to handle critical responses to her own arguments. She's also a new professor at the U. of Alberta, and I sincerely pity her students.

In retrospect, it's pretty obvious to me that Ozma and Kerim are fractally wrong, i.e. so wrong that arguing with them will lead to an infinitely recursive regress of wrongness on every sub-point of debate. I should have recognized this before I invested time in commenting, but somehow I mistakenly thought that since (a) I liked Diamond's book, and (b) I wanted to understand the objections to it, that there was some value in sinking my time into this debate. Stupid me.


p.s. Lots of anthro types seem to have some pretty absurd notions about biology. Two examples:

  1. I compared the difference between Diamond-style hypotheses of ultimate causation, and anthropological hypotheses of proximate causation, to the distinction between evolutionary and developmental biology; and I suggested that, as with "evo-devo", there might be gains to merging the two. Ozma followed with the absurd statement that "evo" was "in retreat", which is absurdly incorrect --- evolution is stronger than ever. She then had the amazing temerity to refer to this bizarre misconception in the Crooked Timber thread, evidently believing that it was a point in her favor rather than evidence of her disconnection from reality and willingness to spout off about subjects that she's completely ignorant of.
  2. "J Thomas" wrote, in a comment, that Darwin "got evolution all wrong but at least said evolution was going on". Ahem. Biology has advanced a great deal in the past century and a half, but Darwin was fundamentally right. It would be accurate to say, "We know a great deal more than Darwin; in their daily work, modern biologists rely on modern theories that are not directly attributable to him." But it is a complete distortion to say that Darwin "got evolution all wrong", and only somebody who was supremely misinformed could say otherwise. (UPDATE 31 July: J Thomas has clarified, so I retract this; see comments.)

This, combined with some disparaging comments by Kerim about "biological/deterministic" reasoning, leads me to believe that anthropology in general (or at least a certain sub-community thereof) has some real problems with the theory of evolution. Given that the theory of evolution is simultaneously one of the greatest intellectual achievements of humankind, and the engine driving one of the most productive and exciting scientific disciplines today, this doesn't speak well of these anthropologists.

UPDATE 31 July: I was too hasty in inferring too much about anthropologists and evolution from what I read. See comments for further discussion.


[0] OK, they did present two references. However, closer examination by commenters --- including myself --- revealed that one is totally irrelevant to Diamond's thesis, and the other seems to be based on significant misreadings of the conditions necessary for Diamond's thesis to be valid. Also, the anthro types never explain in the first place how these citations supposedly demonstrate that Diamond's arguments are either old hat or thoroughly debunked --- they simply point to the footnote and say "See?" This might be acceptable if the citations themselves were not so weak, but as it is...