Posts Tagged ‘AI’

AI Forward chaining

Tuesday, February 9th, 2010

In the last post I described a little about the backward chaining approach used in EarnestAI.  Today I wanted to say a bit about Forward Chaining.  Forward chaining is basically a lazy approach to finding an answer.  The system starts with a question to a known answer such as “Who created you?”

The system then presents a series of preset questions, for example “Do you mean who is my creator?”

The user answers Yes, and the system then moves onto the next question.  When all the questions are complete, the system then compares the answers against a set of stored solutions and decides which solution is best defined by the answers given.

Its a very accurate process in reality, but can also be confusing and irritating for the user.  The best example I have seen to demonstrate this is “Are you male?” Yes,  “Are you pregnant?”, No, “Are you female?”

You get the picture, the system has little or no understanding of the questions it poses, and the onus is on the knowledge engineer to devise the question structure so as to be as unconfusing as possible.

The forward chaining method in its simplest for is both highly accurate, highly irritating and also unable to branch to different lines of questionsing.

It is my hope to refine this approach in EarnestAI to allow a sort of hybrid FWD Chaining.  Basically, I am testing the concept of using a BAckward chaining algorithm that is executed after every answer.  The results will look forward to possibly proved solutions and then switch the path of questioning to a more realistic route.  For instance, if Earnest asks, “does it have 4 legs”, he will look forward to all solutions proved true by this question and then remove questions in the current question path that no longer relate to 4 legged animals.

Initial tests are good, but there are ome risks involved because once again, we are leaving it to the “heuristic reasoning” capability of the backward chaining engine to not ommit important questions.

Oh well, hope that you enjoyed the post.

by for now

Scot

More about Backward chaining in AI

Monday, February 1st, 2010

In my earlier post Ernie takes the leap, I described how Ernie was able to conclude certain facts even though no solution or problem was stored directly for him to be able to “question” his way to the answer.

For example, “Where does a kangaroo live ?” is a question that neither a question nor solution was stored in his knowledge base.  So to understand how he can arrice at the correct conclusion “I believe kangaroo only live Austrailia” we need to study the rules and how the backward chaining part of his inference engine works.

Consider the rules for the solution “Its a kangaroo” a solution linked to the problem “I will guess the animal you are thinking of”.  The rules are:

1 Does it have 2 legs [TRUE]

2 Does it live only in Austrailia [TRUE]

3 Does it have wings [FALSE]

Stored with the solution are the “tags” 1,2,!3  meaning that in basic mode, he would ask the questions one by one and if the pattern of answers matched they he would arive at “Its a Kangaroo”.  This is in effect simple “Forward Chaining”.  The answer is concluded by logical process and a series of set questions devised by the “Expert” or “Knowledge engineer” who made the rules.

In heuristic search mode (as I like to call it)  Ernie is asked the question “Where does a Kangaroo live?” .  Ernie would begin by searching for a fact that gives the answer straight out, or for a rule in his knowledge base by which the answer could be inferred. To find the correct rule, he searches the entire knowledge base for rules who, if true, will answer the question.

In the Kangaroo case, rule 2 says that in order to be a Kangaroo, it MUST live in Austrailia.  Simple stuff, the hard part is the lexical understanding of what has been asked or what is infered by a rule, whos conclusion is only BOOLEAN (TRUE or FALSE).  In forward chaining Earnest has no idea what “Does it live only in Austrailia” means, only that the user must say YES to the question.  In heuristic mode, he has to “read” the rule and try to make sense of it in relation to the question.

V0.02 introduces thisin lib_inference.php and using the demo database he can infer a number of simple conclusions, such as : how many legs does a dog have? what noise does a wolf make? and a number of others.

Study the code in the “heuristic search” part of the compute_solution function to see how he currently does it.  TBH its pretty weak, and only goes a limited number of levels deep.  Over time I will be refining this feature a great deal.

Next time I will introduce the user to Ernies forward chaining approach.

Byee

Ernie takes the leap

Monday, February 1st, 2010

OMG! well not quite but last night saw the first real interesting breakthrough of EarnestAI as the latest version of lib_inference successfully deduced that an Ostrich lives in Austrailia!!!  Whats so great you say?  Well the great thing is that this is the beinings of Ernies heuristic reasoning capability actually working to produce an answer to something that he had not heard the question to before…..

Enter Deep Thinking, well OK its not deep blue in actual fact it is more BAckward Chaining but here is the idea:

Basic Expert System

An Expert System in its most basic form allows an expert in the chosen field to “teach” the system a series of leading questions that are carefully crafted to lead the user to a solution to their problem.  Along the way the expert may add further detail to the question or consultation process and the Expert System will be able to add this new knowledge to its “Knowledgebase” to improve the accuracy of its results.

This is great, and over the coming weeks I will be breaking down Expert System design methods into their various pros and cons and explaining them in greater detail. I guess you can already see however that in order to arrive at a solution the questions must already have been answered and a solution related to the problem question in hand.  This means that whilst a basic Expert System may find a solution and impress the end user, it will fail to impress the expert for it can not deduce anything more than they already have imparted to it.

However Earnest is a project to try and break these limits of Question and Answer consultation and try and derive a system capable of making deductions based on past consultations and expert knowledge.

Yesterday Ernie took the first steps to this.  One of the first things I begn to teach Ernie was about animals.  He would try happily to guess the animal that you are thinking of by asking key questions.  The question process is long and sometimes laborious but for the animals he knows about, he usually finds the right answer.  A fun game but soon lack lustre.  The latest version of Ernies lib_inference has introduced “heuristic reasoning”.

Instant descisions

Heuristic reasoning allows Ernie to make instant descisions without asking you any questions at all.  You ask him and he tells you the  answer all on his own.  Now in previous versions you had to begin the consultation by searching the problem database for problems for which there were known answers.  Like “What animal am i thinking of?” etc.  He would then ask “Does it have 2 legs?”, “Does it make a barking noise?”, “Does it have wings?” etc, a yes to Q1 and Q3 would probably lead to the answer “its a bird”.

What however if we want to ask him a question that he does not know the answer to?  Well V1 allows you to teach him the problem and wha questions to ask.  Is that enough?  NO! That would mean that in order to find a solution to an unkown question the user would also have to be the expert.  Useful but not much.

Heuristic reasoning within Ernies inference engine allows Ernie to consult himself.  For example:  “How many legs does a bird have?” This question is not recorded in Ernies knowledgebase but he can answer the question with accuracy.  How?  By looking to known solutions and backtracing to questions nd conditions that he knows to be true about the subject.  In the bird case,  he will look at the solution “Its a bird” and deduce that in order for this to be true the following conditions must be met: “Its has wings”, “It has 2 legs”.

Heuristics then allow Ernie to study the questons that make these qualifications thus breaking down the question : How many legs does a bird have?   we see “Legs” “Bird”.  The question “Does it have 2 legs” is a TRUE boolean condition of “Its a Bird” and thus Ernie is able to extract the question and reformat it to answer the question : “I believe a bird has 2 legs”….

Simple?  Wel kind of, the V.03 of lib_inference is fairly rudimentary but I will keep refining it.

Well I have to go, hopefully more blogging tomorrow.

EarnestAI

Saturday, January 30th, 2010

Morning,

Well I’ve been busy getting Earnies (his pet name) Sourceforge project in some kind of logical order.  Sorceforge is really quite cool tbh!  It’s been a good experience and setting up the project was really quite easy.

Since releasing the original PRE-ALPHA source code I have been busy trying to get it in some kind of understandable format. I confess even if I have been coding for over 29 years my source formatting is anything but conventional.  Its perfectly readable to me, but my indents and code blocks dont meet modern standards.  Hopefully my rich ue of developer comments will help people disipher whats going on.  For the first time ever I have also made use of a code beautifier to try and make it a bit more friendly to you all.

For those of you who dont know yet, EarestAI is coded in PHP.  I have become something of a PHP fan in the last 10 years as much of my commerial work is in web based applications and I find PHP extremely easy to work with. It took me almost zero time to migrate to it from C and C++ and I chose it to create Earnie so that he was portable but more importantly web based.

Omnipitent Ernie

I wanted Ernie to be web based purely becaus he is able to interface with anything connected to the Internet or even Intranets.  Email servers etc.  It is my hope that as he develops further “Intelligence” and cpability that he will be able to link to further reading, acces emails and play media files etc to enhance his users experience.  BUT above all this, web connectivity means that Ernie has the possibility to communicate with many people at the same time!!  Whats good bout that?  Well, he can possibly use input from one user to solve problems for another, and even remember to ask suitable new users to solve historical problems asked by others and even contact them by SMS with updated results etc.

Yesterday I only grabbed a couple of hours coding in between work, but I have managed to now separate Ernies inference engine (The part of Ernie that makes descisions) and have also tightened his security.

Experienced programmers will probably notice that the coding approach is rather old fashioned at present, that is I have made no use of PHP Classes and there is even a dreaded global variable “if only 1″.  To be honest, its not a big deal, I wanted at first to get a working input model, and my old hacker approach to coding is a bit bottom up on this one,  I just started coding and took it from there.  The application plan was almost non existent all i had was a 12 line plan of the data structure and a vision in my mind on how things would be stored and accessed.

Result: A messy code structure that is at best in efficient and at worse a bit lousy :-) but it works and I can understand it.  I have luckily employed functions heavily and have kept 90% of the page output to templates from the start, this will make it easier to eventually class the functions and create a simple and powerful web based API that can be pulled into almost any web based project and skinned to match the users needs at will.

In my next post I will be starting to write about the AI approach I have chosen for the EarnestAI project the well known Expert System and how hopefully with some new ideas this limited but also powerful model can make Ernie a clever little bunny.  I will also be hopefully setting up a FB page for Ernie fans to promote the project and get some more brains on the job.

Well gotta go, its snowing again and the snowboard beckons……

Artificial Intelligence Revisited in EarnestAI

Friday, January 29th, 2010

I cannot have escaped the thoughts of any computer programmer to dream of one day creating “the one” the deep thought, or Hal of 2001.  The reality and complexity of actually creating Artificial Intelligence has enthralled myself since the age of 10 when I created my first expert system inside the 1K memory of my ZX81.  In 1999 I began to consider the subject much more seriously.  A devout AI and Aibo and I-Cybie lover, the concept of man and machine living in harmony is one which I find truly fascinating, sinister and downright confusing.

I have recently begun work on a web based AI Expert system written in PHP called Earnest.  The project is open source and the homepage is at http://sourceforge.net/projects/earnestai/ you can download the latest source code for this project there.

Earnest is an attempt to create a web based Artificial Intelligence engine capable of performing problem solving and even customer service roles.  Currently in PRE-ALPHA stage the program is capable of basic learning and problem solving.

Here is a screenshot of Earnest in his current stage of development.

EarnestAI welcome screen running in Firefox 3.6 Ubuntu 9.10

If you are interested in helping out with Earnest please feel free to take a look in at the sourceforge homepage and contact me through there.