85
COMP 4601 Expert Systems 1

16-Expert-SystemsChaining% • Forward%chaining%is%a data(driven%method%of%deriving%a par5cular%goal%from%agiven%knowledge%base%and%setof% inferencerules • Inference%rules%are%applied%by%matching%facts%to

  • Upload
    vudieu

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

COMP  4601  

Expert  Systems  

1  

Mo5va5on  

•  Want  to  capture  exper5se  of  knowledgeable  individuals  in  a  field:  – Doctors  for  diagnosis  – Specialists  for  recommenda5on  

•  Exper5se  cannot  be  easily  mined  as  few  data  points  exist  (if  at  all)  

•  Expert  system  programming  is  dis5nc5vely  different  from  conven5onal  programming.  

2  

Expert  Systems  •  Designed  to  func5on  similar  to  a  human  expert  opera5ng  

within  a  specific  problem  domain  

•  Used  to:  –  Provide  an  answer  to  a  certain  problem,  or  –  Clarify  uncertain5es  where  normally  a  human  expert  would  be  

consulted  

•  OOen  created  to  operate  in  conjunc5on  with  humans  working  within  the  given  problem  domain,  rather  than  as  a  replacement  for  them  

22  

Components  of  an  Expert  System  •  Knowledge  Base  

–  Stores  knowledge  used  by  the  system,  usually  represented  in  a  formal  logical  manner  (oOen  first  order  logic)  

•  Inference  System  – Defines  how  exis5ng  knowledge  may  be  used  to  derive  new  knowledge  

•  Search  Control  – Determines  which  inference  to  apply  at  a  given  stage  of  the  deduc5on  

23  

Knowledge  Representa5on  •  For  now,  we’ll  use  a  simple  If  …  Then  …  consequence  rela5on  

using  English  seman5cs  

•  i.e.,:  If  [it  is  raining]  Then  [I  should  wear  a  coat]  –  [it  is  raining]  is  the  antecedent  of  the  rela5on  –  [I  should  wear  a  coat]  is  the  consequent  of  the  rela5on  

•  Facts  can  be  understood  as  consequence  rela5ons  with  an  empty  antecedent  –  i.e.,:  “If  []  Then  [it  is  raining]”  is  equivalent  to  the  fact  that  [it  is  

raining]  

24  

Inferring  New  Knowledge  •  New  knowledge  can  be  constructed  from  exis5ng  knowledge  

using  inference  rules  

•  For  instance,  the  inference  rule  modus  ponens  can  be  used  to  derive  the  consequent  of  a  consequence  rela5on,  given  that  the  antecedent  is  true  

•  i.e.,:    –  k1:  If  [it  is  raining]  Then  [I  should  wear  a  coat]  –  k2:  [it  is  raining]  –  result:  [I  should  wear  a  coat]  

25  

Goal  Directed  Reasoning  •  Inference  rules  are  applied  to  knowledge  base  in  some  order  

to  achieve  a  par5cular  goal  

•  The  goal  in  an  expert  system  is  formed  as  a  ques5on,  or  query,  to  which  we  want  the  answer  

•  i.e.,:  [I  should  wear  a  coat]?  –  note:  this  would  read  easier  in  English  as  “should  I  wear  a  coat”,  but  

we  want  to  use  the  same  proposi5onal  symbol  as  is  in  our  knowledge  base  

•  The  goal  of  the  search  is  to  determine  an  answer  to  the  query,  which  may  be  boolean  as  above  or  more  complex  

26  

Inference  in  rule-­‐based  systems    

•  Two  control  strategies:    –  forward  chaining  – backward  chaining  

27  

Forward  Chaining  •  Forward  chaining  is  a  data  driven  method  of  deriving  a  

par5cular  goal  from  a  given  knowledge  base  and  set  of  inference  rules  

•  Inference  rules  are  applied  by  matching  facts  to  the  antecedents  of  consequence  rela5ons  in  the  knowledge  base  

•  The  applica5on  of  inference  rules  results  in  new  knowledge  (from  the  consequents  of  the  rela5ons  matched),  which  is  then  added  to  the  knowledge  base  

33  

Forward  Chaining  

•  Inference  rules  are  successively  applied  to  elements  of  the  knowledge  base  un5l  the  goal  is  reached  

•  A  search  control  method  is  needed  to  select  which  element(s)  of  the  knowledge  base  to  apply  the  inference  rule  to  at  any  point  in  the  deduc5on  

34  

Forward  Chaining  Example  

•  Knowledge  Base:  –  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  –  If  [X  chirps  and  sings]  Then  [X  is  a  canary]  –  If  [X  is  a  frog]  Then  [X  is  colored  green]  –  If  [X  is  a  canary]  Then  [X  is  colored  yellow]  –  [Fritz  croaks  and  eats  flies]  

•  Goal:  –  [Fritz  is  colored  Y]?  

35  

Forward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]              

 Goal  [Fritz  is  colored  Y]?  

 

36  

Forward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]        

   

Goal  [Fritz  is  colored  Y]?  

 

37  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]              

 Goal  [Fritz  is  colored  Y]?  

 

38  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]        

 Goal  [Fritz  is  colored  Y]?  

 

39  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  

?  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]        

 Goal  [Fritz  is  colored  Y]?  

 

40  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]        

 Goal  [Fritz  is  colored  Y]?  

 

41  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  If  [X  is  a  frog]  Then  [X  is  colored  green]  

[Fritz  is  colored  green]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]        

 Goal  [Fritz  is  colored  Y]?  

 

42  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  If  [X  is  a  frog]  Then  [X  is  colored  green]  

[Fritz  is  colored  green]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]    [Fritz  is  colored  green]  

 Goal  [Fritz  is  colored  Y]?  

 

43  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  If  [X  is  a  frog]  Then  [X  is  colored  green]  

[Fritz  is  colored  green]  

?  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]    [Fritz  is  colored  green]  

 Goal  [Fritz  is  colored  Y]?  

 

44  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  If  [X  is  a  frog]  Then  [X  is  colored  green]  

[Fritz  is  colored  green]  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]    [Fritz  is  colored  green]  

 Goal  [Fritz  is  colored  Y]?  

 

45  

Forward  Chaining  Example  

If  [X  croaks  and  eats  flies]    Then  [X  is  a  frog]   [Fritz  croaks  and  eats  flies]  

[Fritz  is  a  frog]  If  [X  is  a  frog]  Then  [X  is  colored  green]  

[Fritz  is  colored  green]   [Fritz  is  colored  Y]  ?  

Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    [Fritz  is  a  frog]    [Fritz  is  colored  green]  

 Goal  [Fritz  is  colored  Y]?  

 

Y  =  green  

46  

Read  the  ini3al  facts  Begin    

Filter  Phase  =>  Find  the  fired  rules  While  Fired  rules  not  empty  AND  not  end  DO    

Choice  Phase  =>  Solve  the  conflicts  Apply  the  chosen  rule  Modify    (if  any)  the  set  of  rules  

End  do  End    Examples:  Rete  algorithm,  CLIPS,  Jess,  JEOPS,  …  

Forward  Chaining  Algorithm  

Backward  Chaining  •  Backward  chaining  is  a  goal  driven  method  of  deriving  a  

par5cular  goal  from  a  given  knowledge  base  and  set  of  inference  rules  

•  Inference  rules  are  applied  by  matching  the  goal  of  the  search  to  the  consequents  of  the  rela5ons  stored  in  the  knowledge  base  

•  When  such  a  rela5on  is  found,  the  antecedent  of  the  rela5on  is  added  to  the  list  of  goals  (and  not  into  the  knowledge  base,  as  is  done  in  forward  chaining)  

48  

Backward  Chaining  

•  Search  proceeds  in  this  manner  un5l  a  goal  can  be  matched  against  a  fact  in  the  knowledge  base  – Remember:  facts  are  simply  consequence  rela5ons  with  empty  antecedents,  so  this  is  like  adding  the  ‘empty  goal’  to  the  list  of  goals  

•  As  with  forward  chaining,  a  search  control  method  is  needed  to  select  which  goals  will  be  matched  against  which  consequence  rela5ons  from  the  knowledge  base  

49  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?                    

 

50  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?                    

 

51  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?                    

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

52  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]              

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

53  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]              

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

54  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]              

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

55  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]        

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

56  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]        

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

57  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]        

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  

[X  croaks  and  eats  flies]  

58  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]    [X  croaks  and  eats  flies]  

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  

[X  croaks  and  eats  flies]  

59  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]    [X  croaks  and  eats  flies]  

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  

[X  croaks  and  eats  flies]  

60  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]    [X  croaks  and  eats  flies]  

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

[X  is  a  frog]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  canary]  

If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  

[X  croaks  and  eats  flies]   [Fritz  croaks  and  eats  flies]  

X  =  Fritz,  Y  =  green  

61  

Backward  Chaining  Example  Knowledge  Base  If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]    If  [X  chirps  and  sings]  Then  [X  is  a  canary]    If  [X  is  a  frog]    Then  [X  is  colored  green]    If  [X  is  a  canary]    Then  [X  is  colored  yellow]    [Fritz  croaks  and  eats  flies]    Goals  [Fritz  is  colored  Y]?    [X  is  a  frog]    [X  is  a  canary]    [X  croaks  and  eats  flies]  

 

[Fritz  is  colored  Y]  

If  [X  is  a  frog]  Then  [X  is  colored  green]  

If  [X  is  a  canary]  Then  [X  is  colored  yellow]  

[X  is  a  frog]   [X  is  a  canary]  

If  [X  croaks  and  eats  flies]  Then  [X  is  a  frog]  

[X  croaks  and  eats  flies]   [Fritz  croaks  and  eats  flies]  

X  =  Fritz,  Y  =  green  

62  

Filter  Phase  IF  set  of  selected  rules  is  empty  THEN  Ask  the  user  ELSE  

WHILE  not  end  AND  we  have  a  rule  to  select  DO    Choice  Phase  Add  the  condi5ons  of  the  rules  IF  the  condi5on  not  solved  THEN                put  the  condi5on  as  a  goal  to  solve  

END  WHILE    Examples:  Prolog:  SWI-­‐Prolog,  tuProlog,  …  

Backward  Chaining  Algorithm  

Inference  in  rule-­‐based  systems:  Contras5ng  Forward  and  Backward  

Chaining  

64  

Forward  &  backward  chaining  

•  The  choice  of  strategy  depends  on  the  nature  of  the  problem.    

•  Assume  the  problem  is  to  get  from  facts  to  a  goal  (e.g.  symptoms  to  a  diagnosis).    

70  

Forward  &  backward  chaining  

Backward  chaining  is  the  best  choice  if:  •  The   goal   is   given   in   the   problem   statement,   or  can  sensibly  be  guessed  at  the  beginning  of  the  consulta5on;    

or:  •  The  system  has  been  built  so  that  it  some5mes  asks  for  pieces  of  data  (e.g.  "please  now  do  the  gram  test  on  the  pa5ent's  blood,  and  tell  me  the  result"),  rather  than  expec5ng  all  the  facts  to  be  presented  to  it.  

71  

Forward  &  backward  chaining  

Backward  chaining      •  This  is  because  (especially  in  the  medical  domain)  the  test  may  be    – expensive,  – or  unpleasant,  – or  dangerous  for  the  human  par5cipant  

so  one  would  want  to  avoid  doing  such  a  test  unless  there  was  a  good  reason  for  it.  

72  

Forward  &  backward  chaining  

Forward  chaining  is  the  best  choice  if:  •  All  the  facts  are  provided  with  the  problem  statement;    

or:  •  There  are  many  possible  goals,   and  a   smaller  number  of  paperns  of  data;  

or:  •  There  isn't  any  sensible  way  to  guess  what  the  goal  is  at  the  beginning  of  the  consulta5on.  

73  

Forward  &  backward  chaining  

•  Note  also  that    –  a  backwards-­‐chaining  system  tends  to  produce  a  sequence  of  ques5ons  which  seems  focussed  and  logical  to  the  user,  

–  a  forward-­‐chaining  system  tends  to  produce  a  sequence  which  seems  random  &  unconnected.    

•  If  it  is  important  that  the  system  should  seem  to  behave  like  a  human  expert,  backward  chaining  is  probably  the  best  choice.    

74  

Forward  &  backward  chaining  

•  Some  systems  use  mixed  chaining,  where  some  of  the  rules  are  specifically  used  for  chaining  forwards,  and  others  for  chaining  backwards.  The  strategy  is  for  the  system  to  chain  in  one  direc5on,  then  switch  to  the  other  direc5on,  so  that:  – the  diagnosis  is  found  with  maximum  efficiency;  

–  the  system's  behaviour  is  perceived  as  "human".      

75  

Meta-­‐rules  

•  Meta-­‐rules  are  rules  which  alter  the  reasoning  process:  these  can  make  a  produc5on  system  more  flexible.  –  e.g.,  a  rule  which  chooses  a  par5cular  style  of  conflict-­‐resolu5on,  on  the  basis  of  data  in  the  working  memory.    

–  Or  a  rule  which  switches  from  forward  to  backward  chaining  at  a  suitable  moment  in  the  reasoning  process.    

–  Or  a  rule  which  "decides"  to  consider  a  certain  type  of  rule  before  other  types.  

76  

Problem  decomposi5on  into  an  and-­‐or  graph  

77  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  A  technique  for  reducing  a  problem  to  a  produc5on  system.    

•  One  par5cular  form  of  intermediate  representa5on.  – A  structured  representa5on  of  the  knowledge,  which  is  not  yet  in  the  form  of  code  that  can  be  put  into  an  expert  system’s  knowledgebase.  

78  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  A  technique  for  reducing  a  problem  to  a  produc5on  system,  as  follows:  – The  principle  goal  is  iden5fied;  it  is  split  into  two  or  more  sub-­‐goals;  these,  too  are  split  up.    

– A  goal  is  something  you  want  to  achieve.  A  sub-­‐goal  is  a  goal  that  must  be  achieved  in  order  for  the  main  goal  to  be  achieved.  

79  

Problem  decomposi5on  into  an  and-­‐or  graph  

– A  graph  is  drawn  of  the  goal  and  sub-­‐goals.    –  Each  goal  is  wripen  in  a  box,  called  a  node,  with  its  subgoals  underneath  it,  joined  by  links.  

80  

Problem  decomposi5on  into  an  and-­‐or  graph  

–  The  leaf  nodes  at  the  bopom  of  the  tree  -­‐    the  boxes  at  the  bopom  of  the  graph  that  don’t  have  any  links  below  them  

 -­‐  are  the  pieces  of  data  needed  to  solve  the  problem.    

81  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  A  goal  may  be  split  into  2  (or  more)  sub-­‐goals,  BOTH  of  which  must  be  sa5sfied  if  the  goal  is  to  succeed;  the  links  joining  the  goals  are  marked  with  a  curved  line,  like  this:    

Goal 1 Goal 2 82  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  Or  a  goal  may  be  split  into  2  (or  more)  sub-­‐goals,  EITHER  of  which  must  be  sa5sfied  if  the  goal  is  to  succeed;  the  links  joining  the  goals  aren't  marked  with  a  curved  line:    

Goal 1 Goal 2 83  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  Example    •  "The  func3on  of  a  financial  advisor  is  to  help  the  user  decide  whether  to  invest  in  a  savings  account,  or  the  stock  market,  or  both.  The  recommended  investment  depends  on  the  investor's  income  and  the  current  amount  they  have  saved:  

84  

Problem  decomposi5on  into  an  and-­‐or  graph  

❶ Individuals  with  inadequate  savings  should  always  increase  the  amount  saved  as  their  first  priority,  regardless  of  income.  

❷ Individuals  with  adequate  savings  and  an  adequate  income  should  consider  riskier  but  poten3ally  more  profitable  investment  in  the  stock  market.    

85  

Problem  decomposi5on  into  an  and-­‐or  graph  

❸ Individuals  with  low  income  who  already  have  adequate  savings  may  want  to  consider  spliWng  their  surplus  income  between  savings  and  stocks,  to  increase  the  cushion  in  savings  while  aXemp3ng  to  increase  their  income  through  stocks.  

86  

Problem  decomposi5on  into  an  and-­‐or  graph  

❹ The  adequacy  of  both  savings  and  income  is  determined  by  the  number  of  dependants  an  individual  must  support.      There  must  be  at  least  $3,000  in  the  bank  for  each  dependant.      An  adequate  income  is  a  steady  income,  and  it  must  supply  at  least  $9,000  per  year,  plus  $2,500  for  each  dependant."  

87  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  How  can  we  turn  this  informa5on  into  an  and-­‐or  graph?  

•  Step  1:  decide  what  the  ul5mate  advice  that  the  system  should  provide  is.    It’s  a  statement  along  the  lines  of  “The  investment  should  be  X”,  where  X  can  be  any  one  of  several  things.  

88  

•  Start  to  draw  the  graph  by  placing  a  box  at  the  top:  

Advise  user:  investment  should  be  X  

89  

•  Step  2:  decide  what  sub-­‐goals  this  goal  can  be  split  into.    In  this  case,  X  can  be  one  of  three  things:  savings,  stocks  or  a  mixture.    Add  three  sub-­‐goals  to  the  graph.  Make  sure  the  links  indicate  “or”  rather  than  “and”.  

90  

Advise  user:  investment  should  be  X  

X  is  stocks  X  is  savings   X  is  mixture  

91  

•  Steps  3a,  3b  and  3c:  decide  what  sub-­‐goals  each  of  the  goals  at  the  bopom  of  the  graph  can  be  split  into.  –  It’s  only  true  that  “X  is  savings”  if  “savings  are  inadequate”.  That  provides  a  subgoal  under  “X  is  savings”  

–  It’s  only  true  that  “X  is  stocks”  if  “savings  are  adequate”  and  “income  is  adequate.  That  provides  two  subgoals  under  “X  is  stocks”  joined  by  “and”  links.  

–  Similarly,  there  are  two  subgoals  under  “X  is  mixture”  joined  by  “and”  links.  

   

92  

Advise  user:  investment  should  be  X  

X  is  stocks  X  is  savings   X  is  mixture  

Savings  are  inadequate  

Savings  are  adequate  

Income  is  adequate  

Savings  are  adequate  

Income      is  inadequate  

93  

•  The  next  steps  (4a,4b,4c,4d  &  4e)  mainly  involve  deciding  whether  something’s  big  enough.  – Step  4a:  savings  are  only  inadequate  if  they  are  smaller  than  a  certain  figure  (let’s  call  it  Y).  

– Step  4b:  savings  are  only  adequate  if  they  are  bigger  than  this  figure  (Y).  

– Step  4c:  income  is  only  adequate  if  it  is  bigger  than  a  certain  figure  (let’s  call  it  W),  and  also  steady.    

– Step  4d  is  the  same  as  4b.  Step  4e  is  like  4c,  but  “inadequate”,  “smaller”  and  “not  steady”.  

94  

Advise  user:  investment  should  be  X  

X  is  stocks  X  is  savings   X  is  mixture  

Savings  are  inadequate  

Savings  are  adequate  

Income  is  adequate  

Savings  are  adequate  

Income      is  inadequate  

Amount  saved      <  Y   Amount  

saved  >  Y  Income  is    steady  

Income  is    not  steady  

Income  >  W  

Income  <  W  

95  

•  Now  we  need  a  box  in  which  the  value  of  Y  is  calculated:    

 

and  we  need  a  box  in  which  the  value  of  W  is  calculated:    

Y  is  Z  5mes  3000  

W  is  9000  plus  2500  5mes  Z   96  

•  Z  is  the  number  of  dependants,  so  we  need  a  box  in  which  this  value  is  obtained:    

 

•  We  can  now  add  these  last  three  boxes  into  the  bopom  layers  of  the  graph  in  the  same  way  as  we’ve  added  all  the  others:  

Client  has  Z  dependants    

97  

98  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  Pieces  of  evidence  describing  the  current  state  of  affairs  appear  in  the  bopom  layer  of  the  graph.    

•  In  some  cases,  these  are  statements  that  may  or  may  not  be  true,  depending  on  the  features  of  the  case  currently  under  considera5on.  

99  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  In  the  next  layer  up,  there  are  simple  opera5ons  such  as  calcula5ons  and  comparisons.    

•  The  lines  indicate  which  pieces  of  evidence  act  is  inputs  to  these  opera5ons.  

100  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  In  the  upper  layers,  there  are  conclusions  that  can  be  drawn,  if  the  pieces  of  evidence  (and  the  results  of  the  simple  opera5ons)  feeding  into  them  (from  below)  are  true.    

•  Above  them,  there  are  further  conclusions  that  can  be  drawn  if  the  conclusions  feeding  into  them  are  true.  

101  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  At  the  top,  we  have  the  final  conclusion  of  the  reasoning  process.  

•  The  variables  W,  Y  and  Z  allow  this  graph  to  represent  both  numerical  and  logical  reasoning.  The  variable  X  allows  it  to  deliver  more  than  one  possible  conclusion.  

102  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  Students  oOen  seem  to  mix  up  this  sort  of  chart  with  a  flow-­‐chart.  It  isn’t  the  same  thing  at  all.    • A  flow-­‐chart  shows  the  sequence  of  opera5ons  that  a  program  must  go  through  (probably  with  some  branching)  to  execute  its  task.    

•  The  and-­‐or  graph  shows  the  pieces  of  evidence  that  must  be  present  if  a  certain  conclusion  is  to  be  reached.  

103  

Problem  decomposi5on  into  an  and-­‐or  graph  

• Why  draw  an  and-­‐or  chart?  •  Because  it  makes  the  point  that  a  decision-­‐making  process  like  this  can  be  broken  down  into  a  sequence  of  simple  decisions,  in  a  very  systema5c  way.  

•  Because  it’s  a  first  step  towards  turning  a  human  being’s  reasoning  into  a  collec5on  of  produc5on  rules.  

104  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  The  and-­‐or  chart  can  be  considered  as  a  backward-­‐chaining  produc5on  system,  reading  from  the  top  to  the  bopom.  Or  as  a  forward-­‐chaining  produc5on  system,  reading  from  the  bopom  to  the  top.  

105  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  Every  node  is  the  conclusion  of  a  produc5on  rule,  except  for  the  leaf  nodes  at  the  bopom,  which  are  requests  for  informa5on  from  the  user.    

• When  several  links  enter  a  node  from  below,  they  represent  the  condi5ons  for  that  produc5on  rule.  They  may  be  joined  by  "and"  connec5ves  or  by  "or"  connec5ves.  

• Alterna5vely,  if  several  links  (or  groups  of  links)  enter  a  node  from  below,  and  they  are  "or"  links  (or  groups  of  links  separated  by  "or"),  this  can  represent  several  different    produc5on  rules  which  all  have  the  same  conclusion.  

106  

Produc5on  rule:    if  savings  adequate  and  income  adequate  then  X  is  stocks  

107  

Produc5on  rule:    if    income  <  W  and  income  is  not  steady                    then  income  is                                inadequate  

108  

Produc5on  rule:    if  amount  saved  <  Y    then    savings    inadequate  

109  

Produc5on  rule:    if    X  is  savings  or  X  is  stocks  or  X  is  mixture  then  advise  user  investment  should  be  X  

110  

IMPLEMENTING  AN  AND-­‐OR  CHART  IN  PROLOG  

111  

112  

%  Top  level  goal  advise_user(X,  stocks)  :-­‐  

 stocks(X).  advise_user(X,  mixture)  :-­‐  

 mixture(X).  advise_user(X,  savings)  :-­‐  

 savings(X,  inadequate).    savings(X,  adequate)  :-­‐  

 saved(X,  Y),    required_savings(X,  Z),    Y  >  Z,  !.  

savings(_,  inadequate).    required_savings(X,  Z)  :-­‐  

 dependents(X,  Y),    Z  is  Y  *  3000.  

stocks(X)  :-­‐    savings(X,  adequate),    income(X,  adequate).  

 income(X,  adequate)  :-­‐  

 income_steady(X),    salary(X,  W),    required_income(X,  W1),    W  >  W1,  !.  

income(_,  inadequate).    required_income(X,  W)  :-­‐  

 dependents(X,  Z),    W  is  9000  +  2500  *  Z.  

 mixture(X)  :-­‐  

 savings(X,  adequate),    income(X,  inadequate).  

%  Facts  for  Fred.  salary(fred,  4000).  income_steady(fred).  saved(fred,  1000).  dependents(fred,  2).  

Require  facts  for  each  person  in  

order  to  have  the  expert  system  work;  however,  you  could  ask  ques5ons  to  achieve  this.  

Problem  decomposi5on  into  an  and-­‐or  graph  

•  The  underlying  principle  is  that  state  spaces  can  always  be  converted  into  produc5on  systems,  and  vice-­‐versa.    

•  Searching  a  large  produc5on  system  is  essen5ally  the  same  problem  as  searching  a  large  state-­‐space.  

113  

Summary  

•  Expert  Systems  encapsulate  knowledge  oOen  derived  from  human  experts  

•  Expert  system  =  inference  engine  +            knowledge  base  +  data  

 •  Two  main  modes  of  interference:  

– Forward  chaining  – Backward  chaining  

114