### 6.1.1.4 Reasoning with Certainty Factors

Another application of meta-rules is in the manipulation of uncertainty. A full implementation of the uncertain reasoning facility described below is included among the examples distributed with KnowledgeWorks, and also in Uncertain Reasoning Facility.

In this example, we wish to associate a certainty factor with objects in a manner similar to the MYCIN system (see Rule-Based Expert Systems , B. G. Buchanan and E. H. Shortliffe, Addison-Wesley 1984). When we assert an "uncertain" object we wish it to acquire the certainty factor of the instantiation which is firing. We define the certainty factor of an instantiation to be the certainty factor of all the objects making up the instantiation multiplied together. Additionally, we wish rules to have an implication strength associated with them which is a multiplicative modifier to the certainty factor obtained by newly asserted uncertain objects. The general approach is as follows:

• Define global variables ``` *c-factor*``` to hold the certainty factor of the current instantiation and ``` *implic-strength*``` to hold the implication strength of the rule, and a class of "uncertain" KnowledgeWorks objects:
`(def-kb-class uncertain-kb-object ()`
` ((c-factor :initform (* *c-factor* *implic-strength*)`
`            :accessor object-c-factor)))`

The uncertain objects should contain this class as a mixin.

• Define a function to obtain the certainty factor of instantiations:
`(defun inst-c-factor (inst)`
`  (reduce '* (inst-token inst) :key 'object-c-factor))`
• Define a conflict resolution tactic to prefer either more or less certain instantiations (See User-definable Conflict Resolution for details).
• Define a meta-rule to set the global certainty factor to the certainty factor of the instantiation about to fire:
`(defrule uncertain-context :backward`
`   ((uncertain-context)`
`    <--`
`    (start-cycle)`
`    (instantiation ?inst)`
`    ((setq *c-factor* (inst-c-factor ?inst)))`
`     (fire-rule ?inst)`
`     (cut)`
`     (uncertain-context)))`
• Define a function implication-strength which sets the variable ``` *implic-strength*``` so that rules may set their implication strength by calling the action:
``` ((implication-strength <number>))```

A rule could be defined similarly to:

`(defrule my-rule :forward`
`   (my-class ?obj1)`
`   (my-class ?obj2)`
`   -->`
`   ((implication-strength 0.6))`
`   (assert (my-class ?obj3)))`

where the certainty factor of the new object ``` ?obj3``` will automatically become:

``` (* (object-c-factor ?obj1) (object-c-factor ?obj2) 0.6)```

While this is an extremely simplistic version of uncertain reasoning, it suggests how a more elaborate treatment might be approached.

KnowledgeWorks and Prolog User Guide (Macintosh version) - 4 Apr 2005