Beej's Lab1

Introduction

I've implemented a highly intelligent rule-based system that generates write-ups very similar to the one you're reading now. I tell a lie; it is generating this report right now!

Well, really it isn't, but I felt inclined to begin this "write-up" on the other foot, as it were. After all, since this is merely a write-up (as opposed to a "paper", "term paper", or (heaven forbid) a "thesis"), it should be acceptable to undergo a reasonable amount of silliness over the course of this document.

Finally, what I have implemented: a Prolog backward-chaining expert system that will help backyard stargazers (of the naked-eye and binocular calibre) to identify (classify) exactly what type of astronomical object they're looking at. For instance, it could help answer the question, "Hey! What's that fuzzy thing in Sagittarius?" by going through a list of questions that will help it understand the situation. (Ideally, my expert system would reply, in a Mr. T voice, "It's the Trifid Nebula, Fool!" but it has yet to progress that far.)

It is my hope that my rule-based system will become self-aware after a certain number of runs, but this is not demonstrated in this paper. (Or rather, "in this write-up".)

Background

The Universe was created somewhere in the range of 20 billion years to 6,000 years ago, depending on who you ask and how gullible they are. The event of my writing this expert system was precipitated by countless other actions and reactions since the beginning of time and I would be hard pressed to condense them all to fit on a single page. Therefore, what follows is the condensed version of these events.

About 13 billion years ago (probably), the universe may or may not have been created in an event that many people like to believe was something which has come to be generally known as the "big bang". This scattered all kinds of crap everywhere which eventually turned into people, slugs, birds, trees, automobiles, and David Hasselhoff. In addition, it created all kinds of nifty matter that condensed into stars, planets, galaxies (sponsored by the Force of Gravity), nebulae, comets, and Cary Grant.

Gazing around the sky, you can see many of these objects using your naked-eye or binoculars while engaging in an activity commonly known as "backyard astronomy" to us amateurs. Often times you will come across a fuzzy speck and your heart will miss a beat as you think to yourself, "I have discovered Comet Beej!" until you check your star chart and realize that you're simply looking at a globular star cluster in Hercules.

With this in mind, I've written an expert system that will help narrow down the possibilities of what you're looking at so that I get a good grade in this class people, um, get a better understanding of what stargazing is all about and don't waste any of the good peoples' time at the International Comet Registry with false discoveries.

There are a couple things that I ought to define before you see the source so you don't sit there thinking, "Beej just made all this up to look cool--I wonder what it means?" One is the magnitude of an object. In a nutshell, it's the brightness. Except it's not a nice normal scale that you'd hope for; see, the brighter the object, the lower its magnitude. Stars in Ursa Major are about magnitude 2, and the dimmest stars you can see with your naked-eye are magnitude 6 (or 8 if you hyperventilate pure oxygen for 10 minutes). Venus can be magnitude -4 at times, the moon -10, and the sun -22. The expert system considers "bright" to be brighter than magnitude -8.

The expert system also has a concept of "large". This means that the object appears to cover more than two degrees of sky. The moon covers 2.5 degrees. (You can cover the entire disk of the full moon with your thumb held at arms' distance--that's how small it really is.)

As an astronomical reference, I offer myself, as I have been stargazing since I was about 13 years old. But that's not all! Order now, and I'll also offer "Stargazing" by David Levy as a reference. Yes, from the guy who put the "Levy" in "Comet Shoemaker-Levy" (the one that crashed into Jupiter) comes a wonderful book with plenty of knowledge for my petite expert system.

Other works in this field

None.

Well, there are rather a lot, actually. (In the immortal words of Graham Chapman, "When I say 'none', I mean a certain amount.") There are none that I have found that cater to the amateur astronomer, as such, but there are plenty that have to do with data processing (http://www.stsci.edu/~miller/draco/draco-aldb.html). This is understandable, since astronomers must regularly deal with countless reams of data of all sorts: catalogs of 16 million stars, millions of galaxies, ephemerides of comets, planets, and asteroids, etc., etc. It could be said that astronomical information exists as an open universe in its own right, since it will continue to expand forever.

Not all such programs are so dull, however. There are expert systems that deal with scheduling Hubble observations (http://www.stsci.edu/apsb/doc/papers-and-meetings/93-Intelligent-Scheduling/spike/spike-chapter3.html). There's another that helps telescopes at SEASU Observatory align on target stars (http://www.math-science.sfasu.edu/mapserve/schoolscimath/physics/obs.htm). In a nutshell, there are tons of systems out there. None are as simplistic, however, as mine is.

What I Actually Did

Although my system fell short of my actual goal of becoming self-aware (or at least doing my laundry until then), it will identify classes of objects. It will, as it gathers more information from the operator, focus in on sub-classes of objects for a more vivid description.

The classes and subclasses of objects defined for the system are:

Each of the above objects has a set of basic attributes that uniquely identify it. These attributes (such as "fuzzy", "bright", or "moving") are what the user is queried on. By adding these user observations of the object as facts in the system, it can narrow the possibility of what an object might actually be.

The Solution

The source for my project is split into several sections, each a grouping of rules serving a different function.
  1. The itsa/1 predicate is defined. This predicate will be used to help identify objects. A user could verify an object type by specifically querying:

        ?- itsa('spiral galaxy').
    

    or could ask the program to hunt through everything it knows by querying:

        ?- itsa(X).
    

    The itsa/1 predicate simply maps nice human readable strings to other predicated defined in the next section of code.

  2. This section defines the attributes of actual astronomical objects. Some of these are the base attributes that will be asked of the user, and others are other objects themselves. For instance, a comet is fuzzy and a planetoid, but a planetoid moves against the background. An object will not be identified as a comet unless it is identified as a planetoid first.

  3. Finally, each of the base attributes is defined. Rather than simply setting these to "true" and "fail" and letting the user modify the source on every run, I've implemented an ask/1 predicate that will prompt the user, say, "Does the object ever appear as a crescent?" The ask/1 predicate is defined below, and is dependent on the asked/1 predicate defined next:

  4. The asked/1 predicate keeps track of which questions have already been asked. It's initialized to "fail" for each question (no questions have been asked) and each is asserted in the ask/1 predicate as it happens.

  5. Lastly, the ask/1 predicate checks to make sure it hasn't asked this question yet, then asserts that the question has been asked, prints the question, reads input, and asserts the question as true if the user entered 'yes'. Between ask/1 and asked/1, each base attribute will be either "true" or "fail" once the question has been asked.

Sample Run

This first sample run shows the user trying to verify that an object is an inner planet (orbits closer to the sun than the Earth does). This is accomplished through specific use of the itsa/1 predicate:

    Welcome to SWI-Prolog (Version 2.7.20)
    Copyright (c) 1993-1996 University of Amsterdam.  All rights
    reserved.

    For help, use ?- help(Topic). or ?- apropos(Word).

    1 ?- consult(astro2).
    astro2 compiled, 0.02 sec, 13,376 bytes.

    Yes
    2 ?- itsa('inner planet').
    Does the object appear to move against the stars? yes.
    Does the object appear as a disk? yes.
    Does the object ever appear as a crescent? yes.

    Yes
    3 ?- itsa('planetoid').

    Yes
    4 ?- _

Notice that the results of the "inner planet" query have now determined that the object is a planetoid. Asking itsa('planetoid') now returns "true" no questions asked.

This next run demonstrates what might happen if a user were trying to identify the Beehive Cluster (Messier object 44--I told you they like to catalog everything), an open cluster in Cancer. (An open cluster is a loose gravitationally bound collection of a few stars within the plane of the galaxy.)

    2 ?- itsa(X).
    Does the object have a fuzzy appearance? yes.
    Does the object appear to move against the stars? no.
    Can you resolve individual stars in the object? yes.
    Is the object a single point of light? no.

    X = cluster ;
    Is the object larger than 2 degrees across? no.
    Does the object consist of more than 40 stars? no.

    X = 'open cluster' ;

    No
    3 ?- _

The final "No" is an artifact of the ask/asked relationship and how it is used to determine an attribute status. It would certainly be an improvement to get this to say "Yes" when it makes a possible identification.

The code can be optimized somewhat, as well. The questions are duplicated in the ask/1 and asked/1 predicates, and this could be removed. The itsa/1 predicate is in its entirety a redundancy which could be commutatively removed.

Finally, I believe that a more "proper" design (as only experience can teach) observed from the beginning could have eliminated the need for the asked/1 predicate all together, but that's probably destined to be remain more of a gut-feeling than a reality.

Limitations, Goodness, and the Future

There are a lot of oversimplifications in the code that are meant to make my life easier as a coder, but have an adverse effect on actual object identification. For instance, the Beehive cluster is bigger than the full moon, but that is the exception, not the rule for clusters. It would convolute my definition of "large" to have it large and not the others. So, I lie and say the Beehive cluster is smaller than 2 degrees.

So, is the program really "good"? Well, let's not beat around the bush: it's pretty useless as it stands. It's more of a toy to examine expert systems than an expert system in its own right. I'd have to add a lot of rules and questions, and really describe each object type in detail. A special case to handle the Beehive Cluster would not be out of the question. As a teaching tool, well, maybe, but the type of amateur astronomer who already takes his computer out back to gather CCD deep sky images through his 6" Schmidt-Cassegrain has no need for this kind of program to begin with.

On this other hand, if the program were coupled with some kind of image analyzing software, it might be able to identify objects in a photograph, for instance. Of course, this would take some seriously tricky code to handle things like comets moving across the sky. I'll bet there are already systems out there to do this kind of thing (a supernova hunter comes to mind) but I can't locate any references.

In lieu of a conclusion, I'd like to add the following bit of logic from Douglas Adams' "Hitchhikers Guide to the Galaxy", as it is somewhat analogous to my mental processes while I was trying to wrap my head around this whole expert systems thing:

The Babel fish is small, yellow and leechlike, and probably the oddest thing in the Universe. It feeds on brainwave energy received not from its own carrier but from those around it. It absorbs all unconscious mental frequencies from this brainwave energy to nourish itself with. It then excretes into the mind of its carrier a telepathic matric formed by combining the conscious thought frequencies with nerve signals picked up from the speech centers of the brain which has supplied them. The practical upshot of all this is that if you stick a Babel fish in your ear you can instantly understand anything said to you in any form of language. The speech patterns you actually hear decode the brainwave matrix which has been fed into your mind by your Babel fish.

Now it is such a bizarrely improbable coincidence that anything so mind-bogglingly useful could have evolved purely by chance that some thinkers have chosen to see it as a final and clinching proof of the nonexistence of God.

The argument goes something like this: "I refuse to prove I exist," says God, "for proof denies faith, and without faith I am nothing."

"But," says Man, "the Babel fish is a dead giveaway, isn't it? It could not have evolved by chance. It proves you exist, and so therefore, by your own arguments, you don't. QED."

"Oh dear," says God, "I hadn't thought of that," and promptly vanishes in a puff of logic.

"Oh, that was easy," says Man, and for an encore goes on to prove that black is white and gets himself killed on the next zebra crossing.

Most leading theologians claim that this argument is a load of dingo's kidneys, but that didn't stop Oolon Colluphid making a small fortune when he used it as the central theme of his best-selling book, Well, That about Wraps It Up for God.

Meanwhile, the poor Babel fish, be effectively removing all barriers to communication between different races and cultures, has caused more and bloodier wars than anything else in the history of creation.


beej@ecst.csuchico.edu