PRODUCT

Design

Content

Publish

RESOURCES

Blog

Careers

Docs

About

Writings

Matchboxes Playing Tic-tac-toe

Matchboxes Playing Tic-tac-toe

下棋的火柴盒

Preface: In 1961, a machine learned to play a game without a single wire, just three hundred matchboxes. Following the previous #AI series and #MarvinMinksy series. This post is co-written with Claude.


On the morning of February 24, 1956, IBM broadcast a live checkers demonstration on television. One of the players was an IBM 701, the company's first large commercial stored-program computer, a machine that filled an entire room.

IBM's founder, Thomas Watson Sr., made a point of having the company's shareholders watch, and predicted that after the demonstration IBM's stock would rise fifteen points. Supposedly it did. A few months later, Watson died. Standing behind the machine was a soft-spoken engineer in his fifties. He wasn't a mathematician or a psychologist. His specialty was vacuum tubes.

Arthur Samuel was born in 1901 in Emporia, Kansas. He studied at the College of Emporia while working on and off at General Electric in Schenectady, New York. He earned a master's degree from MIT in 1926, stayed on as an instructor for two years, and joined Bell Labs in 1928. He spent nearly twenty years there, working mainly on electron tubes, the same vacuum tubes we met in the SNARC post. During the war, he helped develop a key component of radar: a switch that kept the receiver from burning out in the instant the radar fired its powerful pulse.



In 1946 he became a professor of electrical engineering at the University of Illinois and joined a project to build one of the early electronic computers. Samuel came up with an idea: write a program that played checkers and have it challenge the world champion. If it won, there would be no better way to show everyone how powerful electronic computers could be. At the time, he thought it wouldn't be hard.

The computer wasn't finished in time, so the checkers program never got finished at Illinois either. In 1949 Samuel moved to IBM's lab in Poughkeepsie, New York, and took the checkers idea with him. He later said that the problem of writing a program that seemed intelligent took up nearly all his spare time for as long as he was at IBM.


Why Checkers

In 1952, Samuel wrote his first checkers program on the IBM 701.

He chose checkers deliberately. Its rules are much simpler than chess, with only two kinds of pieces, ordinary pieces and kings, yet it has roughly five hundred billion billion possible positions, a 5 followed by twenty zeros. Simple rules meant the program wasn't hard to write, and most of the machine's effort could go into "thinking." So many positions meant there was no way to win by working through all of them. Bellman's curse of dimensionality applied here too. The program had to learn to judge whether the position in front of it was good, without being able to calculate all the way to the end of the game.



This was the same problem Hassabis ran into as a teenager writing his Othello program. Samuel's program also had two parts.

One part looked ahead. The program spread out every possible move, and every reply the opponent could make to each one, layer by layer like the branches of a tree. It looked a few moves ahead, then used minimax, assuming the opponent would always make the move best for them, to carry the scores back from the future to the present.

The other part was the evaluation function. After looking a few moves ahead, the game was still far from over, so the program had to give those future positions a score. Samuel's approach was to pick out a set of features, like how many pieces each side had left, how many kings, who controlled the center of the board, and whose pieces were more exposed to capture, give each feature a weight, and add them up into a total score.

An evaluation function is a formula for scoring a position. It is made up of a number of features, each multiplied by a weight, and the sum is the position's score.

Up to this point, this was only a program that played checkers, not a program that learned. The weights were set by a person. If the person set them well, the program played well; if not, it kept playing badly. What Samuel wanted was for the program to adjust those weights itself.


First Impressions and Second Thoughts

Samuel had the program learn in two ways.

The first he called "rote learning." As it played, the program stored the positions it came across, along with the scores it had worked out for them. The next time it looked ahead and found a position it had seen before at the end of a branch, it didn't need to analyze it again; it simply pulled up the stored score. And that stored score had itself come from looking several moves ahead the last time. In effect, the program could see further than it appeared to. This kind of learning was very slow, but it kept improving, and it was especially useful in the opening and the endgame, where positions repeat most often.

The second kind of learning was more interesting, and it's what earned Samuel his place in the history of reinforcement learning. He called it "generalization learning," and what it adjusted were the weights in the evaluation function.

The question was which way to adjust them. The most direct approach would be to wait until the game was over, then strengthen the judgments used in that game if it was won and weaken them if it was lost. But a game of checkers can run dozens of moves, and by the end there's no way to tell which of the earlier judgments went wrong.

Samuel's idea was: don't wait for the end of the game.

Before every move, the program gave the position in front of it a score. This was its "first impression," what the evaluation function could see at a glance. Then it looked a few moves ahead, spread out the branches, and carried the scores of those future positions back, arriving at a new score. This new score was its "second thought," because it took into account what might happen over the next few moves, and it was usually more accurate than the first impression.

If the two scores differed, the evaluation function's first impression was off. So the program adjusted the weights to bring its next first impression closer to this second thought.

Here's an example. At first glance, the program thinks it has a slight edge in some position and scores it +3. After looking a few moves ahead, it finds the opponent has a double jump coming that will take two of its pieces, and the score carried back is only −5. The gap is 8 points, which means the evaluation function is too optimistic about this kind of position. So the program checks which features produced the +3. Say "control of the center" was weighted too heavily and "how exposed my pieces are" too lightly. It turns the first down a little and the second up a little.

This way, the program learned with every move, without waiting for the game to be decided. Every lookahead was a small test, with the self that thought more deeply correcting the self that thought more shallowly.

The idea is strikingly close to Bellman's equation: the value of a position can be worked out from the positions that follow it. But there is a fundamental difference. Bellman needed to know all the rules of the world in advance and sit down to calculate every situation. Samuel didn't. He had the program estimate the value of each position, step by step, from the experience of actually playing.


Two Selves

To let the program adjust its own weights, Samuel also designed a way for it to play against itself.

He ran two versions of the program at once, one called Alpha and one called Beta. Alpha kept adjusting its evaluation function during every game in the way just described, while Beta stayed fixed. The two played each other. If Alpha won, its adjusted evaluation function was better, so Beta was replaced with Alpha's current version, and the games went on. If Alpha kept failing to win, it had drifted the wrong way and needed a shake-up to start over in a different direction.

This was one of the first attempts to make a machine stronger by having it play itself. More than fifty years later, AlphaGo Zero used the same basic idea, on a scale vastly larger.

In 1959, Samuel published a paper titled "Some Studies in Machine Learning Using the Game of Checkers." In the abstract, he wrote that with only about eight to ten hours of machine playing time, the program could learn to play a better game of checkers than the person who wrote it. The term "machine learning" spread along with the paper.



Three claims about Samuel get repeated more than any others: that he coined the term "machine learning" and gave it its classic definition, "the field of study that gives computers the ability to learn without being explicitly programmed"; that in 1962 his program beat a state checkers champion; and that this was the first time a machine had beaten a human expert at a game of skill. The first is only half right, the second is wrong, and the third needs a heavy discount. That much-quoted definition can't be found in Samuel's 1959 paper. It's a later summary of his work that eventually got attributed to him.

By 1962, Samuel's program had been moved to the faster IBM 7094. In a public match, it played a Connecticut player named Robert Nealey, and won. IBM's promotional materials called Nealey a former Connecticut checkers champion and one of the best players in the country. The news spread nationwide, and many people came away believing that checkers had been conquered by a machine.

It hadn't. At the time of the match, Nealey wasn't a state champion; he didn't win that title until four years later, in 1966. He had never played in top-level events like the U.S. championship, and his reputation came mostly from beating local players. And in that game, Nealey made an obvious blunder. In the rematch that followed, Nealey won one game and drew five, and the program didn't win a single one. In 1965 the program played a few games against the world checkers champion, Walter Hellman. Hellman won all four games played by mail, and the one game played across the board was a draw.

But the impression that checkers had been solved had already taken hold. Researchers moved on to chess, and checkers was largely neglected for more than twenty years. It wasn't until 1994 that Chinook, a program from the University of Alberta in Canada, truly reached world-champion level.

Why did Samuel's program stop where it did? He gave the answer himself in his 1967 review. Generalization learning was much faster than rote learning and did surprisingly well in the middle game, but its progress soon leveled off. The reason was that all the program could adjust were the weights, while the features themselves, what counted as "control of the center," what counted as "exposed to capture," had all been chosen by a person. If the features a person picked left out something important, no amount of reweighting could make up for it. What the program could learn would never go beyond the angles a person had taught it to look from.

This was the same wall Hassabis's Othello program ran into. He had to write "bonus points for corners" in by hand, and the machine just calculated according to his intuition. It would take AlphaGo for a machine to start deciding for itself what to look at on the board.

Samuel retired from IBM in 1966 and went to Stanford as a lecturer, later becoming a research professor, and taught there until 1982. He kept improving his checkers program until later programs outclassed it completely. He also never stopped writing code. He contributed to Stanford's operating system and to Donald Knuth's TeX typesetting system, and at eighty-six he was still writing programs for multi-font printing, possibly the oldest working programmer in the world at the time. He died at Stanford Hospital in July 1990 from complications of Parkinson's disease, at the age of eighty-eight.

Yet while Samuel was at IBM getting his program to play against itself, on the other side of the Atlantic, an Englishman who had broken German codes at Bletchley Park also wanted to teach a machine to play a game. He had no IBM 701. He didn't even have an electronic computer.


1923: The Codebreaker Born in Rangoon

Donald Michie was born in 1923 in Rangoon, in what was then British Burma. He went to Rugby School and won a scholarship to study classics, Greek and Latin, at Balliol College, Oxford.



The war changed his direction. In 1942, at eighteen, Michie signed up for a course in cryptography and ended up recruited to Bletchley Park, Britain's secret codebreaking center. He was assigned to a section called the Testery, which worked on a teleprinter cipher used by the German high command; the Allies code-named it "Tunny." To break Tunny faster, Bletchley Park built Colossus, one of the world's first programmable electronic computers. Michie was among the first people to operate it.

At Bletchley Park he became a colleague and friend of Alan Turing and Jack Good. The three of them often played chess together, and often talked about a question that sounded far-fetched at the time: could a machine learn to think? The ideas Turing later put into his 1948 report, a machine educated by a schoolmaster pressing keys, were things they had already talked over at Bletchley.



After the war, Michie didn't go on with computers. He returned to Oxford, switched to biology, and became a geneticist. In the 1950s, with his second wife, the biologist Anne McLaren, he studied genetics, fertilization, and embryo transfer in mice, work that later helped lay some of the groundwork for in vitro fertilization. But he never let go of those conversations at Bletchley about learning machines.


1960: MENACE

Around 1960, Michie was working at the University of Edinburgh. He wanted to run an experiment showing that a machine could learn to play a game by trial and error. But in Britain at that time, it wasn't easy for a geneticist to get time on an electronic computer. There were very few of them, they were enormously expensive, and the queue was long. Michie didn't wait. He decided to build his own, out of matchboxes.

He chose the simplest game he could: tic-tac-toe. A three-by-three grid, two players taking turns drawing noughts and crosses, and whoever gets three in a row wins. Tic-tac-toe is simple enough that the number of possible positions is manageable, yet complicated enough that a player who moves at random will certainly lose. He named the machine MENACE, for Matchbox Educable Noughts And Crosses Engine.



MENACE was made up of about three hundred matchboxes. Each matchbox stood for one tic-tac-toe position: one of the ways the board could look when it was MENACE's turn to move. The front of each box showed that position. Tic-tac-toe seems to have a great many positions, but many of them are really the same one. Rotate a board ninety degrees, or flip it left to right, and the game itself hasn't changed at all. Michie merged these essentially identical positions into a single box, which brought the count down from several thousand to about three hundred.

Each box held colored glass beads. Each of the nine squares on the board had its own color. If a box contained beads of a certain color, that meant that in this position, the machine could play in the matching square.

Take one box as an example.

First, give each of the nine squares its own color. For instance:




A red bead always stands for the top-left corner, a cyan bead always for the center, a black bead always for the bottom-right corner, and so on.

Now look at one box. Say the board drawn on the front of this box looks like this:




There's already an X in the top-left corner and an O in the center. It's MENACE's turn, and it can't play on a square that's already taken, only on one of the seven empty ones. So this box holds beads in only seven colors: orange, yellow, green, blue, purple, white, and black. There's no red and no cyan, because those two squares are already occupied.



Drawing a bead means choosing a move. The operator reaches into this box and pulls out a bead at random. Say it's yellow: MENACE puts an X in the top-right corner. The number of beads is each move's chance. If the box holds ten yellow beads and only one green one, a yellow bead is far more likely to come out, so MENACE is far more likely to play the top-right corner. Learning means the beads for good moves keep multiplying, and the beads for bad moves keep dwindling.

When it was MENACE's turn, the operator found the box showing the current position, gave it a shake, and drew out a bead without looking. Whatever the bead's color, that's where the move went. The bead was then set down next to the box rather than put back. After the opponent replied, the operator found the box for the next position and drew another bead. By the end of a game, there would be a row of open boxes on the table, each with the bead just drawn from it sitting beside it.

At first, every box held roughly equal numbers of each color, so MENACE was basically playing at random. Michie also stocked the boxes differently depending on how far into the game they came: boxes for the first move got four beads of each color, boxes for the third move three, the fifth move two, and the seventh move one. The earlier the position, the more beads and the more variety.

When a game was over, the operator dealt with the row of open boxes according to the result.

If MENACE won, each box it had used got its bead back plus three more of the same color. If the game was a draw, the bead went back with one more. If MENACE lost, the bead didn't go back at all. That was all there was to it. After a win, every move made in that game became more likely to be drawn next time; after a loss, every move became less likely. Over many games, the beads for winning moves multiplied and the beads for losing moves dwindled, and MENACE grew more and more likely to draw a good move.

This was Thorndike's Law of Effect turned, quite literally, into a tableful of things you could see and touch. The number of beads was how deeply a move had been "stamped in." SNARC kept track of this with knobs, MENACE with beads; SNARC's knobs needed a bomber's motor to turn them, while MENACE's beads needed only a hand.

Michie played a tournament against MENACE himself, 220 games over two days, with MENACE moving first. At the start, Michie beat it easily. But after seventeen games, MENACE had abandoned every opening but one: its first move always went in a corner. By around the twentieth game, it was drawing consistently. Michie began deliberately playing odd variations, trying to set traps for it, and MENACE slowly learned to handle those too. Finally, after losing eight games out of ten in a row, Michie stopped.



A machine made of matchboxes and glass beads had gone from playing completely at random to almost never losing, in two days. It knew nothing about tic-tac-toe beyond the rules. It had no idea what "take the corner" or "block your opponent" meant, and no one had taught it any strategy. All of its skill came from the changing number of beads.

In 1961, Michie described MENACE in the Penguin Science Survey. In 1962, Martin Gardner, America's most popular mathematics columnist, wrote about it in Scientific American and designed a smaller version that used twenty-four matchboxes to learn a game called hexapawn. Readers built their own at home. One turned it into a carnival game, handing out bigger prizes as the machine got better. Another ate a piece of candy every time her machine lost a game, and said that was how she learned the game faster than the machine did. In 1963, Michie published a paper describing MENACE in detail, and that same year he founded one of Britain's first artificial intelligence research units at the University of Edinburgh.


1961: Naming the Problem

In 1961, Minsky published a long paper titled "Steps Toward Artificial Intelligence," a systematic survey of the field that had only just been given its name. In it, he singled out one particular difficulty: in a complex process made up of many steps, when success or failure finally arrives, how do you divide up the credit or blame among all the decisions that came before? He called it the credit assignment problem.



Over the course of a decade, this problem had been run into from four directions. SNARC used leaking capacitors to give the credit to the last few steps before the reward. Bellman used an equation to work values backward from the end, but he needed to know all the rules of the world in advance. Samuel used later judgments to correct earlier ones, without waiting for the end of the game. MENACE had every move in a game share equally in the result.

Each approach worked on some problem, but none could do two things at once: learn without knowing the rules of the world in advance, and reliably trace credit back to a step taken long before. Samuel came closest, but his method was never distilled into a general rule.


1968: BOXES

After MENACE, Michie applied the same idea to a harder problem. In 1968, he and his colleague Roger Chambers published a system called BOXES, which taught a machine to balance a pole standing upright on a cart.

Picture balancing a broom upright on the palm of your hand: whichever way the broom starts to fall, you move your hand that way to keep it standing. That's what BOXES had to learn. If the pole is falling to the left, should the cart be pushed left or right?

BOXES had no physical form, and that was its biggest difference from MENACE. The cart and pole were simulated on a computer. No hardware was ever built; the pole's length, weight, and friction were simply tuned to resemble a real apparatus. The algorithm itself had been written as a FORTRAN program as early as 1961, born at about the same time as MENACE.

Here's how to picture it: a track with a cart on it, and on the cart a pole that can tip to the left or right. At every moment the machine can do only one thing: push the cart left or push it right, always with the same force. No gentle nudges, no holding still, only left or right. If the pole falls over, or the cart runs into the end of the track, that run counts as a failure. The machine watches four things: where the cart is on the track, how far the pole is leaning, how fast the cart is moving, and how fast the pole is falling. Michie cut position into 5 levels, angle into 5, and each of the two speeds into 3: 5 × 5 × 3 × 3, for 225 cells in all. At any moment, the state of the cart and pole falls into one of these cells, just as a tic-tac-toe position falls into one matchbox.

Each box is home to a little "demon", and each demon holds a left-right switch and a scoreboard, recording how long the pole lasted after it last chose left, how long after it chose right, and how many times each side has been chosen. When the system enters its box, the demon checks the scoreboard and picks whichever side has the better record. There is also a "global demon." It looks at the big picture, tracking the average performance across all the boxes, and gives each little demon a "target score." When a little demon makes its choice, it weighs its own scoreboard against this target. The point is to keep any one box from settling on a direction too early and never trying the other side again. Each time the pole falls and a run ends, every box used during that run updates its scoreboard according to how long the pole lasted after that decision: the longer it lasted, the higher the decision scores. Old results are multiplied by 0.99 after each run, so the older the experience, the less it counts. The inverted pendulum went on to become one of the classic test problems in reinforcement learning research. Fifteen years later, Barto, Sutton, and their colleagues used BOXES as the point of comparison when they demonstrated their new method.


Silence

In the second half of the 1960s, mainstream artificial intelligence turned in another direction. Researchers believed the key to intelligence lay in logic and reasoning: write down enough rules and knowledge for a machine, and it would be able to think like a person. Chess programs, theorem provers, and later expert systems all went down this road. On this road, a machine didn't need to learn from experience. People would tell it everything.

In 1969, Minsky and Seymour Papert published Perceptrons, which laid out the fundamental mathematical limits of simple neural networks. The book's influence went far beyond its actual arguments. Funding for neural network research all but dried up, and the field went into a slump, a story we covered in "The Unsolvable XOR Gate."

Reinforcement learning, caught between the two, was carried on by almost no one. Samuel was still improving his checkers program, and Michie had turned to robotics and automated planning in Edinburgh. The idea that had grown out of animal experiments, that a machine could learn to do things on its own from experience, through reward and punishment, was all but forgotten by the entire field for the better part of the next decade.

In 1977, a young postdoctoral researcher named Andrew Barto arrived at the University of Massachusetts Amherst to join a research project. The project started from an idea nobody at the time took seriously: that every neuron in the brain might be a tiny hedonist. 🧪


Sources:

Preface:1961 年,有一台会学习的机器,不用一根电线,只用了三百个火柴盒。接之前的 #AI 和 #MarvinMinsky 系列,本文和claude合作完成。


1956 年 2 月 24 日早上,IBM 在电视上直播了一场跳棋演示。下棋的一方是一台 IBM 701 计算机,这是 IBM 第一台商用的大型存储程序计算机,占满了整个房间。

IBM 的创始人老 Thomas Watson 特意安排公司的股东观看这次直播,还预言演示过后,IBM 的股价会上涨 15 个点。据说股价真的涨了 15 个点。几个月后,Watson 去世了。站在这台机器背后的,是一个五十多岁、说话温和的工程师。他不是数学家,也不是心理学家,他的专业是真空管。

Arthur Samuel 1901 年出生于堪萨斯州的 Emporia,在当地的 Emporia 学院读书,期间断断续续地在纽约州 Schenectady 的通用电气公司打工。1926 年他在麻省理工学院拿到硕士学位,留校当了两年讲师,1928 年进入贝尔实验室。他在那里待了将近二十年,主要研究电子管,也就是 SNARC 那篇里讲过的真空管。二战期间,他参与研制雷达的一个关键部件:一种开关,能在雷达发射强脉冲的瞬间保护接收机不被烧毁。

1946 年,他去伊利诺伊大学当电机工程教授,参与了一个建造早期电子计算机的项目。Samuel 想出一个主意:写一个下跳棋的程序,让它去挑战世界冠军。如果能赢,这就是向所有人证明电子计算机有多强大的最好办法。那时他以为这件事不难。

计算机没能按时造出来,跳棋程序也就没有在伊利诺伊完成。1949 年,Samuel 跳槽去了 IBM 在纽约州波基普西的实验室,把那个跳棋的念头也一起带了过去。他后来说,写一个看上去有智能的程序,这个问题从此占据了他在 IBM 期间几乎所有的空闲时间。


为什么是跳棋

1952 年,Samuel 在 IBM 701 上写出了第一个跳棋程序。

他选跳棋,是经过考虑的。跳棋的规则比国际象棋简单得多,棋子只有两种,普通棋子和"王",但它的局面数量大约有五百亿亿种,也就是 5 后面跟二十个零。规则简单,意味着程序写起来不太费劲,机器的大部分力气可以花在"思考"上;局面极多,意味着不可能靠把所有局面都算一遍来取胜。Bellman 的维度诅咒在这里同样成立。程序必须学会判断:在算不到终局的情况下,眼前这个局面到底好不好。

这和 Hassabis 少年时写黑白棋程序遇到的是同一个问题。Samuel 的程序也由两部分组成。

一部分是往前看。程序把每一种可能的走法,以及对手针对每一步的所有回应,像树枝一样一层层展开,往前看几步,然后用极小化极大的办法,假设对手总会走对自己最有利的那一步,把分数从未来一层层推回现在。

另一部分是评估函数。往前看几步之后,棋局还远没有结束,程序必须给那些未来的局面打一个分数。Samuel 的做法是挑出一批"特征",比如双方各剩几个棋子,有几个王,谁控制着棋盘中央,谁的棋子更容易被吃掉,然后给每个特征一个权重,把它们加起来,得到一个总分。

评估函数是一套给棋局打分的公式。它由若干个特征组成,每个特征乘上一个权重,加起来就是这个局面的分数。

到这里为止,这还只是一个下棋程序,不是一个会学习的程序。权重是人定的,人定得好,程序就下得好;人定得不好,它就一直下不好。Samuel 想做的,是让程序自己去调这些权重。


第一印象和想过之后

Samuel 让程序用两种方式学习。

第一种,他称为"死记硬背"。程序在下棋的时候,会把遇到过的局面,连同它对这个局面分析出来的分数,一起存下来。下一次往前看时,如果在树枝的尽头碰到一个以前见过的局面,就不用再分析一遍,直接调出存好的分数。而那个存好的分数,本身又是上一次往前看了好几步才得出的。这样一来,程序实际上能看得比它表面上看到的更远。这种学习非常慢,但一直在进步,在开局和残局阶段尤其有用,因为这两个阶段的局面最容易重复出现。

第二种学习更有意思,也正是它让 Samuel 在强化学习的历史上留下了名字。Samuel 称它为"泛化学习",它调整的是评估函数里的权重。

问题在于,权重该往哪个方向调?最直接的办法,是等一盘棋下完,赢了就加强这盘棋里用过的判断,输了就削弱。但一盘跳棋可能有几十步,等到终局,早先的那些判断究竟哪一个出了错,根本无从分辨。

Samuel 的想法是:不必等到终局。

程序每走一步之前,都会对眼前的局面打一个分数,这是它对局面的"第一印象",只靠评估函数一眼看出来的。然后它往前看几步,展开树枝,把未来那些局面的分数推回来,得到一个新的分数。这个新分数是"想过之后的判断",因为它考虑了接下来几步可能发生的事,通常比第一印象更准确。

如果两个分数不一样,就说明评估函数的第一印象有偏差。程序就去调整权重,让下一次的第一印象更接近想过之后的判断。

举个例子。程序第一眼看某个局面,觉得自己略占上风,打了 +3 分。往前看了几步之后发现,对手接下来有一个连跳,能吃掉它两个子,推回来的分数只有 −5。差距是 8 分,说明评估函数对这一类局面太乐观了。于是程序检查,是哪些特征让它给出了 +3,比如"中央控制"那一项权重太高,而"棋子是否容易被吃"那一项权重太低,就把前者调低一点,后者调高一点。

这样,程序每走一步都在学习,不需要等胜负揭晓。每一次往前看,都是一次小小的考试,用"想得更深的自己"去纠正"想得更浅的自己"。

这个思路和 Bellman 的方程惊人地相似:一个局面的价值,可以从它后面的局面推出来。但两者有一个根本的不同。Bellman 需要事先知道世界的全部规则,坐下来把所有处境算一遍;Samuel 不需要,他让程序在实际下棋的经验里,一步一步地估出每个局面的价值。


两个自己

为了让程序自己调权重,Samuel 还设计了一种"自己和自己下棋"的方法。

他让程序同时有两个版本,一个叫 Alpha,一个叫 Beta。Alpha 在每一盘棋里都按上面的办法不断调整自己的评估函数,Beta 则保持不变。两个版本互相对弈。如果 Alpha 赢了,就说明它调整过的评估函数更好,Beta 就换成 Alpha 现在的样子,然后继续对弈。如果 Alpha 一直赢不了,就说明它调歪了,需要打乱一下,换一个方向重新开始。

这是让机器跟自己下棋来变强的最早尝试之一。五十多年后,AlphaGo Zero 用的是同样的基本想法,只是规模大了不知多少倍。

1959 年,Samuel 发表了论文《用跳棋游戏进行机器学习的一些研究》。他在摘要里说,只需要大约八到十个小时的机器下棋时间,程序就能学会下一手比写程序的人自己还好的跳棋。"机器学习"这个词,也随着这篇论文流传开来。

关于 Samuel,流传最广的说法有三条:他发明了"机器学习"这个词,并给它下了一个经典的定义,"让计算机在没有被明确编程的情况下学习的研究领域";他的程序 1962 年打败了一位跳棋州冠军;这是机器第一次在智力游戏上击败人类高手。第一条只对了一半,第二条不对,第三条要打很大的折扣。这个最常被引用的定义,在 Samuel 1959 年的论文里找不到。它是后人对他工作的概括,后来被安到了他头上。

1962 年,Samuel 的程序已经移植到更快的 IBM 7094 上,在一场公开比赛中对阵康涅狄格州的棋手 Robert Nealey,并且赢了。IBM 的宣传材料称 Nealey 是前康涅狄格州跳棋冠军,全美最顶尖的棋手之一。这条新闻传遍了全国,很多人由此以为,跳棋已经被机器攻克了。

实际情况并非如此。比赛时,Nealey 并不是州冠军,他直到四年后,也就是 1966 年才拿到这个头衔。他也从来没有参加过全美锦标赛这类顶级比赛,他的名气主要是在当地赢来的。而且那一局,Nealey 下出了一步明显的失误。在随后的重赛里,Nealey 一胜五和,程序一盘没赢。1965 年,程序又和跳棋世界冠军 Walter Hellman 下了几盘,Hellman 赢下了四盘通信对局,唯一的一盘当面对局是和棋。

但"跳棋已经被解决"的印象已经传开。研究者纷纷转向国际象棋,跳棋在之后二十多年里几乎被冷落。直到 1994 年,加拿大阿尔伯塔大学的程序 Chinook 才真正达到世界冠军的水平。

Samuel 的程序为什么停在了那里?他自己在 1967 年的回顾里给出了答案。泛化学习比死记硬背快得多,在中盘阶段表现得出人意料地好,但进步很快就趋于平缓。原因是,程序能调的只是权重,而那些特征,什么叫"中央控制",什么叫"容易被吃",全都是人挑出来的。如果人挑的特征本身漏掉了某种重要的东西,程序再怎么调权重也补不回来。它能学会的,永远不会超出人教给它看的那些角度。

这正是 Hassabis 的黑白棋程序遇到的同一面墙。他得亲手把"占角加分"写进去,机器只是照着他的直觉去算。要等到 AlphaGo,机器才开始自己决定该看棋盘上的什么东西。

Samuel 1966 年从 IBM 退休,去斯坦福大学当讲师,后来成为研究教授,一直教到 1982 年。他一直在改进跳棋程序,直到它被后来的程序全面超越。他也一直在写代码,参与过斯坦福的操作系统和 Donald Knuth 的 TeX 排版系统,八十六岁时还在写多字体打印的程序,可能是当时世界上年纪最大的在职程序员。1990 年 7 月,他因帕金森病的并发症在斯坦福医院去世,享年八十八岁。

然而,就在 Samuel 在 IBM 让程序自己和自己下棋的时候,大西洋另一边,一个曾在布莱切利园破译德军密码的英国人,也想让机器学会下棋。他没有 IBM 701,手边甚至没有一台电子计算机。


1923:仰光出生的密码员

Donald Michie 1923 年出生于英属缅甸的仰光。他在拉格比公学读书,拿到奖学金,准备去牛津大学贝利奥尔学院读古典学,也就是希腊文和拉丁文。

战争改变了他的方向。1942 年,十八岁的 Michie 去参加一个密码学培训班,结果被招进了布莱切利园,英国破译德国密码的秘密基地。他被分到一个叫"Testery"的部门,破解德军最高统帅部使用的一种电传打字机密码,盟军给它起的代号叫"Tunny"。为了更快地破译 Tunny,布莱切利园造出了 Colossus,世界上最早的可编程电子计算机之一。Michie 是最早一批操作这台机器的人。

在布莱切利园,他和 Alan Turing、Jack Good 成了同事和朋友。三个人常在一起下棋,也常聊一个在当时听起来很遥远的话题:机器能不能学会思考。Turing 后来写进 1948 年那份报告里的想法,由校长按键来教育的机器,他们在布莱切利园就已经聊过。

战后,Michie 没有继续研究计算机。他回到牛津,改读生物,成了一名遗传学家。1950 年代,他和第二任妻子、生物学家 Anne McLaren 一起研究小鼠的遗传、受精和胚胎移植,这些工作后来为体外受精技术打下了一部分基础。但他一直没有放下布莱切利园那些关于学习机器的谈话。


1960 :MENACE

1960 年前后,Michie 在爱丁堡大学工作。他想做一个实验,证明一台机器可以通过试错学会下棋。那时的英国,一个遗传学家要用上一台电子计算机,并不容易。计算机数量极少,价格极高,排队的人很多。Michie 没有等,他决定自己造一台。用的材料,是火柴盒。

他选了一个最简单的游戏:井字棋。三乘三的格子,两个人轮流画圈和叉,谁先连成一条线谁赢。井字棋足够简单,可能出现的局面不算太多;又足够复杂,一个只会乱下的玩家肯定会输。他给这台机器起名 MENACE,全称是"机器可教育的井字棋引擎"(Matchbox Educable Noughts And Crosses Engine),缩写恰好是英文里"威胁"这个词。

MENACE 由大约三百个火柴盒组成。每一个火柴盒代表一种井字棋局面,也就是轮到 MENACE 下棋时,棋盘上可能出现的一种样子。盒子的正面画着那个局面。井字棋看上去有很多种局面,但很多其实是同一个:一个棋盘旋转九十度,或者左右翻过来,棋局本身没有任何变化。Michie 把这些本质上相同的局面合并成一个盒子,数量就从几千个降到了三百个左右。

每个盒子里装着彩色的玻璃珠。棋盘上的九个格子,各对应一种颜色。盒子里有哪种颜色的珠子,就代表在这个局面下,可以把棋下在对应的那一格。

用一个具体的盒子来说。

先给九个格子各配一种颜色。 比如:




红珠子永远代表左上角,青珠子永远代表正中间,黑珠子永远代表右下角,以此类推。

再看一个盒子。 假设这个盒子的正面画的是这样一个棋盘:




左上角已经有一个叉,正中间已经有一个圈。这时候轮到 MENACE 下,它不能下在已经有子的地方,只能下在剩下的七个空格里。所以这个盒子里只放七种颜色的珠子:橙、黄、绿、蓝、紫、白、黑,没有红,也没有青,因为那两格已经被占了。

摸珠子就是选一步棋。 操作的人从这个盒子里随手摸出一颗,比如摸到一颗黄珠子,就在右上角画一个叉。珠子的数量就是每步棋的"机会"。 如果盒子里黄珠子有十颗,绿珠子只有一颗,那摸到黄珠子的机会就大得多,MENACE 就更可能下右上角。学习,就是让好棋的珠子越来越多,坏棋的珠子越来越少。

轮到 MENACE 下棋时,操作的人找出画着当前局面的那个盒子,摇一摇,闭着眼睛摸出一颗珠子。珠子是什么颜色,就在对应的格子上落子。然后把这颗珠子放在盒子旁边,先不放回去。对手走一步之后,再找下一个局面的盒子,再摸一颗珠子。一盘棋下完,桌上会留下一排打开的盒子,每个盒子旁边放着一颗刚才摸出来的珠子。

一开始,每个盒子里各种颜色的珠子数量都差不多,所以 MENACE 基本是在乱下。Michie 还根据棋局进行到哪一步,给盒子放了不同数量的珠子:第一步的盒子,每种颜色四颗;第三步的盒子,每种颜色三颗;第五步两颗;第七步一颗。越早的局面,珠子越多,变化越大。

一盘棋结束后,操作的人要根据输赢,处理桌上那排打开的盒子。

如果 MENACE 赢了,每个用过的盒子里,除了把摸出来的那颗珠子放回去,还要再加三颗同样颜色的珠子。如果是平局,放回那颗珠子,再加一颗。如果输了,那颗珠子就不放回去,直接拿走。就这么简单。赢了,这盘棋里走过的每一步,下次被摸到的机会都变大了;输了,每一步被摸到的机会都变小了。下得多了,导向胜利的走法珠子越来越多,导向失败的珠子越来越少,MENACE 摸出好棋的概率就越来越高。

这就是 Thorndike 的效果律,原原本本地变成了一桌子看得见、摸得着的东西。珠子的多少,就是一个动作被"印刻"得有多深。SNARC 用旋钮记录这件事,MENACE 用珠子;SNARC 的旋钮需要一个轰炸机马达去拧,MENACE 的珠子只需要一只手。

Michie 亲自和 MENACE 下了一场锦标赛,两天里一共下了两百二十盘,MENACE 先走。一开始,Michie 轻松就能赢它。但十七盘之后,MENACE 已经放弃了其他所有的开局,只把第一步下在角上。到第二十盘左右,它已经能稳定地下成平局。Michie 开始故意走一些不太正常的变化,想设陷阱把它绊倒,MENACE 也慢慢学会了对付这些变化。最后,在连续十盘里输掉八盘之后,Michie 停了下来。

一台由火柴盒和玻璃珠组成的机器,从完全乱下开始,用两天时间,下到了几乎不会输的水平。它不知道井字棋的规则以外的任何东西,不知道什么叫"占角",不知道什么叫"堵住对方",没有任何人教过它策略。它所有的棋艺,都来自珠子数量的变化。

1961 年,Michie 在《企鹅科学综览》上介绍了 MENACE。1962 年,美国最受欢迎的数学专栏作家 Martin Gardner 在《科学美国人》上写了它,并设计了一个更小的版本,用二十四个火柴盒学下一种叫"六兵棋"的游戏。读者们纷纷在家里自己做。有人把它做成游乐会上的游戏,机器越下越好,奖品也就越给越多。还有一个读者,每当她的机器输一盘,她就吃一颗糖,她说这样她自己学会这个游戏,比机器还快。1963 年,Michie 发表了详细描述 MENACE 的论文,同一年,他在爱丁堡大学成立了英国最早的人工智能研究单位之一。


1961:给问题起名字

1961 年,Minsky 发表了一篇长文,题为《迈向人工智能的步骤》,系统地梳理了这个刚刚有了名字的领域。他在文中专门讨论了一个难题:在一个由许多步骤组成的复杂过程中,当成功或失败最终到来时,怎么把功劳或责任分配给之前的每一个决定。他把它叫做功劳分配问题。

这个问题在十年之间,被从四个方向碰到过。SNARC 用漏电的电容,把功劳交给奖励到来之前的最后几步。Bellman 用方程把价值从后往前倒推,但需要事先知道世界的全部规则。Samuel 用后来的判断去修正早先的判断,不必等到终局。MENACE 让一盘棋里的每一步平分输赢。

每一种办法都在某个问题上管用,但没有一种办法能同时做到两件事:既不需要事先知道世界的规则,又能可靠地把功劳追溯到很久以前的那一步。Samuel 离这个目标最近,但他的方法从来没有被提炼成一条通用的规则。


1968:BOXES

MENACE 之后,Michie 把同样的思路用到了一个更难的问题上。1968 年,他和同事 Roger Chambers 发表了一个叫 BOXES 的系统,让机器学会平衡一根立在小车上的杆子。

想象把一根扫帚竖在手掌上,扫帚往哪边倒,手就往哪边挪,才能让它一直立着。BOXES 要学的就是这件事:杆子往左倒,小车该往左推还是往右推?

BOXES 没有实物,这是它和 MENACE 最大的不同。小车和杆子是在计算机里模拟出来的,没有造出硬件,只是把杆子长度、重量、摩擦这些参数调得像一个真实的装置。算法本身早在 1961 年就写成了 FORTRAN 程序,和 MENACE 差不多同时诞生。

它的结构可以这样想象:一条轨道,上面一辆小车,车上竖着一根可以左右倒的杆子。机器每一刻只能做一件事:用固定大小的力把小车往左推,或者往右推。不能轻推、不能不推,只有左和右两个选项。杆子倒下,或者小车撞到轨道尽头,这一轮就算失败。机器看的是四样东西:小车在轨道上的位置,杆子倾斜的角度,小车的速度,杆子倒下的速度。Michie 把位置切成 5 档,角度切成 5 档,两个速度各切成 3 档,5 × 5 × 3 × 3,一共 225 个格子。任何一刻,小车和杆子的状态都会落进其中某一个格子,就像井字棋的局面落进某一个火柴盒。

每个盒子里住着一个"小魔鬼",每个小魔鬼手里有一个左右开关,还有一块记分板,分别记着"上次我选左,杆子之后撑了多久"”选右又撑了多久",以及左和右各被选过几次。系统一进到这个盒子,小魔鬼就看记分板,哪边的成绩好就选哪边。还有一个"总魔鬼"。 它看的是全局,统计所有盒子加起来的平均表现,给每个小魔鬼发一个"目标分"。小魔鬼做决定时,会把自己的记分板和这个目标分放在一起比较。这样做是为了防止某个盒子太早认定一个方向、再也不去试另一边。每一轮杆子倒下之后,每个这一轮用到过的盒子,都会根据"做了这个决定之后,杆子又撑了多久"来更新记分板,撑得越久,这个决定的分数越高。旧的成绩每轮打九九折,越早的经验分量越轻。倒立摆后来成了强化学习研究里最经典的测试题之一。十五年后,Barto、Sutton 和他们的同事,正是拿 BOXES 当作对照,演示了他们的新方法。


沉寂

1960 年代后半期,人工智能的主流转向了另一个方向。研究者们相信,智能的关键在于逻辑和推理:给机器写下足够多的规则和知识,它就能像人一样思考。下棋程序、定理证明程序、后来的专家系统,都走的是这条路。在这条路上,机器不需要从经验里学习,人会把一切都告诉它。

1969 年,Minsky 和 Seymour Papert 出版了《感知机》,指出了简单神经网络在数学上的根本局限。这本书的影响远远超出了书中的论证本身,神经网络研究的经费几乎断绝,这个方向随之进入低谷。这段历史,我们在《不可解的 XOR 异或门》里写过。

强化学习这条线,夹在两者之间,几乎无人继续。Samuel 还在改进他的跳棋程序,Michie 在爱丁堡转向了机器人和自动规划。从动物实验里长出来的那个想法,机器可以靠奖励和惩罚,自己从经验里学会做事,在接下来的将近十年里,几乎被整个领域遗忘了。

1977 年,一个叫 Andrew Barto 的年轻博士后来到麻省大学阿默斯特分校,加入了一个研究项目。项目的出发点,是一个当时没有人当真的想法:大脑里的每一个神经元,也许都是一个小小的享乐主义者。🧪


来源: