SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Shell                                   RETE                        Postscriptum




           Sztuczna Inteligencja i Systemy Ekspertowe
                    Systemy ekspertowe (2)

                                 Aleksander Pohl
                          http://apohllo.pl/dydaktyka/ai

                         Wy˙ sza Szkoła Zarzadzania i Bankowo´ ci
                           z                 ˛               s


                                    12 maja 2009



Aleksander Pohl                                                          WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Plan prezentacji



        Shell


        RETE


        Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Plan prezentacji



        Shell


        RETE


        Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                                  RETE         Postscriptum




Shell ekspertowy




          ◮   Formalizm reprezentacji wiedzy
          ◮   Opracowanie mechanizmu wnioskowania
          ◮   Interfejs u˙ ytkownika
                         z




Aleksander Pohl                                          WSZiB
Systemy ekspertowe (2)
Shell                          RETE             Postscriptum




Reguły

          ◮   :- op(100, xfx, [has, gives,
              ’does not’, eats, lays, isa]).
          ◮   :- op(100, xf, [swims, flies]).
          ◮   rule1 :: if
              Animal has hair
              or
              Animal gives milk
              then
              Animal isa mammal.



Aleksander Pohl                                      WSZiB
Systemy ekspertowe (2)
Shell                          RETE   Postscriptum




Reguły 2


          ◮   rule2 :: if
              Animal has feathers
              or
              Animal flies and
              Animal lays eggs
              then
              Animal isa bird.




Aleksander Pohl                            WSZiB
Systemy ekspertowe (2)
Shell                          RETE                  Postscriptum




Reguły 3


          ◮   rule3 :: if
              Animal isa mammal and
              ( Animal eats meat
              or
              Animal has ’pointed teeth’ and
              Animal has claws and
              Animal has ’forward pointing eyes’ )
              then
              Animal isa carnivore.




Aleksander Pohl                                           WSZiB
Systemy ekspertowe (2)
Shell                          RETE          Postscriptum




Reguły 4
          ◮   rule4 :: if
              Animal isa carnivore and
              Animal has ’tawny color’ and
              Animal has ’dark spots’
              then
              Animal isa cheetah.
          ◮   rule5 :: if
              Animal isa carnivore and
              Animal has ’tawny color’ and
              Animal has ’black stripes’
              then
              Animal isa tiger.

Aleksander Pohl                                   WSZiB
Systemy ekspertowe (2)
Shell                          RETE       Postscriptum




Reguły 5

          ◮   rule6 :: if
              Animal isa bird and
              Animal ’does not’ fly and
              Animal swims
              then
              Animal isa penguin.
          ◮   rule7 :: if
              Animal isa bird and
              Animal isa ’good flyer’
              then
              Animal isa albatross.


Aleksander Pohl                                WSZiB
Systemy ekspertowe (2)
Shell                          RETE                    Postscriptum




Reguły 6
          ◮   fact :: X isa animal :-
              member( X, [cheetah, tiger, penguin,
              albatross]).
          ◮   askable( _ gives _, ’Animal’ gives ’What’).
          ◮   askable( _ flies, ’Animal’ flies).
          ◮   askable( _ lays eggs, ’Animal’ lays eggs).
          ◮   askable( _ eats _, ’Animal’ eats ’What’).
          ◮   askable( _ has _, ’Animal’ has
              ’Something’).
          ◮   askable( _ ’does not’ _, ’Animal’ ’does
              not’ fly).
          ◮   askable( _ swims, ’Animal’ swims).
          ◮   askable( _ isa ’good flyer’, ’Animal’ isa
              ’good flyer’).
Aleksander Pohl                                             WSZiB
Systemy ekspertowe (2)
Shell                                 RETE                                Postscriptum




Zasady działania

          ◮   Q jest faktem – to odpowiada ’Q is true’
          ◮   Dla reguły ’if Condition then Q’ badaj Condition i zbuduj
              odpowied´ z
          ◮   Je´ li Q jest „askable” zapytaj o to u˙ ytkownika
                s                                   z
          ◮   Je´ li Q jest postaci ’Q1 and Q2’ badaj Q1, dla fałszywego
                 s
              odpowied´ jest ’Q is false’, w przeciwnym razie zbadaj Q2
                         z
              i zbuduj odpowiednio odpowied´   z
          ◮   Je´ li Q jest postaci ’Q1 or Q2’ badaj Q1 oraz zbadaj Q2
                 s
              i zbuduj odpowiednio odpowied´    z



Aleksander Pohl                                                                WSZiB
Systemy ekspertowe (2)
Shell                                  RETE          Postscriptum




Dialog (1)

          ◮   Question please:
          ◮   peter isa tiger
          ◮   Is it true: peter has hair?
          ◮   yes
          ◮   Is it true: peter eats meat?
          ◮   no
          ◮   Is it true: peter has pointed teeth?
          ◮   yes



Aleksander Pohl                                           WSZiB
Systemy ekspertowe (2)
Shell                                  RETE                  Postscriptum




Dialog (2)
          ◮   Is it true: peter has claws ?
          ◮   why
          ◮   To investigate by rule3, peter isa carnivore
              To investigate by rule5, peter isa tiger
              This was your question
          ◮   Is it true: peter has claws ?
          ◮   yes
          ◮   Is it true: peter has black stripes ?
          ◮   yes
          ◮   Is it true: peter has tawny colour ?
          ◮   yes

Aleksander Pohl                                                   WSZiB
Systemy ekspertowe (2)
Shell                                      RETE               Postscriptum




Dialog (3)
          ◮   (peter isa tiger) is true.
          ◮   Would you like to see how ?
          ◮   yes
          ◮   Peter isa tiger
              Was derived by rule5 from Peter isa carnivore
              And
          ◮   Peter has tawny colour
              Was told
              And
          ◮   Peter has black stripes
              Was told.

Aleksander Pohl                                                    WSZiB
Systemy ekspertowe (2)
Shell                                   RETE    Postscriptum




Dialog (4)
          ◮   Peter isa carnivore
              Was derived by rule3 from
          ◮   Peter isa mammal
              And
          ◮   Peter has pointed teeth
              Was told
              And
          ◮   Peter has claws
              Was told
              And
          ◮   Peter has forward pointing eyes
              Was told.

Aleksander Pohl                                      WSZiB
Systemy ekspertowe (2)
Shell                               RETE   Postscriptum




Dialog (5)



          ◮   Peter isa mammal
              Was derived by rule1 from
              Peter has hair
              Was told.




Aleksander Pohl                                 WSZiB
Systemy ekspertowe (2)
Shell                               RETE                            Postscriptum




Predykaty składowe shella


          ◮   expert – uruchami shell
          ◮   explore(Goal, Trace, Answer)
              Goal – pytanie
              Trace – lista celów od pytania głównego do obecnego
              Answer – drzewo dowodu
          ◮   useranswer(Goal, Trace, Answer) – obsługuje
              dialog z u˙ ytkownikiem
                        z
          ◮   present(Answer) – odpowiada na pytanie „How”




Aleksander Pohl                                                          WSZiB
Systemy ekspertowe (2)
Shell                          RETE                       Postscriptum




Przeszukiwanie

          ◮   explore(Goal, Trace, Answer)
          ◮   Goal
              (X has feathers) or (X flies) and (X lays
              eggs)
          ◮   Trace (drzewa przodków)
              [(peter isa carnivore) by rule3, (peter isa
              tiger) by rule5]
          ◮   Answer (drzewo dowodu potomka)
              (peter eats meat) is false was told



Aleksander Pohl                                                WSZiB
Systemy ekspertowe (2)
Shell                          RETE                    Postscriptum




Implementacja explore (1)
          ◮   explore( Goal, Trace, _) :-
              copy_term( Goal, Copy),
              member( Copy by Rule, Trace),
              instance_of( Copy, Goal), !, fail.
          ◮   explore(Goal, Trace,
              Goal is true was ’found as a fact’) :-
              fact :: Goal.
          ◮   explore(Goal, Trace, Goal is TruthValue
              was ’derived by’ Rule from Answer) :-
              Rule :: if Condition then Goal,
              explore(Condition, [Goal by Rule | Trace],
              Answer),
              truth(Answer, TruthValue).
Aleksander Pohl                                             WSZiB
Systemy ekspertowe (2)
Shell                          RETE                    Postscriptum




Implementacja explore (2)


          ◮   explore(Goal1 and Goal2, Trace, Answer) :-
              !,
              explore(Goal1, Trace, Answer1),
              continue(Answer1, Goal1 and Goal2, Trace,
              Answer).
          ◮   explore( Goal1 or Goal2, Trace, Answer) :-
              exploreyes(Goal1, Trace, Answer);
              exploreyes(Goal2, Trace, Answer).




Aleksander Pohl                                             WSZiB
Systemy ekspertowe (2)
Shell                          RETE                     Postscriptum




Implementacja explore (3)
          ◮   explore(Goal1 or Goal2, Trace, Answer1 and
              Answer2) :- !,
              not exploreyes(Goal1, Trace, _),
              not exploreyes(Goal2, Trace, _),
              explore(Goal1, Trace, Answer1),
              explore(Goal2, Trace, Answer2).
          ◮   explore(Goal, Trace, Goal is Answer was
              told) :-
              useranswer(Goal, Trace, Answer).
          ◮   exploreyes(Goal, Trace, Answer) :-
              explore(Goal, Trace, Answer),
              positive(Answer).

Aleksander Pohl                                              WSZiB
Systemy ekspertowe (2)
Shell                          RETE             Postscriptum




Implementacja


          ◮   instance_of(Term, Term1) :-
              copy_term(Term1, Term2),
              numbervars(Term2, 0, _), !,
              Term = Term2.
          ◮   numbervars( Term, N, Nplus1) :-
              var( Term), !, Term = var/N,
              Nplus1 is N + 1.




Aleksander Pohl                                      WSZiB
Systemy ekspertowe (2)
Shell                          RETE           Postscriptum




Implementacja cd.


          ◮   numbervars( Term, N, M) :-
              Term =.. [Functor | Args],
              numberargs( Args, N, M).
          ◮   numberargs( [], N, N) :- !.
          ◮   numberargs( [X | L], N, M) :-
              numbervars( X, N, N1),
              numberargs( L, N1, M).




Aleksander Pohl                                    WSZiB
Systemy ekspertowe (2)
Shell                          RETE                      Postscriptum




Implementacja cd.

          ◮   truth( Question is TruthValue was Found,
              TruthValue) :- !.
          ◮   truth( Answer1 and Answer2, TruthValue) :-
              truth( Answer1, true), truth( Answer2,
              true), !,
              TruthValue = true ; TruthValue = false.
          ◮   positive( Answer) :-
              truth( Answer, true).
          ◮   negative( Answer) :-
              truth( Answer, false).


Aleksander Pohl                                               WSZiB
Systemy ekspertowe (2)
Shell                           RETE                Postscriptum




Pobieranie odpowiedzi
          ◮   getreply(R) :-
              read(Answer),
              means(Answer, Reply), !;
              nl, write(’Answer Unknown’),nl,
              getreply( Reply).
          ◮   means(yes,yes).
          ◮   means(y,yes).
          ◮   ...
          ◮   getreply(Replay),
              (Reply = yes, interpretyes(...)   ;
              Reply = no, interpretno(...) ;
              ...)

Aleksander Pohl                                          WSZiB
Systemy ekspertowe (2)
Shell                                RETE               Postscriptum




Interpretacja odpowiedzi

          ◮   askable( X eats Y, ’Animal’ eats
              ’Something’).
          ◮   ?- useranswer( X eats Y , [] , Answer).
          ◮   Is it true: Animal eats Something?
          ◮   yes.
              Animal = peter
              Something = meat
              Answer = true
              X = peter
              Y = meat


Aleksander Pohl                                              WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Plan prezentacji



        Shell


        RETE


        Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                                    RETE                         Postscriptum




RETE

          ◮   Algorytm pattern-matching rozumowania wprzód
          ◮   C.L. Forgy z Carnegi Mellon w 1979
          ◮   Optymalizacja rozpatyrwania LHS (left-hand side) oraz
              RHS (right-hand side)
          ◮      z    s´
              Zło˙ ono´ c:
                  ◮          s´
                      R – ilo´ c reguł
                  ◮          s´
                      F – ilo´ c faktów
                  ◮          s´          ´
                      P – ilo´ c dopasowan
              naiwna implementacja: O(R ∗ F P )
              RETE: O(R ∗ F ∗ P)



Aleksander Pohl                                                            WSZiB
Systemy ekspertowe (2)
Shell                                 RETE                                Postscriptum




Pojecia
   ˛



          ◮   Kompilacja lewych stron LHS => RHS (if .. then)
          ◮   Zamieniamy reguły na zestawy wezłów z jednym wej´ ciem
                                               ˛              s
              (filtry) i wezłów z dwoma wej´ ciami (złaczenia)
                         ˛                s           ˛
          ◮   Filtry sprawdzaja czy dany fakt pasuje do elementu LHS
                               ˛
          ◮   Złaczenia zapamietuja fakty, które je cz˛ sciowo spełniły
                 ˛            ˛                       e´




Aleksander Pohl                                                                WSZiB
Systemy ekspertowe (2)
Shell                                RETE   Postscriptum




Przykład



          ◮   if x, y, z then example-2
          ◮   if x, y then example-3
          ◮   LHS => RHS
          ◮   (x,y,z) => example-2
          ◮   (x,y) => example-3




Aleksander Pohl                                  WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                    RETE   Postscriptum




Plan prezentacji



        Shell


        RETE


        Postscriptum




Aleksander Pohl                      WSZiB
Systemy ekspertowe (2)
Shell                                RETE                          Postscriptum




Materiały zródłowe
          ´



          ◮   L.Sterling, E.Shapiro - „The Art Of Prolog”
          ◮   Ivan Bratko - „Prolog – Programming For Artificial
              Intelligence”
          ◮   Slajdy zostały przygotowane za zgoda˛
              dr. Michała Korzyckiego na podstawie jego wykładu.




Aleksander Pohl                                                         WSZiB
Systemy ekspertowe (2)
Shell                      RETE      Postscriptum




                         Dziekuje!
                            ˛   ˛




Aleksander Pohl                           WSZiB
Systemy ekspertowe (2)

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Systemy ekspertowe 2

  • 1. Shell RETE Postscriptum Sztuczna Inteligencja i Systemy Ekspertowe Systemy ekspertowe (2) Aleksander Pohl http://apohllo.pl/dydaktyka/ai Wy˙ sza Szkoła Zarzadzania i Bankowo´ ci z ˛ s 12 maja 2009 Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 2. Shell RETE Postscriptum Plan prezentacji Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 3. Shell RETE Postscriptum Plan prezentacji Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 4. Shell RETE Postscriptum Shell ekspertowy ◮ Formalizm reprezentacji wiedzy ◮ Opracowanie mechanizmu wnioskowania ◮ Interfejs u˙ ytkownika z Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 5. Shell RETE Postscriptum Reguły ◮ :- op(100, xfx, [has, gives, ’does not’, eats, lays, isa]). ◮ :- op(100, xf, [swims, flies]). ◮ rule1 :: if Animal has hair or Animal gives milk then Animal isa mammal. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 6. Shell RETE Postscriptum Reguły 2 ◮ rule2 :: if Animal has feathers or Animal flies and Animal lays eggs then Animal isa bird. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 7. Shell RETE Postscriptum Reguły 3 ◮ rule3 :: if Animal isa mammal and ( Animal eats meat or Animal has ’pointed teeth’ and Animal has claws and Animal has ’forward pointing eyes’ ) then Animal isa carnivore. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 8. Shell RETE Postscriptum Reguły 4 ◮ rule4 :: if Animal isa carnivore and Animal has ’tawny color’ and Animal has ’dark spots’ then Animal isa cheetah. ◮ rule5 :: if Animal isa carnivore and Animal has ’tawny color’ and Animal has ’black stripes’ then Animal isa tiger. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 9. Shell RETE Postscriptum Reguły 5 ◮ rule6 :: if Animal isa bird and Animal ’does not’ fly and Animal swims then Animal isa penguin. ◮ rule7 :: if Animal isa bird and Animal isa ’good flyer’ then Animal isa albatross. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 10. Shell RETE Postscriptum Reguły 6 ◮ fact :: X isa animal :- member( X, [cheetah, tiger, penguin, albatross]). ◮ askable( _ gives _, ’Animal’ gives ’What’). ◮ askable( _ flies, ’Animal’ flies). ◮ askable( _ lays eggs, ’Animal’ lays eggs). ◮ askable( _ eats _, ’Animal’ eats ’What’). ◮ askable( _ has _, ’Animal’ has ’Something’). ◮ askable( _ ’does not’ _, ’Animal’ ’does not’ fly). ◮ askable( _ swims, ’Animal’ swims). ◮ askable( _ isa ’good flyer’, ’Animal’ isa ’good flyer’). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 11. Shell RETE Postscriptum Zasady działania ◮ Q jest faktem – to odpowiada ’Q is true’ ◮ Dla reguły ’if Condition then Q’ badaj Condition i zbuduj odpowied´ z ◮ Je´ li Q jest „askable” zapytaj o to u˙ ytkownika s z ◮ Je´ li Q jest postaci ’Q1 and Q2’ badaj Q1, dla fałszywego s odpowied´ jest ’Q is false’, w przeciwnym razie zbadaj Q2 z i zbuduj odpowiednio odpowied´ z ◮ Je´ li Q jest postaci ’Q1 or Q2’ badaj Q1 oraz zbadaj Q2 s i zbuduj odpowiednio odpowied´ z Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 12. Shell RETE Postscriptum Dialog (1) ◮ Question please: ◮ peter isa tiger ◮ Is it true: peter has hair? ◮ yes ◮ Is it true: peter eats meat? ◮ no ◮ Is it true: peter has pointed teeth? ◮ yes Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 13. Shell RETE Postscriptum Dialog (2) ◮ Is it true: peter has claws ? ◮ why ◮ To investigate by rule3, peter isa carnivore To investigate by rule5, peter isa tiger This was your question ◮ Is it true: peter has claws ? ◮ yes ◮ Is it true: peter has black stripes ? ◮ yes ◮ Is it true: peter has tawny colour ? ◮ yes Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 14. Shell RETE Postscriptum Dialog (3) ◮ (peter isa tiger) is true. ◮ Would you like to see how ? ◮ yes ◮ Peter isa tiger Was derived by rule5 from Peter isa carnivore And ◮ Peter has tawny colour Was told And ◮ Peter has black stripes Was told. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 15. Shell RETE Postscriptum Dialog (4) ◮ Peter isa carnivore Was derived by rule3 from ◮ Peter isa mammal And ◮ Peter has pointed teeth Was told And ◮ Peter has claws Was told And ◮ Peter has forward pointing eyes Was told. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 16. Shell RETE Postscriptum Dialog (5) ◮ Peter isa mammal Was derived by rule1 from Peter has hair Was told. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 17. Shell RETE Postscriptum Predykaty składowe shella ◮ expert – uruchami shell ◮ explore(Goal, Trace, Answer) Goal – pytanie Trace – lista celów od pytania głównego do obecnego Answer – drzewo dowodu ◮ useranswer(Goal, Trace, Answer) – obsługuje dialog z u˙ ytkownikiem z ◮ present(Answer) – odpowiada na pytanie „How” Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 18. Shell RETE Postscriptum Przeszukiwanie ◮ explore(Goal, Trace, Answer) ◮ Goal (X has feathers) or (X flies) and (X lays eggs) ◮ Trace (drzewa przodków) [(peter isa carnivore) by rule3, (peter isa tiger) by rule5] ◮ Answer (drzewo dowodu potomka) (peter eats meat) is false was told Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 19. Shell RETE Postscriptum Implementacja explore (1) ◮ explore( Goal, Trace, _) :- copy_term( Goal, Copy), member( Copy by Rule, Trace), instance_of( Copy, Goal), !, fail. ◮ explore(Goal, Trace, Goal is true was ’found as a fact’) :- fact :: Goal. ◮ explore(Goal, Trace, Goal is TruthValue was ’derived by’ Rule from Answer) :- Rule :: if Condition then Goal, explore(Condition, [Goal by Rule | Trace], Answer), truth(Answer, TruthValue). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 20. Shell RETE Postscriptum Implementacja explore (2) ◮ explore(Goal1 and Goal2, Trace, Answer) :- !, explore(Goal1, Trace, Answer1), continue(Answer1, Goal1 and Goal2, Trace, Answer). ◮ explore( Goal1 or Goal2, Trace, Answer) :- exploreyes(Goal1, Trace, Answer); exploreyes(Goal2, Trace, Answer). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 21. Shell RETE Postscriptum Implementacja explore (3) ◮ explore(Goal1 or Goal2, Trace, Answer1 and Answer2) :- !, not exploreyes(Goal1, Trace, _), not exploreyes(Goal2, Trace, _), explore(Goal1, Trace, Answer1), explore(Goal2, Trace, Answer2). ◮ explore(Goal, Trace, Goal is Answer was told) :- useranswer(Goal, Trace, Answer). ◮ exploreyes(Goal, Trace, Answer) :- explore(Goal, Trace, Answer), positive(Answer). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 22. Shell RETE Postscriptum Implementacja ◮ instance_of(Term, Term1) :- copy_term(Term1, Term2), numbervars(Term2, 0, _), !, Term = Term2. ◮ numbervars( Term, N, Nplus1) :- var( Term), !, Term = var/N, Nplus1 is N + 1. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 23. Shell RETE Postscriptum Implementacja cd. ◮ numbervars( Term, N, M) :- Term =.. [Functor | Args], numberargs( Args, N, M). ◮ numberargs( [], N, N) :- !. ◮ numberargs( [X | L], N, M) :- numbervars( X, N, N1), numberargs( L, N1, M). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 24. Shell RETE Postscriptum Implementacja cd. ◮ truth( Question is TruthValue was Found, TruthValue) :- !. ◮ truth( Answer1 and Answer2, TruthValue) :- truth( Answer1, true), truth( Answer2, true), !, TruthValue = true ; TruthValue = false. ◮ positive( Answer) :- truth( Answer, true). ◮ negative( Answer) :- truth( Answer, false). Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 25. Shell RETE Postscriptum Pobieranie odpowiedzi ◮ getreply(R) :- read(Answer), means(Answer, Reply), !; nl, write(’Answer Unknown’),nl, getreply( Reply). ◮ means(yes,yes). ◮ means(y,yes). ◮ ... ◮ getreply(Replay), (Reply = yes, interpretyes(...) ; Reply = no, interpretno(...) ; ...) Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 26. Shell RETE Postscriptum Interpretacja odpowiedzi ◮ askable( X eats Y, ’Animal’ eats ’Something’). ◮ ?- useranswer( X eats Y , [] , Answer). ◮ Is it true: Animal eats Something? ◮ yes. Animal = peter Something = meat Answer = true X = peter Y = meat Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 27. Shell RETE Postscriptum Plan prezentacji Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 28. Shell RETE Postscriptum RETE ◮ Algorytm pattern-matching rozumowania wprzód ◮ C.L. Forgy z Carnegi Mellon w 1979 ◮ Optymalizacja rozpatyrwania LHS (left-hand side) oraz RHS (right-hand side) ◮ z s´ Zło˙ ono´ c: ◮ s´ R – ilo´ c reguł ◮ s´ F – ilo´ c faktów ◮ s´ ´ P – ilo´ c dopasowan naiwna implementacja: O(R ∗ F P ) RETE: O(R ∗ F ∗ P) Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 29. Shell RETE Postscriptum Pojecia ˛ ◮ Kompilacja lewych stron LHS => RHS (if .. then) ◮ Zamieniamy reguły na zestawy wezłów z jednym wej´ ciem ˛ s (filtry) i wezłów z dwoma wej´ ciami (złaczenia) ˛ s ˛ ◮ Filtry sprawdzaja czy dany fakt pasuje do elementu LHS ˛ ◮ Złaczenia zapamietuja fakty, które je cz˛ sciowo spełniły ˛ ˛ e´ Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 30. Shell RETE Postscriptum Przykład ◮ if x, y, z then example-2 ◮ if x, y then example-3 ◮ LHS => RHS ◮ (x,y,z) => example-2 ◮ (x,y) => example-3 Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 31. Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 32. Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 33. Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 34. Shell RETE Postscriptum Plan prezentacji Shell RETE Postscriptum Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 35. Shell RETE Postscriptum Materiały zródłowe ´ ◮ L.Sterling, E.Shapiro - „The Art Of Prolog” ◮ Ivan Bratko - „Prolog – Programming For Artificial Intelligence” ◮ Slajdy zostały przygotowane za zgoda˛ dr. Michała Korzyckiego na podstawie jego wykładu. Aleksander Pohl WSZiB Systemy ekspertowe (2)
  • 36. Shell RETE Postscriptum Dziekuje! ˛ ˛ Aleksander Pohl WSZiB Systemy ekspertowe (2)