1.EQ
2delim $$
3.EN
4.ls 1
5.ce
6PROGRAMMING BY EXAMPLE REVISITED
7.sp
8.ce
9by John G. Cleary
10.ce
11Man-Machine Systems Laboratory
12.ce
13University of Calgary.
14.sp
15.sh "Introduction"
16.pp
17Efforts to construct an artificial intelligence have relied on
18ever more complex and carefully prepared programs.  While useful in
19themselves, these programs
20are unlikely to be useful in situations where ephemeral and
21low value knowledge must be acquired.  For example a person (or robot)
22working in a normal domestic environment knows a lot about which
23cupboards have sticky doors and where the marmalade is kept.  It seems
24unlikely that it will ever be economic to program such knowledge
25whether this be via a language or a discourse with an expert system.
26.pp
27It is my thesis, then, that any flexible robot system working in the
28real world must contain a component of control intermediate
29between hard wired 'reflex' responses and complex intellectual
30reasoning.  Such an intermediate system must be adaptive, be able
31to carry out complex patterned responses and be fast in operation.
32It need not, however, carry out complex forward planning or be capable
33of introspection (in the sense that expert systems are able to explain
34their actions).
35.pp
36In this talk I will examine a system that acquires knowledge by
37constructing a model of its input behaviour and uses this to select its
38actions.  It can be viewed either as an automatic adaptive system  or
39as an instance of 'programming by example'.  Other workers have
40attempted to do this, by constructing compact models in some appropriate
41programming language:e.g. finite state automata [Bierman, 1972],
42[Bierman and Feldman, 1972]; LISP [Bierman and Krishnaswamy, 1976];
43finite non-deterministic
44automata [Gaines,1976], [Gaines,1977],
45[Witten,1980]; high level languages [Bauer, 1979], [Halbert, 1981].
46These efforts, however, suffer from
47the flaw that for some inputs their computing time is
48super-exponential in the number
49of inputs seen.  This makes them totally impractical in any system which
50is continuously receiving inputs over a long period of time.
51.pp
52The system I will examine comprises one or more simple independent
53models.  Because of their simplicity and because no attempt is made to
54construct models which are minimal,
55the time taken to store new information and to make
56predictions is constant and independent of the amount of information stored
57[Cleary, 1980].  This leads to a very integrated and responsive environment.
58All actions by the programmer are immediately incorporated into the program
59model. The actions are also acted upon so that their consequences are
60immediately apparent.
61However, the amount of memory used could grow
62linearly with time. [Witten, 1977] introduces a modelling system related
63to the one here which does not continually grow and which can be updated
64incrementally.
65.pp
66It remains to be shown that the very simple models used are capable
67of generating any
68interestingly complex behaviour.
69In the rest of this
70talk I will use the problem of executing a subroutine to illustrate
71the potential of such systems.
72The example will also illustrate some of the techniques which have been
73developed for combining multiple models, [Cleary, 1980], [Andreae
74and Cleary, 1976], [Andreae, 1977], [Witten,1981].  It has also been
75shown in [Cleary, 1980] and in [Andreae,1977] that such systems can
76simulate any Turing machine when supplied with a suitable external memory.
77.sh "The modelling system"
78.pp
79Fig. 1 shows the general layout of the modeller.  Following the flow
80of information through the system it first receives a number of inputs
81from the external world.  These are then used to update the current
82contexts of a number of Markov models.  Note, that each Markov model
83may use different inputs to form its current context, and that they
84may be attempting to predict different inputs.  A simple robot
85which can hear and move an arm might have two models; one, say, in
86which the last three sounds it heard are used to predict the next
87word to be spoken, and another in which the last three sounds and the last
88three arm movements are used to predict the next arm movement.
89.pp
90When the inputs are received each such context and its associated
91prediction (usually
92an action) are added to the Markov model.  (No
93counts or statistics are maintained \(em they are not necessary.)  When the
94context recurs later it will be retrieved along with all the predictions
95which have been stored with it.
96.pp
97After the contexts have been stored they
98are updated by shifting in the new inputs. These new contexts are then
99matched against the model and all the associated predictions are retrieved.
100These independent predictions from the individual Markov models
101are then combined into a single composite
102prediction.
103(A general theory of how to do this has been
104developed in [Cleary, 1980]).
105.pp
106The final step is to present this
107composite prediction to a device I have called the 'choice oracle'.
108This uses whatever information it sees fit to choose the next action.
109There are many possibilities for such a device.  One might be to choose
110from amongst the predicted actions if reward is expected and to choose
111some other random action if reward is not expected.  The whole system then
112looks like
113a reward seeking homeostat.  At the other extreme the oracle might be
114a human programmer who chooses the next action according to his own
115principles.  The system then functions more like a programming by
116example system \(em [Witten, 1981] and [Witten, 1982] give examples of such
117systems.
118[Andreae, 1977] gives an example of a 'teachable' system lying between
119these two extremes.
120.pp
121After an action is chosen this is
122transmitted to the external world and the resultant inputs are used
123to start the whole cycle again.  Note that the chosen action will
124be an input on the next cycle.
125.sh "Subroutines"
126.pp
127An important part of any programming language is the ability to write a
128fragment of a program and then have it used many times without it having
129to be reprogrammed each time.  A crucial feature of such shared code is
130that after it has been executed the program should be controlled by the
131situation which held before the subroutine was called. A subroutine can be
132visualised as a black box with an unknown and arbitrarily complex interior.
133There are many paths into the box but after passing through each splits again
134and goes its own way, independent of what happened inside the box.
135.np
136Also, if there are $p$ paths using the subroutine and $q$ different sequences
137within it then the amount of programming needed should be proportional to
138$p + q$ and not $p * q$.  The example to follow possess both these properties
139of a subroutine.
140.rh "Modelling a Subroutine."
141The actual model we will use is described in Fig. 2.  There are two Markov
142models (model-1 and model-2) each seeing and predicting different parts of
143the inputs.  The inputs are classified into four classes; ACTIONs that
144move a robot (LEFT, RIGHT, FAST, SLOW), patterns that it 'sees' (danger,
145moved, wall, stuck) and two types of special 'echo' actions, # actions
146and * actions (*home, #turn).  The # and * actions have no effect on the
147environment,
148their only purpose is to be inputs and act as place keepers for relevant
149information.  They may be viewed as comments which remind the system of
150what it is doing.  (The term echo was used in [Andreae,1977], where the
151idea was first introduced, in analogy to spoken words of which one
152hears an echo.)
153.pp
154Model-2 is a Markov model of order 2 and uses only # actions in its
155context and seeks to predict only * actions.  Model-1 is a Markov model
156of order 3 and uses all four classes of inputs in its context.  It
157seeks to predict ACTIONs, # actions and * actions.  However, * actions
158are treated specially.  Rather than attempt to predict the exact * action
159it only stores * to indicate that some * action has occurred.  This
160special treatment is also reflected in the procedure for combining the
161predictions of the two models.  Then the prediction of model-2 is used,
162only if model-1 predicts an *.  That is, model-1 predicts that some
163* action will occur and model-2 is used to select which one. If model-1
164does not predict an * then its prediction is used as the combined prediction
165and that from model-2 is ignored.
166.pp
167The choice oracle that is used for this example has two modes.  In
168programmer mode a human programmer is allowed to select any action
169she wishes or to acquiesce with the current prediction, in which case
170one of the actions in the combined prediction is selected.  In
171execution mode one of the predicted actions is selected and the
172programmer is not involved at all.
173.pp
174Before embarking on the actual example some points about the predictions
175extracted from the individual Markov models should be noted.  First, if
176no context can be found stored in the memory which equals the current
177context then it is shortened by one input and a search is made for any
178recorded contexts which are equal over the reduced length.  If necessary
179this is repeated until the length is zero whereupon all possible
180allowed actions are predicted.
181.pp
182Fig. 3 shows the problem to be programmed.  If a robot sees danger it
183is to turn and flee quickly.  If it sees a wall it is to turn and return
184slowly.  The turning is to be done by a subroutine which, if it gets
185stuck when turning left, turns right instead.
186.pp
187Fig. 4 shows the contexts and predictions stored when this is programmed.
188This is done by two passes through the problem in 'program' mode: once
189to program the fleeing and turning left; the other to program the wall
190sequence and the turning right.  Fig. 5 then shows how this programming
191is used in 'execute' mode for one of the combinations which had not been
192explicitly programmed earlier (a wall sequence with a turn left).  The
193figure shows the contexts and associated predictions for each step.
194(Note that predictions are made and new contexts are stored in both
195modes.  They have been omitted from the diagrams to preserve clarity.)
196.sh "Conclusion"
197.pp
198The type of simple modelling system presented above is of interest for a
199number of reasons.  Seen as a programing by example system,
200it is very closely
201integrated. Because it can update its models incrementally in real time
202functions such as input/output, programming, compilation and execution
203are subsumed into a single mechanism. Interactive languages such as LISP
204or BASIC gain much of their immediacy and usefulness by being interpretive
205and not requiring a separate compilation step when altering the source
206program. By making execution integral with the process of program entry
207(some of) the consequencs of new programming become immediately apparent.
208.pp
209Seen as an adaptive controller, the system has the advantage of being fast
210and being able to encode any control strategy. Times to update the model
211do not grow with memory size and so it can operate continuously in real time.
212.pp
213Seen as a paradigm for understanding natural control systems, it has the
214advantage of having a very simple underlying storage mechanism. Also,
215the ability to supply an arbitrary choice oracle allows for a wide
216range of possible adaptive strategies.
217.sh "References"
218.in +4m
219.sp
220.ti -4m
221ANDREAE, J.H. 1977
222Thinking with the Teachable Machine.  Academic Press.
223.sp
224.ti -4m
225ANDREAE, J.H. and CLEARY, J.G. 1976
226A New Mechanism for a Brain.  Int. J. Man-Machine Studies
2278(1):89-119.
228.sp
229.ti -4m
230BAUER, M.A. 1979 Programming by examples. Artificial Intelligence 12:1-21.
231.sp
232.ti -4m
233BIERMAN, A.W. 1972
234On the Inference of Turing Machines from Sample Computations.
235Artificial Intelligence 3(3):181-198.
236.sp
237.ti -4m
238BIERMAN, A.W. and FELDMAN, J.A. 1972
239On the Synthesis of Finite-State Machines from Samples of
240their Behavior.  IEEE Transactions on Computers C-21, June:
241592-597.
242.sp
243.ti -4m
244BIERMAN, A.W. and KRISHNASWAMY, R. 1976 Constructing programs from example
245computations. IEEE transactions on Software Engineering SE-2:141-153.
246.sp
247.ti -4m
248CLEARY, J.G. 1980
249An Associative and Impressible Computer. PhD thesis, University
250of Canterbury, Christchurch, New Zealand.
251.sp
252.ti -4m
253GAINES, B.R. 1976
254Behaviour/structure transformations under uncertainty.
255Int. J. Man-Machine Studies 8:337-365.
256.sp
257.ti -4m
258GAINES, B.R. 1977
259System identification, approximation and complexity.
260Int. J. General Systems, 3:145-174.
261.sp
262.ti -4m
263HALBERT, D.C. 1981
264An example of programming by example. Xerox Corporation, Palo Alto,
265California.
266.sp
267.ti -4m
268WITTEN, I.H. 1977
269An adaptive optimal controller for discrete-time Markov
270environments.  Information and Control, 34, August: 286-295.
271.sp
272.ti -4m
273WITTEN, I.H. 1979
274Approximate, non-deterministic modelling of behaviour
275sequences.  Int. J. General Systems, 5, January: 1-12.
276.sp
277.ti -4m
278WITTEN, I.H. 1980
279Probabilistic behaviour/structure transformations using
280transitive Moore models.  Int. J. General Systems, 6(3):
281129-137.
282.sp
283.ti -4m
284WITTEN, I.H. 1981
285Programming by example for the casual user: a case study.
286Proc. Canadian Man-Computer Communication Conference, Waterloo,
287Ontario, 105-113.
288.sp
289.ti -4m
290WITTEN, I.H. 1982
291An interactive computer terminal interface which predicts user
292entries. Proc. IEE Conference on Man-Machine Interaction,
293Manchester, England.
294.in -4m
295