Saturday, August 22, 2009

Electronic mind reader

I am reading Fortune's Formula: The Untold Story of the Scientific Betting System that Beat the Casinos and Wall Street It is a simply amazing book for anyone interested in the intersection of information theory and investing.

Claude Shannon plays a major role in this book, and I've been researching him on the side. He wrote an internal Bell Labs paper called "A Mind-Reading (?) Machine" in 1953. It is freely available here.

The first paragraph reads:
This machine is a somewhat simplified model of a machine designed by D.W. Hagelbarger. It plays what is essentially the old game of matching pennies or "odds and evens." This game has been discussed from the game theoretic angle by von Neumann and Morgenstern, and from the psychological point of view by Edgar Allen Poe in the "The Purloined Letter." Oddly enough, the machine is aimed more nearly at Poe's method of play than von Neumann's.
Before going further, you may wish to try out an online implementation of Shannon's mind-reading device yourself. You can find it here:

"The Purloined Letter" is definitely a good story to read in thinking about this subject... The "odds and evens" game is much like Rock, Paper, Scissors, in that I have also heard of people who were able to model their opponent's though processes (based on the patterns played in the game to that point) and then anticipate their next move. This is all that Shannon's machine is doing. Except that it looks at patterns only three moves long.

The part of the story Shannon refers is this excerpt:
"The measures, then," he continued, "were good in their kind, and well executed; their defect lay in their being inapplicable to the case, and to the man. A certain set of highly ingenious resources are, with the Prefect, a sort of Procrustean bed, to which he forcibly adapts his designs. But he perpetually errs by being too deep or too shallow, for the matter in hand; and many a schoolboy is a better reasoner than he. I knew one about eight years of age, whose success at guessing in the game of 'even and odd' attracted universal admiration. This game is simple, and is played with marbles. One player holds in his hand a number of these toys, and demands of another whether that number is even or odd. If the guess is right, the guesser wins one; if wrong, he loses one. The boy to whom I allude won all the marbles of the school. Of course he had some principle of guessing; and this lay in mere observation and admeasurement of the astuteness of his opponents. For example, an arrant simpleton is his opponent, and, holding up his closed hand, asks, 'are they even or odd?' Our schoolboy replies, 'odd,' and loses; but upon the second trial he wins, for he then says to himself, the simpleton had them even upon the first trial, and his amount of cunning is just sufficient to make him have them odd upon the second; I will therefore guess odd'; --he guesses odd, and wins. Now, with a simpleton a degree above the first, he would have reasoned thus: 'This fellow finds that in the first instance I guessed odd, and, in the second, he will propose to himself upon the first impulse, a simple variation from even to odd, as did the first simpleton; but then a second thought will suggest that this is too simple a variation, and finally he will decide upon putting it even as before. I will therefore guess even' guesses even, and wins. Now this mode of reasoning in the schoolboy, whom his fellows termed "lucky," --what, in its last analysis, is it?"

"It is merely," I said, "an identification of the reasoner's intellect with that of his opponent."

"It is," said Dupin;" and, upon inquiring of the boy by what means he effected the thorough identification in which his success consisted, I received answer as follows: 'When I wish to find out how wise, or how stupid, or how good, or how wicked is any one, or what are his thoughts at the moment, I fashion the expression of my face, as accurately as possible, in accordance with the expression of his, and then wait to see what thoughts or sentiments arise in my mind or heart, as if to match or correspond with the expression.' This response of the schoolboy lies at the bottom of all the spurious profundity which has been attributed to Rochefoucauld, to La Bougive, to Machiavelli, and to Campanella."

"And the identification," I said, "of the reasoner's intellect with that of his opponent, depends, if I understand you aright upon the accuracy with which the opponent's intellect is admeasured."
Back to the online version of Shannon's Mind Reader. Not knowing how it worked, I was still able to beat the machine for a while (until I went off to figure out how it worked). A snapshot from the end of my game is shown. The black bar on the bottom indicates the percentage of games won by the machine.

Then, as a control case, I tried a comparable number of clicks, using a sequence of random numbers generated from Octave (admittedly, these are pseudo-random, but they should be good enough). The results was actually a bit worse, implying that this simple Mind Reader can be outsmarted. The corresponding snapshot indicates a score closer to 50%.

I did suspect one thing before playing against the Mind Reader: It was based on human predictability, which I tried to avoid. It's like the classic statistics course demonstration where the professor asks the students to generate a random sequence (ones and zeros, heads and tails), and he can tell if it was generated by an actual random process or by a student trying to do an impression of a random process. Humans tend to avoid long strings of ones or zeros, incorrectly assuming that 1010110 is more random than 1111000. Knowing this, I tried to avoid obvious patterns.
A mathematical analysis of the strategy used in this machine shows that it can be beaten by the best possible play in the ratio 3:1. To do this it is necessary to keep track of the contents of all the memory cells in the machine. The player should repeat a behavior pattern twice, and then when the machine is prepared to follow this pattern the player should alter it. It is extremely difficult to carry out this program mentally because of the amount of memory and calculation necessary.

All of the above seems to have a lot of relevance to trying to predict how the average person will invest money. I intend to look into the work of von Neumann and Morgenstern to understand their approach to the problem.

No comments: