117WILF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Hands On: Wilf’s Programmers’ Workshop

Wilf’s
Programmers’ Workshop
Learn more about artificial intelligence techniques in the second part of
Wilf Hey’s investigation into expert programs.

magine training your to build a program that simulates Imagine that you are provided with a

I computer to
recognise concepts
rather than objects.
Last month we built an expert program,
some of the workings of the
human mind. There are several
reasons why this is a very difficult
task – first of all because we still know
photograph, and you are required to
identify whether the object portrayed is a
spade. If you can record the steps in your
thought process, you should be able to
which was able to classify objects. When comparatively little about the way our convert them into program code – at least
enough information was classified our minds work, and second because the in theory.
expert was then able to use tree- hardware in our brain functions in very One of the major problems in education
structured data to determine which of different ways from computers. is that sometimes the experts don’t know
several objects you meant when you what it is that makes them experts. For
answered relevant questions. Calling a spade a spade example, the coach who looks for new
Given enough objects, along with Consider how you might provide your PC recruits for football may swear that he has
questions that distinguish them, the expert with the knowledge of what a spade is. You an eye for a good player before even
can quickly identify anything previously could, for example, organise this seeing a demonstration of that player’s
encountered. A competent computerised knowledge with last month’s program in the football skills.
doctor can be built in a similar manner, form of probing questions – ‘Does it have a It may seem unlikely that such
asking a patient questions about disease handle?’ – Yes; ‘Does it have a flat metal expertise could be transferred to a
symptoms, leading to a useful diagnosis. blade?’ and so on. However, this hardly computer – it is intangible and undefined.
It is a totally different matter, however, matches the way a human being thinks. Yet statistical methods can be used that

Steady as she goes


ne of the things that a man-like computer
Yet it must be sensitive to significant changes. it is a wet day? You may think that this depends
O mind has to be able to do is identify the
How can it make a judgement of this type? on whether it was wet yesterday, but the
likelihood that things will continue as they have Let’s look at a simplified version of this surprising fact is that we don’t need to know
in the past. For example, the software that autopilot problem: our program should monitor a previous weather if we are armed with both the
controls an autopilot needs to recognise that single type of event and warn us when a change wet and dry impetus factors. The chance of today
there is some variation in the conditions that is greater than one might expect. Let’s say it will being wet is actually the sum of two factors:
affect it: wind speed and direction are not look at weather, with a view of deciding if it is 1. The chance that it was wet yesterday
constant, for example. changeable or not. multiplied by the ‘stay wet’ impetus factor (75
When there is little change, the autopilot We can first of all define our limits of change: per cent).
should not be making tiny, costly adjustments. if it rained yesterday, there is a 75 per cent 2. The chance that it was dry yesterday multiplied
chance of raining today; if it by the ‘become wet’ impetus factor (20 per cent).
was dry yesterday, there is an If we symbolise the likelihood that yesterday
80 per cent chance of a dry was wet as W, then the likelihood that yesterday
day today. was dry is (1 – W). Now the likelihood that it was
We can readily create a wet yesterday is really the same as the likelihood
history of the last few days, that it is wet on any day; so using a simple bit of
and note how often the algebra we can combine this information:
status changes from wet to
dry or vice versa. If it changes W = (W x 0.75) + ((1 – W) x 0.20)
from wet to dry more than
once in four instances, this is This produces a result of W equal to about 44.4
more than our 75 per cent per cent as the chance of any being wet. So we
impetus factor, so the have a very useful result: the likelihood of any
program can comment that particular day being wet is 44.4 per cent.
the weather is indeed The SuperCD/Disk contains the QBasic program
changeable. It can decide the IMPETUS.BAS which allows you to calculate this
same when it sees more than (and related) values. You can investigate its
Many events – like wet and dry days – tend to occur in
one change of dry to wet simple code to see how it makes conclusions
unbroken strings, and the likelihood of two consecutive wet within five days. about the probability of experiencing three days
days can be expressed by a value called the ‘impetus factor’. What is the likelihood that of sunshine, for example.

308 PC Plus July 1996


Hands On: Wilf’s Programmers’ Workshop

Triage and perhaps several other details would


come to mind.
ne of the most useful applications of diagnostician can be used in a doctor’s waiting Believe it or not, these sort of criteria –
O expert machine technology is triage – a room, for example, to ask sufficient questions and even several more vague – can
word borrowed from the French for separating to verify that the patient has only a simple cold become part of an expert program’s
urgent or complex cases from simple ones. You and not a ruptured appendix. memory. In this month’s SuperDisk/CD
use triage yourself when you do a quick Yet expert machines need not be limited to project we have built a simplified version of
classification of mail, putting aside envelopes triage; any information that can be absorbed such a program – one that you will have to
that look like bills for opening last. and applied by a human can be incorporated train yourself.
Sometimes you may be mistaken in a (with a little effort) into a program. Will we see After it has gone through a training
judgement, but even this rough sorting speeds autodocs – robot physicians performing life- process, STUDENT.BAS (a QBasic
up processing. Of course, you won’t rely solely preserving surgery – in our lifetime? We already program) will faithfully apply the criteria it
on this method – it is only a starting point, and commit our lives to autopilots, which has learnt. This simple implementation
errors in classification can be corrected when incorporate much of the same decision-making does not record its findings in a file, though
you actually open the envelopes. software technology. it would be easy to do if you adopt it as a
In wartime hospitals and other emergency The program STUDENT.BAS demonstrates basis for your own expert machine. In
situations, triage is used to divide the injuries how triage can be performed by a computer:
effect, each time you run it, Student starts
most urgently in need of attention from the samples are divided into two categories, and
off as an imbecile. See the panel How to
more routine. Skilled businessmen use triage to corrections are made to the rules until the
teach your Student on page 310 to learn
organise their schedules to make the most program has become expert in its predictions.
effective use of their time. After this point, the program can be used to how to turn this ignoramus into an expert.
Expert machines are especially useful for perform whatever triage is needed, separating Once you have familiarised yourself
performing triage, identifying cases that may real cases (not samples) into one category or with the program, you may wish to make
require special attention, while dealing with the another, such as ‘superficial wound’ or ‘serious changes to it so that it can selectively
more direct, simpler ones. An expert attention needed’. reload its hard-earned knowledge. You will
need to save the contents of the Rule and
Tweak$ arrays (evaluations and the
will fairly quickly convey sufficient Teaching value judgment condition names), plus Limit (the number of
information into an expert program so that A simple but useful job that we may like a rules/conditions), PosResult$ and
it can establish its own credentials as an computer to perform is to identify whether NegResult$ (the two categories).
expert. Often the program’s powers will a particular person is an ally – a person
exceed those of the original human expert. whom we will allow to look at our files and Program details
How can this possibly be so? bypass our computer lockouts. Such a Student is a fairly simple program which
Well, besides its inherent speed and guardian may be set up with a can be improved in a variety of ways, as
accuracy, the expert program can take the comprehensive database recording you desire. Here are a few interesting
opportunity to work out precise details of personal details of each ally, but this is no techniques that we have highlighted from
what the expert only knows instinctively. expert – it is a dumb servant. the source code.
The football coach may be making his What we require is a program that will We permit the specification of up to 99
selections on a combination of features, enable our computer to make intelligent variables (observations) in Tweak$. This is
some of which may not even appear to be decisions about a person, to establish arbitrary; we can easily change it. In simpler
relevant, such as size of ears. whether the person is an ally rather than to forms of Basic (for example GW-Basic) this
Provided with enough examples of the ‘know’ it from a database. would be more complex.
coach’s decisions, an expert program can How would you train a human to Instead of a FOR..NEXT loop we use
analyse exactly what the coach’s mind function in this role? Simple – you would DO UNTIL..LOOP so that we can change
knows only on an unconscious level. The outline to the person various criteria: an ally the loop variable to its maximum value (99
human coach will continue to make would be an adult rather than a child; an ally in this case) when we want to finish the
occasional errors, being not really aware of would wear a uniform, or otherwise use an loop prematurely.
how the judgements are made, but the identity card with the company’s logo on it; Student works by presenting ➜ p310
expert program he or she has trained will
operate flawlessly, effectively aware of the
hidden factor.
Statistics can become complex and
tiresome to a human being, but computers
are good at juggling figures. Using
statistical methods similar to those
employed in the program IMPETUS.BAS
(see the panel on the left Steady as she
goes) an expert program can classify the
information it gleans from sample expert
decisions, and from this create powerful
predictive calculations.
For example, fed the vital statistics
about both champion and hopeless
basketball players, it would not take long
for the computer to discover that
champions are most often rather tall.
Though this may appear obvious to virtually
any human, even without the labour of
calculation, consider that subtle and
interlocking factors may be involved with
more complex tasks. The flow of logic in STUDENT.BAS is simple: the program evaluates its observations,
formulates an educated guess, and then adjusts its rules whenever it has guessed incorrectly.

July 1996 PC Plus 309


Hands On: Wilf’s Programmers’ Workshop

How to teach your Student


his month’s project program (on the The more observations (that is, questions asked) program has become more or less an expert on
T SuperDisk/CD) is STUDENT.BAS, a QBasic or
the more expert the program will eventually identifying whether a particular sea creature is
QuickBasic program that will learn how to make
become, because distinctions between creatures a mammal or not.
distinctions between many sample objects. can be more easily made. For example, if you only You can actually use the diagnostic line to test
You can, for example, educate it in the fine art
ask about whether the creature has a caudal fin Student’s knowledge. Currently it thinks that a
of telling the difference between an aquaticand eats fish, the expert will be pretty limited sea-going mammal may have a caudal fin, eats
mammal (such as a whale, walrus, porpoise, indeed and unable to distinguish between a shark fish and has a voice; it has decided that it may
manatee) and a fish. To do so we don’t even have
and a porpoise. not have scales and it has not decided about the
to tell it the features it should look for – we will
When you have established the various possession of a tail or scales.
simply answer its questions about each creature,
observations to be made, you should leave the When enough varied samples have been seen,
and tell it whether it is a fish or a mammal.
next one blank. The program will then be primed Student may come to the conclusion that the
When you run Student you will be asked to to learn from you. It will ask for samples, and diagnostic line (quoting the values of the rules it
supply names for the Positive and Negative request that you answer a simple Y or N (for Yes has deduced) should be 1, 0, -1, 0, 0, 1 – some
results (which could be ‘Mammal’ and ‘Fish’ or No) to establish the presence or absence of whales, for example, do not eat fish. Note that if
respectively) and then to supply up to 99 each of the observations. the ‘scales’ criterion had become -1, it would
observations you would want to make. When all the questions about a particular mean that a fish must have scales – which of
sample have been course is not true.
asked, the program will It is important to remember that Student is
venture a guess at the not learning anything when its guesses are
result, and ask you to correct – it learns only from its mistakes.
mark this with Y or N as When the tutor of this program decides that it
well. If it has guessed has become expert enough and is no longer
incorrectly (and you having to adjust its rules, Student is ready to
have answered N) then graduate. A few more changes to the program
it will learn from its can turn it into a resident genius, able to sort real
mistake and modify its items into the two categories you have set. Those
rules. Note that after criteria that have a final value of 0 need not even
each guess Student will be asked – they are irrelevant. The other criteria
print a line of throw the balance in favour of the positive or
diagnostic information: negative result (one category or the other).
this is the status of its As well as remembering the rules and criteria
various rules, each with names (by storing them as files on disk) the
a value of 1, –1 or 0. changed version of Student would have to know
The result will that it is no longer learning, but expounding. You
become more and more could include a simple switch for this purpose
an educated guess, and (also written to disk), which when set would not
STUDENT.BAS is a program that learns from its mistakes, learning
how to distinguish between as many samples as you want, dividing you may eventually ask for evaluation of each result, nor modify the
them into two categories. decide that the rules further.

each of the criteria stored in Tweak$ and Rule(i) = SGN(Rule(i) + Value(i)) always give the correct guess. The best
asking you whether the object currently way to understand this is to watch it
being evaluated matches it (Y or N). In the SGN always produces a value of 1, –1 or 0, happen – set up a simple three-rule test
array named Value, 1 is used to indicate Y, so it is ideal for our circumstances. We and watch what happens to the diagnostic
or 0 for N. never want the magnitude to exceed one line. Try it in situations where all questions
In the array called Rules you’ll find a (whether positive or negative). are significant, and where one question
sequence of values which indicate the If we omitted this function, the has no significance (for example, colour
significance of the corresponding question magnitude of each rule may become quite when trying to distinguish between plants
in Tweak$: 0 means that the rule provides large, depending on how many adjustments and animals).
no clue to the final result; 1 means that the to the rules are made. It would then take Note that rules which at one point have
rule is considered to be a clue towards a many samples to make an effective change a value of 0 (having no bearing on the
positive decision; and –1 means that the to the evaluation. answer) may well end up with a different
rule is considered to be a clue towards a Remember that when Student makes result after evaluating several more
negative decision. its guesses, it does so only on the basis of samples, so even these seemingly
When we multiply each answer value whether its calculation is positive or irrelevant questions are still asked while
by the corresponding rule value, we arrive negative and not on the magnitude of the the program is in its learning mode.
at several small positive or negative values, value. The program learns more quickly If you use this program as a basis for
each contributing a particle of information when you keep these values low – close to your own expert, you will of course stop
about whether the sample object deserves zero – so that they can change from asking such insignificant questions (those
to be in one category or the other. positive to negative readily (or vice versa). with the matching rule entry having a value
All these clues are added together. If This modification of the rules by adding 0) when the program is switched into
the sum is positive, the program guesses or subtracting the corresponding answer expounding mode. See also the panel
that the positive category (whatever it is values, according to whether the program’s above, How to teach your Student, for
named) is correct; if the sum is negative, it incorrect guess was Y or N, modifies those more information.
suggests the negative category’s name. rules where you answered Y. Keep these projects to hand – last
If the calculation provides the wrong Assuming that you set up enough rules month’s expert programs, and this month’s
result for a particular sample, the rules are to distinguish between objects with Student program – because in the future
modified – the place where this happens is accuracy, and that you gave truthful we will return to the topic of expert
indicated by a comment in the program answers, the rule values will eventually systems. These both provide a good
code. Note the use of the SGN function: settle into the pattern of answers which foundation on which to build. PCP

310 PC Plus July 1996

You might also like