PII: 0888-613X(93)90013-4 Consistency Checking for Fuzzy Expert Systems K. S. Leung and Y. T. So T h e C h i n e s e University o f H o n g K o n g ABSTRACT Inconsistency frequen@ exists in a rule-based expert system. Detecting the existence o f inconsistency in a fuzzy rule-based environment is difficult and may be different from that o f traditional rule-based systems. A n affinity measure, which is based on the similarity measure, is introduced to determine the likeness o f two fuzzy terms. By using the affinity measure, the techniques f o r consistency checking in a non-fuzzy environment can be easily applied to a fuzzy environment. A consistency checker (CCFE) is implemented to detect possible inconsistency in a mixed fuzzy and non-fuzzy environment. K E Y W O R D S : E x p e r t s y s t e m , f u z z y theory, i n c o n s i s t e n c y , possibility distribution I. INTRODUCTION In the development of a rule-based expert system, the knowledge engineering process is an iterative one. The knowledge base needs to be refined many times. When new rules are added or the existing rules are altered, inconsistency in the knowledge base frequently occurs. Although H a y e s - R o t h [1] pointed out that a missing key feature of rule-based systems is "a suitable verification methodology or a technique for testing the consistency of completeness of a rule set," many software tools such as TERIRESIAS [2], ONCOCIN's rule-checker [3], INSPEC- T O R [4], and ESC [5] have been developed to identify inconsistencies in non-fuzzy knowledge bases. The consistency checking tools help both the domain experts and knowledge engineers to build the expert systems more easily, accurately, and quickly. However, checking inconsistency in a fuzzy rule-based environment [6-8] is not as simple as that in a non-fuzzy environment and may also be different from that of traditional rule-based systems. Let "height" be a Address correspondence to K. S. Leung, Department of Computer Science, The Chinese University of Hong Kong, Shatin, N. T., Hong Kong. Received April 30, 1991; accepted March 12, 1993. International Journal of Approximate Reasoning 1993; 9:263-282 © 1993 S. K. Leung 263 264 K.S. Leung and Y. T. So fuzzy object having three fuzzy terms (tall, medium, short) as its possible values. I f the user enters the following two rules: R u l e 1" I F height is tall T H E N C R u l e 2: I F height is short T H E N C D o e s r e d u n d a n c y occur? Consider a n o t h e r case: R u l e 3: I F A T H E N height is more-or-less tall R u l e 4: I F A T H E N height is n o t very tall D o e s conflict occur? Thus, it would be b e t t e r if we could apply a quantitative m e a s u r e on the two fuzzy terms (e.g., tall, not short) in o r d e r to d e t e r m i n e to what extent these two fuzzy terms m e a n the same thing. A n "affinity" m e a s u r e based on the similarity m e a s u r e [6] is c r e a t e d to d e t e r m i n e the degree o f matching between two fuzzy expressions. Using the affinity measure, the techniques for consistency check in a non-fuzzy e n v i r o n m e n t can be transported to a fuzzy environment. T h e following section summarizes different kinds of inconsistencies that exist in a rule-based environment. Section 3 introduces the similarity and affinity measures. Section 4 describes a consistency checker, C C F E , imple- m e n t e d for fuzzy rule-based expert systems. Its results in detecting incon- sistency i n a fuzzy e n v i r o n m e n t are illustrated by an example and discussed in the fifth section. 2. I N C O N S I S T E N C Y I N R U L E - B A S E D S Y S T E M S T h e r e are several kinds o f inconsistencies in a non-fuzzy rule-based e n v i r o n m e n t [9-12]. T h e s u m m a r y is given as follows: L e t us consider the rules: R u l e 1: I F A 1 T H E N B1 (CF1) R u l e 2: I F A 2 T H E N B 2 ( C F 2 ) where A 1 and A 2 m a y be any combination of propositions, B1 and B 2 are single propositions, and CF1 and CF2 are the certainty factors, ranging f r o m 0 to 1, of rule 1 and rule 2 respectively. 2.1. R e d u n d a n t R u l e s • Two rules succeed in the same situation and have the same results. i.e., i, A 1 = A 2 & B1 = B 2 & sign(CF1) = sign(CF2) or ii, A 1 = A 2 & B1 ~ B2 & sign(CF1) ~ sign(CF2) • T h e two rules m a y cause the same i n f o r m a t i o n to be c o u n t e d twice, leading to e r r o n e o u s increases in the certainty factor o f the conclusion. Consistency Check for Fuzzy Expert Systems 265 • C o n d i t i o n ii above m a y n o t be r e d u n d a n t if the expert wants to confirm o n e value (e.g., B 1 with C F 1 > 0) and at the same time disconfirm a n o t h e r value (e.g., B 2 with C F 2 < 0) of the conclusion. 2.2. Conflicting Rules (Contradiction) • Two rules succeed in the same situation b u t with conflicting results. i.e. i, A 1 = A 2 & B 1 = B 2 & s i g n ( C F 1 ) --/: s i g n ( C F 2 ) or ii, A 1 = A 2 & B 1 --/: B 2 & s i g n ( C F 1 ) = s i g n ( C F 2 ) • It is a c o m m o n occurrence in rule sets. However, it m a y cause no problems (inconsistency) because the expert m a y want to conclude different values with different certainty factors. • F o r example, the following are the rules extracted from a medical expert system E S R O M [8]: (Rule m l 7 a I F (((mdcs is anycd) O R (mdcs is gmd)) A N D (gestation > = 30) A N D (gestation < = 34)) T H E N m a n a g e m e n t is delivery Certainty is 0.7 (Rule m18 I F (((mdcs is anycd) O R (mdcs is gmd)) A N D (gestation > = 30) A N D (gestation < = 34) T H E N m a n a g e m e n t is observation Certainty is 0.3 M a n a g e m e n t is a single-valued object with expected values (delivery, observation). T h e two rules listed above have the same a n t e c e d e n t part but with conflicting conclusions. However, they are set on pur- pose by the expert and by no m e a n s a mistake. 2.3. Subsumed Rules • Two rules have the same result, b u t one contains additional restric- tions on the situation in which it will succeed. W h e n e v e r the m o r e restrictive rule succeeds, the less restrictive rule also succeeds, resulting in redundancy. i.e., ( A 1 c A 2 or A 2 c A 1 ) & B 1 = B 2 or ( A 1 c A 2 or A 2 c A 1 ) & B 1 4~ B 2 • e.g., in E S R O M (Rule i o l I F (diagnosis is u n r u p t ) T H E N cx is uninf) Certainty is 0.8 & s i g n ( C F 1 ) = s i g n ( C F 2 ) & s i g n ( C F 2 ) ~ s i g n ( C F 1 ) (Rule iil0 I F ((diagnosis is u n r u p t ) A N D (ctg is reactive)) T H E N cx is uninf) Certainty is 0.95 W h e n e v e r rule iil0 is triggered, rule i o l will also be triggered. Thus, there is redundancy. 266 K.S. Leung and Y. T. So • H o w e v e r , the k n o w l e d g e e n g i n e e r m a y wan t t o write these kinds o f rules so t h a t t h e m o r e restrictive rules will ad d weight to t h e conclu- sions. Thus, t h e experts should b e w a r n e d an d r e q u e s t e d t o clarify t h e i r meanings. In the above example, if the e x p e r t ' s i n t e n t i o n is to give m o r e weight to "cx is u n i n f " w h e n "ctg is r e a c t i v e " is also true, t h e n t h e c e r t a i n t y f a c t o r o f rule i i l 0 should b e c h a n g e d t o 0.75. If b o t h "diagnosis is u n r u p t " and "ctg is r e a c t i v e " are true, t h e cert ai n t y o f conclusion "cx is u n i n f " b e c o m e s 0.95 a f t e r b o t h rules are fired an d the e v i d e n c e c o m b i n a t i o n calculation is app l i ed [6]. 2.4. Sub-contradiction Rules It is a special case o f c o n t r a d i c t i o n . T w o rules have d i f f e r e n t results, b u t o n e contains additional restrictions o n the situation in which it will succeed. W h e n e v e r the m o r e restrictive rule succeeds, t h e less restrictive rule also succeeds: i.e., ( A 1 c A 2 o r A 2 c A 1 ) & B 1 4 : B 2 & s i g n ( C F 1 ) = s i g n ( C F 2 ) o r ( A 1 c A 2 o r A 2 c A 1 ) & B 1 = B 2 & s i g n ( C F 2 ) 4: s i g n ( C F 1 ) 2.5. Unnecessary IF Conditions • T w o rules have the same conclusion, an I F co n d i t i o n in o n e rule is in conflict with an I F c o n d i t i o n in the o t h e r rule, an d all o t h e r I F conditions in t h e two rules are equivalent. e.g., ( A 1 = p / x q ) , ( A 2 = p A -1 q), B 1 = B 2 & C F 1 = C F 2 • T h e e x a m p l e described above actually indicates t h a t only o n e rule is necessary. T h e s e c o n d I F conditions (q a n d -1 q ) o f b o t h rules are unnecessary. A l t h o u g h it will n o t cause any e r r o r in consultation, it would be b e t t e r to i n t e g r a t e the two rules into one: I F p T H E N B I ( C F 1 ) • e.g., ( A 1 = p A q ) , ( A 2 = ~ q ) , B 1 = B 2 & CF1 = C F 2 T h e s e c o n d I F c o n d i t i o n in the first rule is unnecessary, a n d t h e two rules could b e c o m b i n e d into: I F p V -1 q T H E N B I ( C F 1 ) • I f C F 1 4: C F 2 , n o u n n e c e s s a r y I F c o n d i t i o n occurs b e c a u s e t h e ex p ert m a y want to c o n c l u d e a value with differen t cert ai n t y factors in d i f f e r e n t situations, e.g., in E S R O M ( R u l e m20 I F (((wcc > 10) A N D (wcc < 15)) O R ((crp > 20) A N D (crp < 40) a n d (gestation > = 32))) T H E N m a n a g e m e n t is delivery) C e r t a i n t y is 0.8 ( R u l e m21 I F (((wcc > 10) A N D (wcc < 15)) O R ((crp > 2 0 ) A N D (crp < 40) an d (gestation < 32))) T H E N m a n a g e m e n t is delivery) C e r t a i n t y is 0.5 Consistency Check for Fuzzy Expert Systems 267 T h e c o n d i t i o n (gestation > = 32) in rule m20 is conflicting with t h e c o n d i t i o n (gestation < 32) in rule m21. H o w e v e r , t h e e x p e r t wants to assign d i f f e r e n t c e r t a i n t y factors to d i f f e r e n t situations. 2.6. C i r c u l a r R u l e s A set o f rules is circular if the chaining o f these rules in t h e set fo rm s a cycle. i.e., A1 = B2 & A 2 = B2 & sign(CF1) -- sign(CF2) 2.7. S e l f - r e f e r r i n g R u l e s T h e c o n d i t i o n and conclusion clauses o f a rule r e f e r to t h e sam e subject. e.g., I F A = 0 T H E N A = 1 (for A is n o t a multi-valued object) 2.8. I n c o n s i s t e n t I F - C l a u s e T h e clauses in the c o n d i t i o n are c o n t r a d i c t o r y to each o t h e r . e.g., I F A = 1 and A = 2 T H E N B (for A is n o t a multi-valued object) In 2.7 and 2.8, if A is a multi-valued object, it c a n n o t b e c o n c l u d e d that inconsistency occurs b e c a u s e a multi-valued object can have m o r e t h a n o n e value at anytime T h e above discussion only m e n t i o n s superficial inconsistency b e t w e e n two rules. H o w e v e r , inconsistency m a y arise a f t e r a s e q u e n c e o f infer- ring steps, e.g., R u l e l : I F A T H E N B (CF1 > 0 ) R u l e 2: I F B T H E N C (CF2 > O) R u l e 3: I F C T H E N D (CF3 > O) R u l e 4: I F A T H E N D (CF4 > O) R e d u n d a n c y occurs b e t w e e n rule set ( 1 - 3 ) an d rule 4. M o r e o v e r , the d e t e c t i o n o f circular-rule chains is a f f e c t e d by t h e threshold. T h e c e r t a i n t y factors m a y cause a circular chain o f rules to b e " b r o k e n " if the c e r t a i n t y f a c t o r o f conclusion falls below t h e t h r e s h o l d (e.g., 0.2). e.g., R u l e 1: R u l e 2: R u l e 3: R u l e 4: I F A T H E N B (CF = 0.4) I F B T H E N C (CF = 0.7) I F C T H E N D (CF = 0.7) I F D T H E N A (CF = 0.8) As (0.4)(0.7)(0.7) = 0.19 < 0.2, the circular-rule chain is b r o k e n . 268 K.S. Leung and Y. T. So 3. C O N S I S T E N C Y C H E C K S I N A F U Z Z Y E N V I R O N M E N T First, let us consider the possibility, necessity, and similarity measures in possibility theory, and t h e n the affinity m e a s u r e of two fuzzy terms will be introduced. L e t the fuzzy terms be r e p r e s e n t e d by a list o f 11 real numbers that are grades o f m e m b e r s h i p o f the points on an imaginary psychological c o n t i n u u m with an interval scale. The fuzzy terms " t a l l , " " m e d i u m , " and " s h o r t " are r e p r e s e n t e d as follows: tall: 0 0 0 0 0 0 .0280 .1176 .3277 .6561 1 medium: 0 0 0 .0588 .328 1 .328 .0588 0 0 0 short: 1 .6561 .3277 .1176 .0280 0 0 0 0 0 0 H e d g e s like " v e r y " or " m o r e - o r - l e s s " may be applied to the above fuzzy terms to f o r m fuzzy expressions such as " v e r y tall" and "more-or-less short." A square and a square root functions are the fuzzy concepts handling functions for the hedges " v e r y " and " m o r e - o r - l e s s " respectively [13]. The modified representations are shown: very tall: 0 0 0 0 0 0 .0008 .0138 .1074 .4305 1 more-or-less short: 1 .8100 .5725 .3429 .1673 0 0 0 0 0 0 T h e m e m b e r s h i p values described above can be viewed as a possibility distribution [14]. But this distribution has only an indicative or subjective m e a n i n g and m a y n o t be i n t e r p r e t e d directly. Figures 1-3 depict the curves o f the above fuzzy t e r m s / e x p r e s s i o n s . Note that the curves are normalized and convex. 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 v e r y 0 . 1 0 I I I I ; , , , , Figure 1. Possibility distribution for the concepts "tall" and '"very tall." Consistency Check for Fuzzy Expert Systems 269 1 0.9 ~ x 08 m o r e o r l e s s 0.7 0.6 0.5 0.4 0.3 0.2 0 ~ I I I Figure 2. Possibility distribution for the concepts '"short" and "more-or-less" short. 3.1 Possibility and Necessity T h e f o r m u l a e o f t h e possibility ( P ) and necessity ( N ) m e a s u r e s b e t w e e n a fuzzy d a t u m and a fuzzy p a t t e r n are given as follows [15]: P ( F [ F ' ) = max(min(~F(W), I.LF,(W))) N ( F I F ' ) = 1 - e ( ~ F I E ' ) 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 m e d i u m , i Figure 3. Possibility distribution for the concept "medium." 270 K.S. Leung and Y. T. So w h e r e P(FIF') is t h e possibility o f the fuzzy d a t u m F ' given the fuzzy p a t t e r n F , and N(F[F') is the necessity o f the fuzzy d a t u m F ' given t h e fuzzy p a t t e r n F . /~(w) is the m e m b e r s h i p function o f w in the universe o f discourse, an d ~ F is the c o m p l e m e n t o f F . T h e possibility m e a s u r e s the d e g r e e o f overl ap p i n g b e t w e e n t h e d a t u m and the p a t t e r n ; o r in o t h e r words, it m e a s u r e s t h e n o n - e m p t i n e s s o f F A F ' . F o r example: P(tall~very tall) = 1 P ( s h o r t l m o r e - o r - l e s s short) = 1 P ( t a l l l m e d i u m ) = 0.028 P ( s h o r t l t a l l ) = 0 Possibility is an optimistic m e a s u r e : it only m e a n s s o m e t h i n g is possi- ble b u t d o e s n o t g u a r a n t e e it will h a p p e n . O n t h e o t h e r hand, necessity is a drastic m e a s u r e t h a t is equal to the impossibility b e t w e e n two o p p o s i t e events. F o r example: N(tall~very tall) = 0.6561 N ( s h o r t l m o r e - o r - l e s s short) = 0.4275 N ( t a l l l m e d i u m ) = 0 N(shortltall) = 0 U n d e r n o r m a l circumstances, the necessity has t h e following p r o p e r t i e s : I F N(FIF') > 0.5 T H E N F ' has a m o r e c o n c e n t r a t e d o r n a r r o w e r distribution t h a n F. e.g., tall and very tall. I F N(FIF') < 0.5 T H E N F ' has a m o r e dilated o r b r o a d e r distribution t h a n F . e.g., short and m o r e - o r - l e s s short, tall a n d m e d i u m . I F N(FIF') = 0.5 T H E N F has the same distribution as F. Consistency Check for Fuzzy Expert Systems 271 Also f r o m the definition o f b o t h possibility a n d necessary, it can be shown that: i, P ( A I B ) = P ( B I A ) .... (1) ii, P(AIB u C ) - - max(P(AIB), P ( A I C ) ) .... ( 2 ) iii, N(AIB U C ) -- m i n ( N ( A I B ) , N(AIC)) .... (3) iv, N ( A I A ) > = 0.5 .... (4) 3.2. Similarity T h e similarity M is calculated by the following algorithm [6]: I F N ( F I F ' ) > 0.5 T H E N M = P ( F [ F ' ) E L S E M = ( N ( F I F ' ) + 0.5)*P(FIF') where * d e n o t e s multiplication. T h a t m e a n s w h e n necessity is greater t h a n or equal to 0.5, the similar- ity b e t w e e n p a t t e r n and d a t u m is s a t u r a t e d and is forced to equal the possibility. I f the similarity is n o t s a t u r a t e d (necessity is less t h a n 0.5), the similarity should d e p e n d o n b o t h possibility and necessity. T h e similarity m e a s u r e is proven to be a useful tool to d e t e r m i n e the similarity b e t w e e n the fuzzy d a t a in a fact base a n d the fuzzy patterns in the premise part of a rule [8]. However, t h e r e is o n e shortcoming in similarity; it is n o t commutative, i.e, M ( p l q ) ~ M(qlp). F o r example, P ( n o t mediumltall) = 1 and P ( m e d i u m l t a l l ) = 0.0588 N ( n o t mediumltall) = 1 - 0.0588 = 0.9412 T h e r e f o r e , M ( n o t m e d i u m ltall) = 1. But P(talllnot m e d i u m ) = 1 and P ( n o t talllnot m e d i u m ) = 1 =* N(talllnot m e d i u m ) = 1 - 1 = 0 T h e r e f o r e , M(talllnot m e d i u m ) = 0.5. H e n c e , the o r d e r o f rule checking will influence the value o f similarity. Owing to this limitation, the affinity ( A ) m e a s u r e is introduced. 3.3. A f f i n i t y T h e Affinity of two simple propositions p and q is defined as follows: A ( p , q ) = M ( p A q[p v q) where Izp ̂ q(W) = m i n ( t z p ( w ) , tZq(W)), tzp v q(W) = max(tZp(W), tZq(W)) a n d /z(w) is the m e m b e r s h i p function o f w in the universe o f discourse. 272 K.S. Leung and Y. T. So A(p, q) measures the similarity o f p v q given p A q. T h a t is, to what extent does the whole part o f b o t h p a n d q ( p v q) m a t c h the shared part o f t h e m ( p A q). T h e following are some properties o f the affinity measures: i, I f p and q are identical, A(p, q) will be equal to 1 (because p V q = p A q ) . ii, A(p, q) is commutative, i.e., A(p, q) = A(q, p). B e c a u s e p A q = q A p a n d p V q = q V p . iii, A(p, q) = min(M(plq), M(qlp)) .... (5) P r o o f o f a s s e r t i o n (iii): Consider the possibility first P ( p A q ] p V q) =max(min(IXp^q(W),lXpvq(W))) = max(I.£pAq(W)) = max(min( i.tp(w), tXq(W))) = P ( p l q ) = P ( q l p ) and Now consider Similarly, N ( p A qlp V q) = m i n ( N ( p A qlp), N ( p A q l q ) ) N ( p A qlp) = l - - P ( ~ ( p A q ) I p ) = 1 - P ( p [ ~ ( p A q ) ) = 1 - P ( p l ~ p V ~ q ) = 1 - m a x ( P ( p [ ~ p), P(p[ ~ q)) = 1 - m a x ( P ( ~ pip), P( ~ q l p ) ) = min(N(p[p), N(q[p)) N ( p A qlq) = min(N(qlq), N ( p l q ) ) [by eqn (1)] .... (6) [by eqn (3)] [by eqn (1)] [by eqn (2)] [by eqn (1)] Consistency Check for Fuzzy Expert Systems 273 So t h a t N ( p /x qlp v q) = m i n ( N ( p l p ) , N(p]q), N(q]p), N(qlq)) .... (7) By e q n (4), it can be c o n c l u d e d that N ( p l p ) an d N(qlq) are b o t h g r e a t e r t h a n o r e q u a l to 0.5. Now, we c o n s i d e r all f o u r cases: case 1: If b o t h N(p[q) and N(qlp) > = 0.5, t h e n M(plq) = P(plq) = P(q[p) = M(qlp) = min(M(plq), M(qlp)) [by e q n (6)] and N ( p A qlP V q > = 0.5 [by e q n (7)] T h u s Z ( p , q ) = M ( p A qlp V q) = P ( p A qlp V q) = e ( p l q ) = P(qlp) = min(M(plq), M(qlp)) [by e q n (6)] Thus, the assertion ( e q n (5)) holds. case 2: If N(plq) < 0.5 and N(qlp) > 0.5, t h e n N ( p A qlp V q) = N(plq) < 0.5 and A ( p , q) = (N(p[q) + 0.5)*P(p[q) = M(plq) ( m i n i m u m o f M(plq) and M(q[p)) case 3: If N(qlp) < 0.5 and N(p[q) > 0.5, t h e n N ( p A qlP v q) = N(qlp) < 0.5 and A ( p , q) = (N(qlp) + 0.5)*P(q[p) = M(q]p) ( m i n i m u m o f M(pJq) and M(q[p)) case 4: If b o t h N(plq) and N(qlp) < 0.5, t h e n N ( p A qlP V q) = min(N(p[q), N(qlp)) So A ( p , q) = M ( p A qlp v q) = ( N ( p m qlp v q) + 0 . 5 ) * e ( p m qlp v q) = (min(N(plq), N(qlp)) + 0.5)*P(plq) = min(M(plq), M(qlp)) T h e r e f o r e , A(p, q) = min(M(plq), M(q]p)) holds fo r all cases. [by eqns (6) & (7)] 274 K.S. Leung and Y. T. So I m p l e m e n t i n g A ( p , q ) using o u r definition (ie., A ( p , q ) = M ( p A ql p v q)) will result in two comparisons, two additions, and one multiplica- tion less t h a n that o f using A ( p , q) = min(M(plq), M(qlp)) each time. H e n c e the f o r m e r is actually used for i m p l e m e n t a t i o n in o u r system. A m o n g the above properties, the c o m m u t a t i v e o n e is the most impor- tant because it implies t h a t the o r d e r o f rule-checking has no influence on the value of the affinity. In o r d e r to investigate the suitability o f affinity in consistency checks, we c o m p u t e all the results o f the affinity for different values o f p and q on a fuzzy object such as " h e i g h t . " H e d g e s like " v e r y " and " m o r e - o r - l e s s " and logical n e g a t i o n " n o t " are a d d e d to the possible fuzzy terms o f the object. So the values of p and q could be [not] [very Imore-or-less] {tall Imedium Ishort} where the choice inside the [ ] is optional. (Although the expressions like "more-or-less m e d i u m " or " v e r y m e d i u m " are n o t very meaningful, we include t h e m to complete the investigation.) T h e results o f the affinity o f any two fuzzy expressions p and q can be divided into four groups. (1) A ( p , q ) = 1 e.g., A(tall, tall) = 1 A(very m e d i u m , m e d i u m ) = 1 (2) A ( p , q) > 0.5 e.g., A(tall, very tall) = 0.9305 A(more-or-less short, short) = 0.9275 A(more-or-less m e d i u m , very m e d i u m ) = 0.9273 (3) A ( p , q ) = 0.5, P ( p /x qlp v q) = 1 a n d N ( p A q[p v q) = 0 e.g., A(tall, n o t m e d i u m ) = 0.5 A ( n o t short, m e d i u m ) = 0.5 A ( n o t very tall, more-or-less short) = 0.5 (4) A ( p , q ) < 0.5, P ( p A qlp V q) < 1 and N ( p A qlp V q) = 0 e.g., A(tall, n o t tall) = 0.1720 A(more-or-less tall, m e d i u m ) = 0.0837 A(short, tall) = 0 The affinities o f groups (1) and (2) are both greater t h a n 0.5. This m e a n s that their degrees of matching are greater t h a n their differences. There- fore, we conclude that the two fuzzy concepts being c o m p a r e d are the same or similar (to some extent). The affÉnities in group (4) are less t h a n 0.5, we say that the two terms are different. The affinities in group (3) equal to 0.5 which m e a n s that the t r u t h and falsity o f the likeness between two fuzzy terms c a n n o t be indicated by the affinity measure. As a conclu- Consistency Check for Fuzzy Expert Systems 275 sion, if the affinity between two fuzzy terms is greater than 0.5, they can be treated as equal. For case (3), we could swing to either side depending on the implementation. The definition of affinity could be extended to detect the likeness of the antecedent part of two rules. Let P1 and P2 be the antecedent parts of two rules that contain multiple propositions connected by A N D operators, i.e., P1 - - P l l A P12 A P13 A "'" A Plk P2 = P21 A P22 A P23 A .-- A P2k Then A ( P 1 , P2) = f i A ( P l k , P2k) k = l If Plk and P2k are non-fuzzy and Plk = P2k, then A ( P l k , p 2 k ) = 1; otherwise, A ( P l k , P2k) = 0. The affinity of an antecedence is equal to the product of the affinity of its propositions. 4. A C O N S I S T E N C Y C H E C K E R IN F U Z Z Y E N V I R O N M E N T Using affinity, we could detect inconsistency in a fuzzy environment. The detection methods can be the same as those used in a nonfuzzy environ- ment except that we use affinity to measure the degree of matching of two fuzzy expressions. i.e., (P1 = P2) and (P1 4: P2) could be replaced by A ( P I I P 2 ) >_>_ 0.5 and A ( P I I P 2 ) < 0.5 in a fuzzy environment respectively. A consistency checker in a fuzzy environment (CCFE) has been imple- mented to check the rule bases built from a fuzzy expert system shell Z-III that allows any mix of fuzzy and non-fuzzy terms in the rules [8]. C C F E is implemented using Turbo C 2.0 in a microcomputer environment. Affinity measure is employed to determine the degree of matching of two fuzzy propositions. At the first stage of the development of CCFE, we set the following assumptions: (a) Only one proposition is allowed in the consequence part of each rule. (b) Disconfirmation of a consequent proposition is represented by a negative certainty factor to a rule. i.e., For the rule: IF height is tall T H E N weight is not light certainty is 0.8 276 K.S. Leung and Y. T. So (c) (d) (i) can be represented as follows: IF height is tall T H E N weight is light certainty is - 0.8 Single-valued objects are assumed. CCFE only searches for the following most common inconsis- tencies: Redundancy Let: rule 5: IF P1 T H E N C1 (CF1) rule 6: IF P2 T H E N C2 (CF2) where P1 and P2 may be any combination of propositions, and CF stands for the certainty factor of a rule. Redundancy may occur when: A ( P I l P 2 ) > 0.5 & A ( C l J C 2 ) > 0.5 & sign(CF1) = sign(CF2) or A ( P I I P 2 ) > 0.5 & A ( C I l C 2 ) < 0.5 & sign(CF1) 4~ sign(CF2) ( i i ) Contradiction Contradiction may occur when: A ( P I l P 2 ) > 0.5 & A ( C I l C 2 ) > 0.5 & sign(CF1) v~ sign(CF2) or A ( P I l P 2 ) > 0.5 & A ( C I l C 2 ) < 0.5 & sign(CF1) = sign(CF2) ( i i i ) Subsumption A special case of redundancy. The details have been described in section 2. (iv) Sub-contradiction A special case of contradiction. The details have been described in section 2. A decision table is used for verification of the rule base. A decision table facilitates the testing of a set of rules for inconsistent conditions. Each column of a decision table represents the conditions of a rule. Building a decision table from the rules is relatively simple [5]. CCFE creates a decision table by parsing the rules stored in the rule base, entering each corresponding value in the appropriate row and column. The table is implemented using arrays of pointers. Thus, the storage for the table is dynamically allocated. Besides, a dynamically allocated one-dimensional array is created to store the certainty factor of each rule. Consistency Check for Fuzzy Expert Systems T a b l e 1. A Sample R u l e Set 277 (rule rl (if (height is tall then weight is heavy) certainty is 0.7 (rule r3 (if (eating is much) and (activity is little) then weight is moreorless heavy) certainty is 0.9 (rule r2 (if (height is tall) and (eating is very much) then weight is very heavy) certainty is 0.65 T h e algorithm for creating the decision table and the array storing the certainty factors is as follows: R e a d all the rules f r o m a file into the rule base. C o u n t the total n u m b e r of objects and rules in the rule base. Allocate spaces for the table a n d the certainty factors. Initialise all the cells in the table to U N O C C U P I E D . F o r all the rules in the rule base Parse the rule a n d e n t e r the values to the corresponding row and column. Set t h a t cell to O C C U P I E D . F o r instance, f r o m the rules in Table 1, C C F E will create the corre- sponding decision table a n d the array storing certainty factors as shown in Figure 4. height eating activity weight r l r2 r3 tall tall very much much little heavy very heavy moreorless heavy Certainty factor 07 I 065 I Figure 4. The sample decision table. 0.9 278 K.S. Leung and Y. T. So A f t e r constructing the decision table, all the rules are checked for inconsistencies. Affinity m e a s u r e is employed to d e t e r m i n e the likeliness b e t w e e n two expressions, either fuzzy or non-fuzzy. T h e following is the algorithm for consistency checking: F o r i = 1 to no. o f rules - 1 F o r j = i + 1 to no. o f rules case compare(antecedence(i), antecedence(j)) E Q U A L : if ( s a m e ( c o n s e q u e n c e ( i ) , consequence(j)) t h e n if (sign(CF(i)) = sign(CF(j))) t h e n report r e d u n d a n c y else report contradiction else if (sign(CF(i)) = sign(CF(j))) t h e n report contradiction else report r e d u n d a n c y endif continue SUBSET: if ( s a m e ( c o n s e q u e n c e ( i ) , consequence(j)) t h e n else if (sign(CF(i)) = sign(CF(j))) t h e n report subsumption else report sub-contradiction if (sign(CF(i)) = sign(CF(j))) t h e n report sub-contradiction else report subsumption e n d i f continue D I F F E R E N T : continue endcase e n d f o r e n d f o r where compare is a function using affinity m e a s u r e to d e t e r m i n e w h e t h e r two antecedences are the SAME, D I F F E R E N T , or one o f the ante- cedence is a S U B S E T o f the other. Consistency Check for Fuzzy Expert Systems 279 same is a Boolean function using affinity measure to determine whether two consequences are the same. sign returns the sign of the certainty factor. 5. RESULTS AND DISCUSSIONS CCFE is used to verify the consistency of fuzzy rule bases. The following rule base with fuzzy and non-fuzzy objects is verified by CCFE and the results are presented. (The example is an inconsistent testing case, so some rules may not make too much sense.) Let height is a fuzzy object with possible values (tall, medium, short). weight is a fuzzy object with possible values (heavy, fit, light). eating is a fuzzy object with possible values (much, balanced, little). sleeping is a non-fuzzy single-valued object with possible values (enough, fair, bad). sport is a non-fuzzy single-valued object with possible values (big-2, football, basketball). Rule Base: (rule r l If (height is tall) then weight is heavy) Certainty is 0.7 (rule r2 if ((height is tall) and (eating is much)) then weight is very heavy) Certainty is 0.75 (rule r3 if (height is tall) then weight is balanced) Certainty is - 0 . 5 (rule r4 If ((eating is much) and (sport is big-2)) then weight is very heavy) Certainty is 0.6 280 K.S. Leung and Y. T. So (rule r5 if (eating is very much) then weight is light) Certainty is 0.5 (rule r6 if (eating is very much) and (sport is big-2) and (sleeping is not bad) then weight is very heavy) Certainty is - 0 . 7 (rule r7 if (eating is much) and (sport is big-2) and sleeping is enough) then weight is heavy) Certainty is 0.6 (rule r8 If (sleeping is not enough) then weight is light) Certainty is 0.5 (rule r9 If (sleeping is bad) then weight is light) Certainty is 0.4 Diagnosis: Warning 1: Subsumption between rules r l and r2 Warning 2: Redundancy between rules r l and r3 Warning 3: Subsumption between rules r2 and r3 Warning 4: Sub-contradiction between rules r2 and r5 Warning 5: Sub-contradiction between rules r4 and r5 Warning 6: Sub-contradiction between rules r4 and r6 Warning 7: Subsumption between rules r4 and r7 Warning 8: Subsumption between rules r5 and r6 Warning 9: Sub-contradiction between rules r5 and r7 Warning 10: Contradiction between rules r6 and r7 Warning 11: Redundancy between rules r8 and r9 Total, 11 warnings. Consistency Check for Fuzzy Expert Systems 281 F r o m the results, we can see that affinity is useful to d e t e r m i n e the degree of matching o f two fuzzy expressions for consistency checking. T h e techniques used in a non-fuzzy e n v i r o n m e n t can be easily trans- p o r t e d to a fuzzy environment. However, in an e n v i r o n m e n t full of mixtures o f approximate and exact reasonings, there are no absolute definitions of consistency as discussed in sections 2 and 3. A fuzzy consistency checker such as the one i m p l e m e n t e d can only serve as a provider for warnings of possible inconsistency to aid b e t t e r knowledge engineering. T h e levels o f warnings can be adjusted by varying p a r a m e - ters such as the threshold affinity in the definition and levels o f tracking. 6. C O N C L U S I O N Using affinity, it has b e e n d e m o n s t r a t e d that we can detect possible inconsistency in a fuzzy environment. T h e detection techniques are very similar to those used in a non-fuzzy e n v i r o n m e n t except that we use. affinity to m e a s u r e the likeness o f two fuzzy expressions, i.e., for two non-fuzzy expressions A1 and A2, A1 = A 2 and (A1 v~ A2) could be replaced by A ( A 1 , A2) > 0.5 and A ( A 1 , A2) < 0.5 respectively for fuzzy expressions A1 and A 2 in a fuzzy environment. The commutative property of affinity makes the checking o r d e r of new and old rules totally indepen- dent. The affinity m e a s u r e has been proven to be a good tool to m e a s u r e the likeness o f two fuzzy terms. The consistency checker C C F E has been successfully i m p l e m e n t e d for aiding knowledge engineering in a heteroge- neous fuzzy e n v i r o n m e n t with mixed fuzzy and non-fuzzy terms. References 1. Hayes-Roth, F., Rule-based systems, Communication of ACM, 28(9), 921-932, 1985. 2. Shortliffe, E. H., Computer-Based Medical Consultations: MYCIN, Elsevier, New York, 1976. 3. Suwa, M., Scott, A. C., and Shortliffe, E. H., An approach to verifying completeness and consistency in a rule-based expert system, AI Magazine, 3(3), 16-21, 1982. 4. KES General Description Manual, Software Architecture and Engineering, Inc., Arlington, V.A., 33, 1983. 5. Cragun, B. J., and Steudel, H. J., A decision-table-based processor for checking completeness and consistency in rule-based expert systems, Int. J. Man-Machine Studies, 26, 633-648, 1987. 282 K.S. Leung and Y. T. So 6. Leung, K. S., and Lam, W., Fuzzy concepts in expert systems, IEEE Computer, 2l(9), 43-56, Sept. 1988. 7. Leung, K. S., and Lam, W., A fuzzy expert system shell using both exact and inexact reasoning, J. Automated Reasoning, 5(2), 207-233, 1989. 8. Leung, K. S., So, Y. T., Leung, A., and Wong, W. S. F., Z-Ill: A PC-based fuzzy expert system shell, Proc. Int. Computer Symp., 657-662, 1990. 9. Beauvieux, A., and Dague, P., Interactive checking of knowledge base consis- tency, Int. Computer Sci. Conf. 567-574, 1988. 10. Buchannan, B. G., and Shortliffe, E. H., Knowledge Engineering, in Rule-Based Expert Systems, Addisley-Wesley Publishing Company, 1984. 11. Nguyen, T. A., Perkins, W. A., Laffey, T. J., and Pecora, D., Knowledge base verification, A I Magazine, 69-75, summer 1987. 12. Tsang, W. W., Wan, Y. S., Lim, E. L., and Hioe, W., A space searching method for checking the consistency and completeness of a rulebase, Int. Computer Sci. Conf. 575-579, 1988. 13. Zadeh, L. A., A fuzzy-set-theoretic interpretation of linguistic hedges, J. Cybernetics, 2(3), 4-34, 1972. 14. Zadeh, L. A. P R U F - - A meaning representation language for natural lan- guages, Int. J. Man-Machine Studies, 10, 395-460, 1978. 15. Cayrol, M., Farreny, H., and Prade, H., Fuzzy Pattern Matching, Kybernetes, 11, 103-116, 1982.