Menu

Decision Tree , Animal Form

Faraz
2020-10-05
2022-05-13
  • Faraz

    Faraz - 2020-10-05

    Hi there
    Having , I have come to know that in order to make a decision tree , it is best to represent knowlodge base in the form of facts and not to put them in static rules (as is done in the animal.clp example in clips 6.4) . However I do not seem to understand how the file "animal.clp" actually works , as the flow of information makes it hard to watch all the activations and ...
    could somebody please walk me through it ?
    I would also like to thank Mr.Riley for his efforts don the project
    The file is attached

     
    • Gary Riley

      Gary Riley - 2020-10-07

      Attached is a shortened version of the CLIPS 6.4 program that is easier to step through.

      CLIPS> (load shortanimal.clp)
      +++:!%%%%%%%*********$
      TRUE
      CLIPS> (reset)
      CLIPS> (run)
      Does your animal have a backbone? (yes no) yes
      I think your animal is a cow.
      CLIPS> (reset)
      CLIPS> (run)
      Does your animal have a backbone? (yes no) no
      I think your animal is a snail.
      CLIPS> (reset)
      CLIPS> (facts)
      f-1     (goal (variable type.animal))
      f-2     (legalanswers (values yes no))
      f-3     (rule (name rule-1) (validate no) (if backbone is yes) (then superphylum is backbone) (processed))
      f-4     (rule (name rule-2) (validate no) (if backbone is no) (then superphylum is jellyback) (processed))
      f-5     (question (valid-answers) (variable backbone) (query "Does your animal have a backbone?"))
      f-6     (rule (name rule-3) (validate no) (if superphylum is backbone) (then type.animal is cow) (processed))
      f-7     (rule (name rule-4) (validate no) (if superphylum is jellyback) (then type.animal is snail) (processed))
      f-8     (answer (variable type.animal) (prefix "I think your animal is a ") (postfix "."))
      For a total of 8 facts.
      CLIPS> (agenda)
      0      startup: *
      For a total of 1 activation.
      CLIPS> (watch rules)
      CLIPS> (watch facts)
      CLIPS> (watch activations)
      CLIPS> (watch focus)
      CLIPS> (run)
      FIRE    1 startup: *
      ==> Focus ASK from MAIN
      ==> Focus CHAIN from ASK
      FIRE    2 propagate-goal: f-1,f-7
      ==> f-9     (goal (variable superphylum))
      ==> Activation 0      propagate-goal: f-9,f-3
      ==> Activation 0      propagate-goal: f-9,f-4
      FIRE    3 propagate-goal: f-9,f-4
      ==> f-10    (goal (variable backbone))
      ==> Activation 0      ask-question-legalvalues: f-2,f-10,f-5,*
      FIRE    4 propagate-goal: f-9,f-3
      FIRE    5 propagate-goal: f-1,f-6
      <== Focus CHAIN to ASK
      FIRE    6 ask-question-legalvalues: f-2,f-10,f-5,*
      ==> f-11    (activity)
      ==> Activation -10    continue: f-11
      <== f-10    (goal (variable backbone))
      Does your animal have a backbone? (yes no) yes
      ==> f-12    (variable (name backbone) (value yes))
      ==> Activation 0      rule-satisfied-is: f-12,f-3
      <== Focus ASK to MAIN
      FIRE    7 continue: f-11
      <== f-11    (activity)
      ==> Focus ASK from MAIN
      ==> Focus CHAIN from ASK
      FIRE    8 rule-satisfied-is: f-12,f-3
      <== f-3     (rule ... (if backbone is yes) ... (processed))
      ==> f-3     (rule ... (if) ... (processed backbone is yes #))
      ==> Activation 0      apply-rule: f-3
      FIRE    9 apply-rule: f-3
      ==> f-13    (variable (name superphylum) (value backbone))
      ==> Activation 0      rule-satisfied-is: f-13,f-6
      FIRE   10 rule-satisfied-is: f-13,f-6
      <== f-6     (rule ... (if superphylum is backbone) ... (processed))
      ==> f-6     (rule ... (if) ... (processed superphylum is backbone #))
      ==> Activation 0      apply-rule: f-6
      FIRE   11 apply-rule: f-6
      ==> f-14    (variable (name type.animal) (value cow))
      ==> Activation 0      goal-satified: f-1,f-14,f-8
      <== Focus CHAIN to ASK
      <== Focus ASK to MAIN
      FIRE   12 goal-satified: f-1,f-14,f-8
      I think your animal is a cow.
      <== Focus MAIN
      CLIPS> 
      
      1. The startup rule focus on the CHAIN module (which generates goals) and the ASK module (which asks questions to satisfy goals).
      2. The propagate-goal rule determines that the superphylum value is needed to determine the type.animal value so a goal is generated.
      3. The propagate-goal rule determines that the backbone value is needed to determine the superphylum value so a goal is generated.
      4. The propagate-goal rule determines that the backbone value is needed to determine the superphylum value, but no goal is generated because one already exists.
      5. The propagate-goal rule determines that the superphylum value is needed to determine the type.animal value, but no goal is generated because one already exists.
      6. The ask-question-legalvalues rule asks a question to determine the backbone value.
      7. The continue rules focuses on the CHAIN and ASK modules since new information is available.
      8. The rule-satisfied-is rule removes the "backbone is yes" condition from rules requiring that condition.
      9. The apply-rule rule applies the actions of the rule with the "backbone is yes" condition since it is now satisfied and the superphylum value is set to backbone.
      10. The rule-satisfied-is rule removes the "superphylum is backbone" condition from rules requiring that condition.
      11. The apply-rule rule applies the actions of the rule with the "superphylum is backbone" condition since it is now satisfied and the type.animal value is set to cow.
      12. The goal-satisfied rule fires since the value for type.animal has been determined and that is the value specified by the answer fact. A message is printed specifying the determined value.
       
  • Faraz

    Faraz - 2020-10-16

    Thanks a lot for your explanation
    YOU ARE A LEGEND :D

     

Log in to post a comment.