jeudi 9 janvier 2020

Exclusive selection

How are Geiger counters and what makes human brains unique related? There's a much more specific answer than "human brains came up with Geiger counters, and crow brains procrastinated for too long and didn't."

In my post-before-last I made passing mention of a board game called Nim and its role in the history of computing. Actually, Nim is more of a matchstick game than a board game, but that doesn't matter! Nim is normally played with 4 rows of matchsticks, arranged in counts of 1, 3, 5, and 7 (that's a total of 16 matchsticks). Other counts work. And you could use tallies in orange chalk, pennies, donkeys, or whatever. What matters is that we have several different groups of items. Each row is a group. Mathematically, each row is actually a set, in our case a set of distinct matchsticks sharing the same row. Synoptically, Nim is an ancient Chinese game about sets and how many items are in them. But it's more fun to pick up matchsticks than to think of mathematical sets, sizes of sets, etc. (Play it here. The player who picks up the last matchstick loses.)

Ok, but what about the history of computing? On September 24, 1940, Edward Condon, a 38-year-old physicist, patented a machine called the Nimatron that he'd recently presented at the 1939-1940 World's Fair in New York. The showcase at the fair had taken place on May 11, and he'd filed for a patent a couple weeks earlier, on April 26. This machine could play Nim better than most humans. Indeed, it won 9 out of every 10 games.

The idea of robots was not new to fairgoers. One of the attractions was a man dressed up in a metallic (bronze? tough to tell in black and white) suit, talking in staccato fashion about having a mind. (Correction: that "man dressed up" was actually the robot Elektro. It had me fooled!) Other attractions prompted audience discussions about the new, advanced mechanization in factories putting workers out of jobs. At least one person took the other side of the old fence and said what AI researchers like to say today: that the widespread fear of lost jobs had not actually happened, because mechanization changes the nature of our human roles and therefore of our jobs. The debate continues more than 200 years after it started. But all that aside, it's something quite different to walk up to a machine that promptly outsmarts you.

That's what happened for about 90,000 visitors at the fair, out of perhaps 100,000 who played the Nimatron. What's particularly interesting about the patent on this machine is that it's earlier than the first general computer, yet it uses a similar process. Somewhere in the back of Condon's mind, he was aware that more could be done with the gadgetry he was assembling. It could do more than just beat fairgoers at matchsticks (represented by lightbulbs).

A year later, in May, 1941, a machine developed by Konrad Zuse, the Z3, became the first general, digital computer, a contraption broadly equivalent to whatever you're reading this post on, just slower and with less memory. The principle had been worked out, the invention built. And it worked. (I'm simplifying here. Yes it worked, but if Condon didn't know the full capabilities of the process, neither did Zuse. As far as the latter was concerned, this was a very effective calculator. No one knew his Z3 was a computer in the proper sense until work in the 90s proved it. However, this began a lifelong career in computer science and engineering and manufacturing. He did knowingly build computers later. He was the first. He cracked it.) Let's return to Zuse's computer in a moment, though. After all, the Nimatron had in some ways beaten it to the punch.

One thing that made Nim particularly suited to such early development is that the winning strategy relies on binary numbers. It's actually quite easy, if you know how to count in binary.

1) Convert every row's matchstick count into the equivalent binary number.

2) Cross off pairs of identical digits. That is, with these binary numbers stacked up and alined on their right sides, just as in grade-school addition, go down each column and cross off any pairs of 1s that you find. For example, if there are three 1s in the rightmost column, cross off two of them, and bring the last down, writing 1 under the column. If there were five, you'd cross of two pairs, or four of them. You'd also write 1 underneath. If there are four, cross off all four. Write 0 underneath. Everything canceled this time. If there's one, don't cross off any. Write 1 underneath. This process will result in a new binary number made of the straggler 1s for columns that weren't completely canceled out. At most a single 1 will be left for each column. Like with grade-school addition, each column represents a specific place value, a specific location in the final answer. You get a new binary number, but the value of that number isn't important. What we care about is whether it's 0 or not. When you receive a board position that produces 0, that's bad.

3) For your next move, make the sum 0. If at all possible, that's what you want to do. And while you're at it, remove as many matchsticks as possible to do so. Making a move in Nim (I should have said this before, but there's no time like the present) means choosing a row and choosing a number of matchsticks to remove from it. You can remove any number of matchsticks, but only from one row, and you have to remove at least one matchstick. Do this so that the process in step 2 passes a 0 to your enemy to deal with, every turn (except the last, when you craftily leave them the final matchstick so they lose), and you will definitely win.

Step 2 actually amounts to performing the XOR (exclusive or) operation on the numbers, something very easy to accomplish with gizmotry, and a core operation in computing. It's also very easy for humans when we line the numbers up vertically on paper, as in normal addition. Step 2 may sound complicated, but I could teach you to do it in about one minute, even if the words above make no sense.

Following this strategy assures a win if you are the second player. If you are the first, it assures a win if your partner (opponent) makes a mistake. Otherwise, they have the advantage and can always win by following the strategy exactly. Summary: be the second player. Other summary: if you're the first player, you may be out of luck, but try to distract your opponent. Skeleton key: use the strategy.

What about Geiger counters? I was getting to that.

Ok, the Nimatron was born in a moment of inspiration. Edward Condon was working with Geiger counters, and he suddenly realized the internal mechanics could do something more than just counting. (I don't understand the details, as I've yet to research the claim "he realized that the same calibration circuits used in Geiger counters (although built with ordinary electromagnetic relays, not by valves), can be used to represent the numbers defining the state of a game.") Fast forward a bit, and he's built this clever party trick that's perplexing people at a New York City fair.

What just killed Edward was that he could have gone about a million steps further, without too much additional effort. The same principle and the same components are what got Konrad Zuse's contraption calculating, well, uh, in theory, anything that could ever be calculated. That's more than a game of Nim. No matter how much you like Nim, you have to admit that "anything that could ever be calculated" is a rather larger prize.

You may think I've now connected Geiger counters and what makes human minds special, right? But there's something I've kept up my sleeve, and if you've been reading the science news lately, you may have noticed.

Breaking news, then. Some neuroscientists have been examining layers two and three of the human cerebral cortex. These are the layers of cells that seem to be most unique to us. They're much thicker in humans than in our closest animal relatives. The cerebral cortex itself, of course, is also much bigger, but just blowing up the square meterage isn't necessarily going to make for qualitatively different experiences and powers. Something about layers two and three, though, stood out. What stands out on closer examination is that the cells in these layers can compute XOR.

This may not seem impressive. After all, I promised I could teach you to do an XOR on several binary numbers in one minute. And it seems to be the easiest thing a computer can do. Why is this impressive at all?

I know, it doesn't seem impressive, right?

Let's talk about neural networks for a minute. The earliest attempts to model human brain tissue resulted in what are now called, depending on context, finite-state automata, regular expressions, or regular grammars. To put it simply, when you sign up for a new account online and it gives you some rules for what your password should be like, the code that checks your password against those rules is a finite-state automaton. More to the point, the rules themselves are represented as a finite-state automaton. It's sort of like a mini, prototype brain that can only say whether your new password follows the rules given. You can actually think of the rules as the finite-state automaton (or regular expression, or regular grammar—the analogy with grammar, rules about letters, may possibly make more sense now). It's primitive, but that was our first semi-successful attempt to model brain tissue. We now use it all over the world trillions of times a second, if not more, as these conceptual rule widgets are at the heart of all coding languages in practical use. These are not neural networks, mind you. That was the next innovation.

Neural networks, to make a long story short, and I mean the artificial kind (ANNs, for artificial neural networks), use matrix math to try to match human pattern recognition and pattern creation. These networks of matrices can approximate any information process you want, using calculus behind the scenes to learn the right numbers to put in the matrices. This is much like, though not identical to, the way your brain can learn a vast array of different processes just by tweaking some connections with experience. And that is no coincidence. We were trying to mimic human learning, and, though it took a couple generations to get things moving at a good clip, today I think we can say we've succeeded far better than most people believed we would, even many who were working in the field.

"XOR, you promised XOR," I hear you saying. The most famous result early in research on artificial neural networks and their properties was that these networks, though they could learn many processes, could not learn XOR. This one little observation put a chill on the field for decades, because people who didn't entirely know what they were saying went around repeating the finding to each other. It became fashionable to make fun of ANNs for being overhyped, so overhyped they couldn't even do XOR. Ha ha. How silly those ANNs are.

ANNs can do XOR, actually. It just takes more layers of artificial neurons. While it is true that, using the basic matrix method we knew about decades ago, a single neuron (or even a single layer of neurons) cannot do XOR alone, just by looking at its inputs, it is also true that groups of neurons working together can do the same work as a single XOR operation. It's a group effort, if you will.

This may sound like a limitation of artificial neural networks, but actually all biological neurons examined until perhaps this last year—whenever the new finding occurred—had the same limitation as the simplified, mathematical, artificial neurons I've been talking about. There are no chimpanzee neurons that are known to be able to do XOR. Not without teaming up.

Yet the "most different" part of our brains has just been found to contain neurons that, completely on their own, can compute XOR.

So when I said I could teach you XOR in a minute, that's a funny statement. You have many cells that are doing XOR independently. I'd just be showing you how to do what a single one of your brain cells already knows how to do!

***

Maybe you'd use this capacity intuitively if you were playing Nim by the winning strategy. Instead of tallying things up, as in the 3 steps I give above, you could use your eyes.

As we scan the rows of matchsticks, we're looking for powers of 2. That's 1, 2, 4, 8, 16, 32, 64... but the only ones that show up for 16 matchsticks arranged into 4 rows are 1, 2, and 4. The setup of the game shows you: a row with 1 matchstick, a row with 1 matchstick and then 2 matchsticks, a row with 1 and 4 matchsticks, and a row with 1 and 2 and 4 matchsticks. That's the result of grouping into powers of two.

1
1 + 2
1 + 4
1 + 2 + 4

Which on the board looks like

|
| | |
| | | | |
| | | | | | |

Personally, I find it easier to think in big numbers first here, like this:

1
2 + 1
4 + 1
4 + 2 + 1

Mathematically it's identical either way, for the purposes of Nim (and addition, and XOR).

So you could see this:

|
| |   |
| | | |   |
| |   | | | |   |

Or this:

|
|   | |
|   | | | |
|   | |   | | | |

Or lining things up:

|
|   | |
|         | | | |
|   | |   | | | |

It's all equivalent.

You want there to be an even number of every group.

Wherever you see one of the clusters, look for another cluster just like it to cancel it out. If you don't find one, or if the other one has already been used to cancel another cluster, then the board is unbalanced. Every time you move, you want to make the board visually "balanced" in this way. That's it. That's basically the entire strategy. With only a few minutes of practice, you can "see" it. In this first board position, everything cancels out with another group.

I
I   | |
|         | | | |
|   | |   | | | |

|
|   | |
I         | | | |
I   | |   | | | |

|
|   I I
|         | | | |
|   I I   | | | |

|
|   | |
|         I I I I
|   | |   I I I I

Let's revisit XOR now. XOR in general means: "We're good as long as exactly one of the options passes. No more, no fewer. One."

Either you eat an apple, or you eat an orange, or you eat a grape.

Feel free to skip the next paragraph if this is crystal clear.

This rule is being followed if you eat an apple. It's being followed if you eat a grape. It's being followed if you eat an orange. It is not being followed if you eat nothing. It is not being followed if you eat an apple and a grape, or an apple and an orange, or a grape and an orange, or an apple and a grape and an orange. Just want to be complete about this XOR example! Many things are obvious until they aren't.

Apple XOR Orange XOR Grape. Pick a fruit and stop, and you're following my rule. Take exactly one.

The player who picks up the last matchstick loses, so perhaps you're thinking ahead and you see how that implies XOR. I'll give you a hint: the last. But it doesn't work how you'd expect. It works in the opposite way.

For our Nim strategy, the XOR we use means something like: "If there's exactly one uncanceled group for a given group size, then that's good for Satan." (I mean our opponent, sorry. Just trying not to mince words.) Basically, we want to break XOR every time it's our turn. We don't want to hand the matchsticks over in an XOR-abiding situation. We want to keep the rule broken for our opponent every time they see the board on their turn. There should be no lonely "exactly one" cluster. All the groups should be balanced, fully canceled out. It's a little counterintuitive, because at the end, on our opponent's last turn, the moment they lose, they'll be looking at nothing but an uncanceled group of 1 matchstick. You see, if you resist leaving the board in an unbalanced, XOR-abiding configuration, then because of the way the game works, this means you can put it in an XOR configuration in the final moment. On your last turn only, you make the board XOR-friendly. The player who picks up the last matchstick loses.

This was the first computerized game because the strategy's logic is so simple to apply with XOR. And the game is still kind of fun, because most people won't figure out the strategy on their own. (I didn't. In a few dozen games trying to figure out how the computer kept winning, I worked out that it was probably related to even versus odd numbers. That's as far as I got.)

Maybe detailing XOR for Nim hasn't helped anything. But I will claim that it quickly becomes possible to see the strategy. And after all, maybe that suggests individual neurons are handling the XOR. Is that necessarily true? No, I see no reason to believe that. But when you watch your own mind clasp these either/or calculations visually, and then looking for the odd group out becomes effortless, you have a more visceral appreciation of what those individual neurons just discovered are doing.