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)
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)