Newsletter #7: Feb/Mar 2002 Edition
Home Up Feedback Search

Products
Order
Downloads
Support
Articles & Tips
Recommended Links
About

 
 

 
 

Note: Somehow, Newsletter #6 was lost.  It was either not written or not sent properly.  We apologize for any confusion

 

RiverSoftAVG Newsletter #7
Feb/Mar 2002

It's alive!  Welcome, at last, to the seventh edition of our newsletter!  It has been way too many months (whatever happened to November through January?!) since our last newsletter.  We apologize for the delay.  The effort to finish the Early Experience Program for the second version of the Inference Engine Component Suite was much more work than expected.

 

In this issue, the major topic for discussion is the powerful new Expert System Wizard in the IECS EEP (see "Getting Friendly with IECS v2.0 EEP" for more details).  There are also a couple of terrific tips: one about using the Combs method with the EEP and the other about writing rules to create aggregate facts.  Finally, there are two new, great downloads you should know about.

 

A reminder, this newsletter and all previous ones are available for download from the web site at http://www.riversoftavg.com/articles_&_tips.htm


Contents

    Article: Getting Friendly with IECS v2.0 EEP

    News: 10% Off on IECS v2.0/EEP ends March 31st, 2002

    Tip: How to implement the Combs method using IECS v2.0/EEP Fuzzy Logic to prevent combinatorial explosion

    Tip: How to write rules to collect information about some facts

    Free Download: IECS/EEP Demo and Non-Source Version Due March 11-15.

    Free Download: IECS/EEP v2.0 Expert System Wizard.

 

Note: You received this newsletter because you are an owner of a RiverSoftAVG product.  If you received this newsletter by mistake or if for any reason you wish to not receive any future mailings from RiverSoftAVG, just reply to this message informing us so.  We apologize for any intrusion.

 


Article: Getting Friendly with Inference Engine Component Suite Version 2.0 EEP

Version 2.0 of the Inference Engine Component Suite represents a major leap forward for the IECS.  Not only has the IECS got significantly more powerful and faster, it has also gotten friendlier.  A major goal for version 2.0 was to make this version much more accessible and friendly for the non-AI programmer.  Fuzzy Logic was added to make writing rules more intuitive.  Also, we are proud to present an extremely powerful wizard for writing your new expert systems.  The focus of this short article is talking about the New Expert System Wizard in the IECS v2.0.

 

Before we start talking about the wizard, we should note for our non-EEP owners that there is a version of the wizard available for download from our web site.  We converted the wizard to an application which you may run stand-alone outside of Delphi; unfortunately, unlike the wizard, it cannot fill in your TInferenceEngine Component for you.  It is intended only to show the features of the wizard.  You may download the application at

 

How to start the Expert System Wizard

 

The Expert System Wizard is a component editor.  As such, it is accessed in Delphi by double-clicking on the TInferenceEngine component.  Alternatively, you can right click on the TInferenceEngine component and Select the "Start Expert System Wizard..." menu item.  (If you are using the wizard application, just start the application).

 

How to use the Expert System Wizard

 

The Expert System Wizard guides you in making an expert system by taking you, step-by-step, through the various questions you need to answer to create one.  This wizard works similar to programs such as Tax Cut or Turbo Tax.  The wizard asks you questions and fills in the expert system based on your answers.  In addition to guiding you through the steps of creating an expert system, it also provides some small expert systems for you.  You may select these expert systems to see how they are made and to "jump start" your own expert system.  The Expert System Wizard is a great tool for learning the parts of an expert system (types, templates, fact, rules, etc) and for learning the syntax of the IECS language.  However, it cannot write the entire expert system for you, you must provide the "intelligence" of the expert system.

 

When you start the expert system, you are presented with a Welcome screen.  Read this at your leisure.  Click the Next button a few times (or the Skip Button) to get heart of the wizard.

 

The Expert System Wizard presents you with 6 steps for creating your expert system:

bulletSelecting your Domain
bulletDefine Types
bulletDefine Fact Templates
bulletDefine Rules
bulletDefine Initial Facts
bulletFinish Up

Selecting your Domain

 

Your first step in creating an expert system is to decide what you want to create it for.  You must decide the problem area, or domain, that you wish to reason about.  There are a few ready-made domains and expert systems available.  You can also load an expert system (IE File) from your hard disk and use the wizard to take you through that expert system.  If you started the wizard from the IDE, your current expert system in the TInferenceEngine component is automatically selected.

 

For the purposes of our walkthrough, we are going to use a pre-built expert system, Project Risk Assessment, which is a fuzzy expert system for determining the risk of a project based on various factors such as cost, manpower, etc.  The Project Risk Assessment expert system is under the Business Domain.  Select the "Business" domain and click Next.  You will then see presented some SubDomain choices.  Select the "Project Risk Assessment (Fuzzy)" and Click Next.  The wizard will show you some text about your selected domain.  Click Next until you get back to the Agenda.

 

Define Types

 

The next four sections; Define Types, Define Fact Templates, Define Rules, and Define Initial Facts; are the real core of the wizard.  In these four sections, you select and define the constructs of your expert system.  In this section, you start your expert system by selecting and define the "simple" types, including the fuzzy types, of your expert system.

 

Defined Types are similar to the enumerated types or integer sub-range types you would define in Object Pascal (as opposed to Fact Templates, which are more similar to classes in Object Pascal).  DefTypes, while a unique construct of the IECS, borrow concepts from (and provide some substitute features for) CLIPS deftemplate slots.  You can define the type (e.g., integer, string, fuzzy), numeric range of the type (for integers, floats, and fuzzy), units, and allowed values (similar to Object Pascal enumerations) or fuzzy terms.  Types are not necessary for creating expert systems.  By default, all fact slots can be ALL types (except fuzzy).  However, deftypes provide enhanced type checking and range checking.  They are also required if you want to use fuzzy logic in the IECS.

If you click Next a few times, you will get past the explanation pages and get to the "Select Type" page.  This page introduces you to a paradigm the wizard uses again and again.  On the left of the page, there is a pane detailing the available types defined for this expert system.  On the right is the description and syntax to generate the selected type.

 

If you were creating a new expert system, the left pane would be blank except for the "Create New Type..." item.  To select types to include in your expert system, make sure the items are checked.  If you uncheck an item, it will NOT be in the generated expert system.  Note that unchecking a type can make other constructs, such as fact templates or rules, invalid because they depend on the unchecked type.  You would need to uncheck those invalid constructs in the Define Fact Templates, Define Rules section etc or recheck the type to generate your expert system.  Invalid constructs, whether because of syntax errors or dependency errors, are displayed in the Left pane in RED.

 

To edit a type, select the type in the Left Pane and click Next.  The following pages will take you through all the decisions you need to make and the information you need to provide to create that type.  To create a new type, select the "Create New Type..." item and click Next.  Finally, to quit defining types, click the Skip button to go to the next section of the wizard: Define Fact Templates.

 

Define Fact Templates

 

The Define Fact Templates section works exactly like the Define Types section.  In this section, you define the fact templates of your expert system.

 

The fact template provides the basic building blocks of your expert system.  It defines a knowledge unit, or fact type or fact class, in your domain.   It serves as a definition for a group of facts, similar to how a Pascal record definition or class definition defines the structure for all variables of that type.  The deftemplate, as it is known in CLIPS, or fact template, defines the relation name for a group of facts plus zero or more slots that encapsulate properties about the class.

 

To edit a fact template, select the template in the Left Pane and click Next.  The following pages will take you through all the decisions you need to make and the information you need to provide to create that fact template.  To create a new fact template, select the "Create New Fact Template..." item and click Next.  Finally, to quit defining templates, click the Skip button to go to the next section of the wizard: Define Rules.

 

Define Rules

 

The Define Rules section is where you put the intelligence in your expert system.  It is where all the hard work gets done.

 

Rules define the "code" of your expert system.  They manipulate facts ("objects or data") to infer new facts or perform actions.  Unlike procedural languages, however, rules are always present and able to be fired if there conditions are met.  Rules are basically IF-THEN constructs for reasoning about the domain.  The inference engine matches rule conditions (the IF portion) with facts in the expert system and flags rules which have been matched (called a rule activation).  After the inference engine has determined all the rule matches, it selects one rule based on its strategy and a rule's salience (priority) and fires that rule.

 

The Define Rules section works exactly like the previous two sections.  You can edit existing rules or create new rules.  When you are finished defining rules, click the Skip button to go to the Define Initial Facts section.

Define Initial Facts

 

This is the final section in the wizard for defining expert system constructs.  In this section, you define the initial facts of your domain.

 

Facts define pieces of knowledge or data in your expert system.  Facts define the world of your expert system, i.e.,  the people in it, the things in it, etc.  Rules manipulate facts to infer new facts (or new knowledge) and to act.  Facts can be asserted into the world or retracted from the world.  Facts are based on fact templates.  They consist of a relation name (the fact template name) and zero or more slots and their associated values.  For example, the fact '(person (name Tom) (hair-color brown))' defines a person in the world whose name is Tom and has brown hair color.

 

Note that there are two ways to define initial facts.  The Expert System Wizard allows you to define initial facts to be automatically asserted onto your fact list the first time your expert system is run.  However, subsequent executions will not contain these facts.  Fact Sets, or deffacts in CLIPS terminology, define a group of facts that are asserted into your expert system every time the inference engine is Reset.  You can create fact sets by dropping a TFactSet component on your form and clicking the component's Facts property.

 

After you are finished editing or creating facts, click the Skip button to go to the wizard's final section.

 

Finish Up

 

In this section, the wizard allows you to review your choices.  You get to see all the defined types, fact templates, rules and initial facts in your system.  The first page of this section displays all the constructs in a tree.  Constructs, which are invalid, whether because of bad syntax or dependency problems, are highlighted in red. 

 

To edit a construct (fact, rule, etc), select the construct and click the Correct button.  Only after everything is correct are you taken to the final page.  The final page shows you what your expert system will look like.  If you are running the wizard application, the wizard ends here.  You can select the expert system text and copy it into a file for your use though.  You may have to edit it though, there may be some v2.0-isms in there which will make the expert system invalid for v1.0 as written.  If you are running the wizard from the IDE, clicking Finish will fill your TInferenceEngine component with the new expert system.

 

Well, that was a short overview of the IECS v2.0 Expert System Wizard.  Obviously, such a massive wizard can only be superficially explained here.  We encourage you to experiment with the wizard, either in the IDE or the download application.  If you have suggestions, please don't hesitate to write us.

 

 

News: 10% Off on IECS v2.0/EEP ends March 31st, 2002

Right now, there is a sale on the Inference Engine Component Suite v2.0/EEP where you can get 10% off the price, full version or upgrade.  It is a great time to order.  However, all good things must come to an end and March 31st is the last day of the sale.  So if you want to take advantage of this offer, please hurry!  Here are the current prices and the prices after March 31st:

 

IECS v2.0/EEP Full Version (Source)              $315 Until March 31st            $350 After March 31st

IECS v2.0/EEP Upgrade (Source) (Pre-August 1st 2001 Owners)

                                                                    $157.50 Until March 31st       $175 After March 31st

IECS v2.0/EEP Upgrade (Source) (After-August 1st 2001 Owners)

                                                                    $112.50 Until March 31st       $125 After March 31st

IECS v2.0/EEP Crossgrade (Non-Source to Source) (Pre-August 1st 2001 Owners)

                                                                    $270 Until March 31st           $300 After March 31st

IECS v2.0/EEP Crossgrade (Non-Source to Source) (After-August 1st 2001 Owners)

                                                                    $225 Until March 31st           $250 After March 31st

IECS v2.0/EEP Full Version (No Source) - Delphi 5/6           

                                                                    $180 Until March 31st           $200 After March 31st

IECS v2.0/EEP Upgrade (No Source) (Pre-August 1st 2001 Owners)

                                                                    $90 Until March 31st             $100 After March 31st

IECS v2.0/EEP Upgrade (No Source) (After-August 1st 2001 Owners)

                                                                    $76.50 Until March 31st        $85 After March 31st  

Note: IECS v2.0 is for Delphi 5 and 6 only.

 

Non-source code users will also have a chance to buy v2.0/EEP at 10% off.  The next EEP will be available for non-source code users as well (see the Announcement below).  To reduce the development time (preparing non-source code versions is labor intensive), that EEP will be the *only* EEP where non-source code is available until the release of version 2.0.

 

 

Tip: How to implement the Combs method using IECS v2.0/EEP Fuzzy Logic to prevent combinatorial explosion

 

A handicap that expert systems, especially fuzzy expert systems, face is what is called combinatorial explosion.  Combinatorial explosion occurs when the number of rules increases exponentially with the increase in dependent variables (and their values). A Boeing engineer, William E. Combs, has developed a method, called oddly enough :-) the Combs method, for preventing combinatorial explosion; this tip shows how to implement the Combs method with the IECS v2.0.  For the purposes of space, we will not explain in detail combinatorial explosion and the Combs method.  Please see "The Fuzzy Systems Handbook, 2nd Edition" by Earl Cox or the "Imploding Combinatorial Explosion in a Fuzzy System" gem by Michael Zarozinshi in the "Game Programming Gems 2" book, edited by Mark DeLoura for more details.

 

Combinatorial Explosion of Rules in Fuzzy Expert Systems

 

Combinatorial explosion of the number of rules occurs in Fuzzy Expert Systems as the number of dependent variables, or fuzzy variables, increase the variables values, or fuzzy sets, increase.  For example, suppose you have written a fuzzy expert system to determine the financial credit worthiness of an applicant.  Your first attempt at the fuzzy expert system uses two fuzzy variables: Income and Debt, both of which may be either Low, Medium, or High.  Your expert system also has one solution fuzzy variable: Risk.  Conventional thought for fuzzy expert systems is that you must write a rule for every combination of your dependent input variables: "if Income is Low and Debt is Low then Risk is Medium," "if Income is High and Debt is Low, then Risk is Low," etc.  You must create a rule for every combination of Income and Debt.  A Fuzzy Expert System designed this way is essentially what is called a Fuzzy Associative Memory, or FAM for your fuzzy system.  For two input variables (Income and Debt) and 3 fuzzy sets per variable (Low, Medium, High), you would need 3 squared or 9 rules.  If you added just one extra fuzzy set value to Income and Debt, you would need 4 squared (16) rules.  If you added another fuzzy variable, say Mental Health, you would now have 4 Cubed (4^3=64) rules.  As the number of fuzzy variables or fuzzy sets increase, the number of rules increases exponentially:

 

Number of                Number of                Number of

Fuzzy Variables          Fuzzy Sets/Var           Rules

  2                        3                        9

  2                        4                        16

  3                        3                        27

  3                        4                        64

  4                        4                        256

  5                        4                        1024

  10                       4                        1048576

 

In practice, using hedges and smart rule writing, you don't need a separate rule for each combination.  However, the concern is valid, rules do increase exponentially.  What can we do?

 

Well, William Combs developed a method to reduce this exponential growth to linear growth.  Instead of 10 Fuzzy Variables with 4 Fuzzy Sets Each having over a million rules, the Combs method makes you end up with 40 rules!  Basically, the Combs method realizes that the logical proposition (p and q) then r is equivalent to (p then r) OR (q then r), where p, q, and r represent terms such as "Income is Low," "Debt is Low," and "Risk is Low" respectively.

 

What does this mean in practice?  Instead of writing rules for every combination of input variables and fuzzy set values, you just write rules for each input variable by itself:

"if Income is Low, then Risk is High"

"if Income is Medium, then Risk is Medium"

"if Income is High, then Risk is Low"

"if Income is Obscene, then Risk is Low"

With the IECS, you just need to rewrite the rules... everything else happens automatically. 

 

Not only does the Combs method reduce the number of rules, it also reduces maintenance.  Suppose you did want to add a new input variable to your expert system.  With the traditional technique, you would have to modify ALL of your existing rules as well as adding new ones!  With the Combs method, you just add rules for the new input variable.

 

What's the catch?  Ok, it does seem to be too good to be true.  But in this case, there is little penalty for using the Combs method.  With a fuzzy expert system, the Combs method does give slightly different results than the traditional method.  This is more a matter of how fuzzy inference engines work than the method itself.  When you AND variables together, the Fuzzy Inference Engine uses the MINIMUM pattern match strength of all the variables.  A rule such as "if Income is Low AND Debt is High..." may match with facts so that Income matches with a 17% strength and Debt matches with a 80% strength.  The Fuzzy Inference Engine activates this rule with the minimum of the two strengths: 17%.  This activation strength modifies any assertions made in the rule, e.g., assert Risk is High with a cutoff of 17%.  The Combs method avoids this minimization, it just ORs the results together.

 

The Combs method provides great advantages.  It reduces the number of rules and maintenance of those rules.  Plus, it provides faster expert systems!  The Inference Engine does not have to perform so much work matching facts with potentially thousands of rules.  You owe it to yourself to consider using the Combs method with your expert systems.

 

 

Tip: How to write rules to collect information about some facts

 

Occasionally in your expert systems, you may find yourself needing to look at all facts of one type and find some aggregate information.  For example, you may have a list of customer facts and you want to find the average income of your customers.  Unfortunately, expert systems do not give an easy way for finding this aggregate information.  This tip will illustrate one way to write some rules to find the average of a fact slot, the average income in all the customer facts on your fact list.  Let's fire up the Advanced Console Editor to create our expert system.

 

First, we need to define the fact templates we are working with.  Of course, there is the customer fact template.  For our purposes, we are going to ignore all slots and just ensure we have an income slot.  To calculate an average, we need to sum all the customer ages and then divide by the number of customers.  Therefore, we need an intermediate fact to hold the sum and fact count.  Here are the two fact templates we came up with

 

(deftemplate customer
    (slot income )
)
(deftemplate customer-all (slot sum) (slot count))

 

Now, you may just be tempted to write a rule that matches with a customer fact and modifies the customer-all fact:

 

(defrule build-sum
    (customer (income ?income) )
    ?ca <- (customer-all (count ?count) (sum ?sum) )
    =>
    (modify ?ca (sum (+ ?sum ?income) ) (count (+ ?count 1) ))
)

 

This rule will have one activation for every customer fact in the fact list.  However, there is a problem.  As written, this rule causes an infinite loop!  Every time the customer-all fact is modified, this rule gets reactivated for the new customer-all fact.  What can we do?

 

Well, we need to prevent the reactivation.  The CLIPS way is to create another intermediate fact, say add-sum.  Every customer fact would assert one add-sum fact.  This add-sum fact would not cause reactivation of the summing rule.  Then, another rule would add the add-sum facts to make customer-all.  Here are the modified rules:

 

(defrule build-sum
    (customer (income ?income) )
    =>
    (assert (add-sum ?income ))
)

(defrule build-sum-end
    ?as <- (add-sum ?income)
    ?ca <- (customer-all (count ?count) (sum ?total) )
    =>
    (retract ?as ?ca)
    (assert (customer-all (sum (+ ?total ?income)) (count (+ ?count 1))))
)

 

Finally, we need to create a rule to calculate the actual average.  For our purpose, we will just printout the average.  The only tricky part about this rule is that we don't want it to activate on the customer-all fact until every other rule has finished firing.  To do this, we just declare the salience (or priority) to a negative number; remember that salience is different than priority in that lower values have LESS priority.  Since all the other rules have the default salience of 0, this averaging rule will fire last:

 

(defrule calc-average

   (declare (salience -10))

   (customer-all (count ?count) (sum ?total) )
    =>
   (printout t "Average is " (/ ?total ?count)))

 

Voila!  We're done.  We just need to add the customer facts and the customer-all facts to test our expert system.  The fact set (deffacts) for that is below:

 

(deffacts myfacts
    (customer (income 20000))
    (customer (income 40000))
    (customer (income 55000))
    (customer (income 20000))
    (customer (income 100000))
    (customer (income 90000))
    (customer (income 56000))
    (customer (income 33000))
    (customer (income 28000))
    (customer (income 200000))
    (customer-all (sum 0) (count 0))
)

 

Reset the expert system and run!  Next time, we will show you how to create a user function to do the same function.


 
Free Download: IECS/EEP Demo and Non-Source Version Due March 15

 

The Inference Engine Component Suite version 2.0 Early Experience Program will release a new version next week, hopefully on the Ides of March :-).  This release will have bug fixes as well as help updates.  The big news is that next week a demo version AND a non-source code version will also be released.  To download the demo, check back at http://www.riversoftavg.com/downloads.htm at the end of next week.  Non-source code users will be able to upgrade to the new version at the same time.  And now through March 31st, the upgrade will be available at 10% off.


Free Download: IECS v2.0 Expert System Wizard

 

The Inference Engine Component Suite version 2.0 Expert System Wizard is available as a stand-alone application from our downloads page.  This application allows you to try out the wizard for yourself if you don't have the EEP.  Though it cannot generate the expert system automatically for you, you can copy the expert system to the clipboard to try and use with the Advanced Console Demo.  Our article above, Getting Friendly with IECS v2.0 EEP, also talks about the Expert System Wizard.

 
Send mail to webmasterNO@SPAMRiverSoftAVG.com with questions or comments about this web site.
Copyright © 2002-2010 RiverSoftAVG
Last modified: September 20, 2010