Show/Hide Toolbars

RiverSoftAVG Products Help

Navigation: Inference Engine Component Suite (IECS) > Expert Systems

Define the rules that infer new information based on your domain

Scroll Prev Top Next More

After you have defined the type of objects you can have in your system, you need to define the rules that manipulate the system. Rules define the "code" of your expert system.  They manipulate facts ("objects") 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.


Expert systems require programmers to get used to a new kind of programming paradigm.  A programmer does not specify an algorithm for achieving a goal (like traditional procedural programming).  Rather, the programmer specifies rules about the domain and the inference engine controls the order of execution about matching facts with the left hand side of rules and selecting rules to fire.  Building an expert system is an iterative process, in fact, by not specifying control flow an inference engine encourages incremental improvements, large processing modifications can be realized by just adding or subtracting one rule.


Back to our example from the last section, we are defining an expert system for mortgage loan applications.  We have defined the data types, now we need to define the rules.  Your job now is to work with your domain expert to define the rules of thumb for mortgage applications.  You would compile a list of IF-THEN rules, such as:


IF customer has salary greater than $35,000 and a fair credit history

THEN extend customer a loan of $100,000 for 30 years at 10%


IF customer has salary greater than $35,000 and a poor credit history

THEN extend customer a loan of $100,000 for 30 years at 12.5%




Then, you would convert these pseudo rules into CLIPS format:


(defrule credit-is-fair

    "customer has salary greater than $35,000 and a fair credit history"

    (declare (salience 0))

    (customer (ID ?id) (salary ?s&:(> ?s 35000)) (credit-history fair) )


    (assert (loan ?id 100000 30 10)))


(defrule credit-is-poor

    "customer has salary greater than $35,000 and a poor credit history"

    (declare (salience 0))

    (customer (ID ?id) (salary ?s&:(> ?s 35000)) (credit-history poor) )


    (assert (loan ?id 100000 30 12.5)))


Of course, your rules would probably not be as simple as these.  You would probably want to have rules for a range of salary ($35,000 - $60,000; $60,001 - $120,000; etc).  Also, you would only want to extend a loan if one was not already extended.  As you play with your expert system, you will fiddle and tune with it to get the exact behavior you want.


After defining your data types and rules, the last thing you need to define is the initial state of the expert system.


Note:  It is imperative to define the types of your objects before defining rules or facts.  The inference engine removes rules and facts that become invalid after modifying fact templates.  For example, if you have a fact template with a slot called age and you remove that slot, any rules or facts that reference that fact template will be deleted.  The inference engine can attempt to recover the rules and facts for you but it is by no means guaranteed.


RiverSoftAVG Products Help © 1996-2016 Thomas G. Grubb