Sunum yükleniyor. Lütfen bekleyiniz

Sunum yükleniyor. Lütfen bekleyiniz

Prolog 5 M.Fatih Amasyalı Web :

Benzer bir sunumlar


... konulu sunumlar: "Prolog 5 M.Fatih Amasyalı Web :"— Sunum transkripti:

1 Prolog 5 M.Fatih Amasyalı Web :

2 Hangisi? go :- hypothesize(Animal), write('I guess that the animal is: '), write(Animal), nl, undo. hypothesize(cheetah) :- cheetah, !. hypothesize(tiger) :- tiger, !. hypothesize(giraffe) :- giraffe, !. hypothesize(zebra) :- zebra, !. hypothesize(ostrich) :- ostrich, !. hypothesize(penguin) :- penguin, !. hypothesize(albatross) :- albatross, !. hypothesize(unknown). Birini doğruladığı anda, Animal’in başka değerleri için doğruluk araması yapmasın diye

3 cheetah :- mammal, carnivore, verify(has_tawny_color), verify(has_dark_spots). tiger :- mammal, carnivore, verify(has_tawny_color), verify(has_black_stripes). giraffe :- ungulate, verify(has_long_neck), verify(has_long_legs). zebra :- ungulate, verify(has_black_stripes). ostrich :- bird, verify(does_not_fly), verify(has_long_neck). penguin :- bird, verify(does_not_fly), verify(swims), verify(is_black_and_white). albatross :- bird, verify(appears_in_story_Ancient_Mariner), verify(flys_well).

4 mammal :- verify(has_hair), !. mammal :- verify(gives_milk). bird :- verify(has_feathers), !. bird :- verify(flys), verify(lays_eggs). carnivore :- verify(eats_meat), !. carnivore :- verify(has_pointed_teeth), verify(has_claws), verify(has_forward_eyes). ungulate :- mammal, verify(has_hooves), !. ungulate :- mammal, verify(chews_cud). ask(Question) :- write('Does the animal have the following attribute: '), write(Question), write('? '), read(Response), nl, ( (Response == yes ; Response == y) -> assert(yes(Question)) ; assert(no(Question)), fail). /*assert yes döner, no(Q) ekleyip, verify’a no dönmesi için*/ :- dynamic yes/1,no/1. /* How to verify something */ verify(S) :- (yes(S) -> true ; % aynı soruyu önceden sorup cevabını yes olarak almışsa bir daha sormaz ve true döner (no(S) -> fail ; % cevabını no olarak almışsa bir daha sormaz ve false döner ask(S))). % aynı soruyu sormamışsa sorar /* undo all yes/no assertions */ undo :- retract(yes(_)),fail. /*undo yu yeniden denesin diye.*/ undo :- retract(no(_)),fail. /*undo yu yeniden denesin diye.*/ undo. Yeni sentaks: if P then Q else R ( P->Q ; R )

5 Fatih Sarı’ya teşekkürler

6 Evde su var? Kitchen Bathroom Hall Kitchen_dry Hall_wet Bathroom_dry Window_closed No_rain No_water_from_outside Problem_in_kitchen Leak_in_bathroom Leak_in_kitchen Window ve veya

7 Sızıntı nerede? leak_in_bathroom :- hall_wet, kitchen_dry. problem_in_kitchen :- hall_wet, bathroom_dry. no_water_from_outside :- window_closed ; no_rain. leak_in_kitchen :- problem_in_kitchen, no_water_from_outside. hall_wet. bathroom_dry. window_closed. ?- leak_in_kitchen. Yes Geriye doğru çıkarım

8 Yeni Sentaks :- op(800, fx, if). :- op(700, xfx, then). :- op(300, xfy, or). :- op(200, xfy, and). is_true(P) :- fact(P). is_true(P) :- if Condition then P, is_true(Condition). is_true(P1 and P2) :- is_true(P1), is_true(P2). is_true(P1 or P2) :- is_true(P1) ; is_true(P2). ifhall_wet and kitchen_dry thenleak_in_bathroom. ifhall_wet and bathroom_dry thenproblem_in_kitchen. ifwindow_closed or no_rain thenno_water_from_outside. ifproblem_in_kitchen and no_water_from_outside thenleak_in_kitchen. fact(hall_wet). fact(bathroom_dry). fact(window_closed). ?- is_true(leak_in_kitchen). Yes Geriye doğru çıkarım Öncelikle ters orantılı

9 :- dynamic fact/1. forward :- new_derived_fact(P), write('Derived:'),write(P),nl, assert(fact(P)), forward ; write('No more facts.'). new_derived_fact(Conc) :- if Cond then Conc, not(fact(Conc)), composed_fact(Cond). composed_fact(Cond) :- fact(Cond). composed_fact(Cond1 and Cond2) :- composed_fact(Cond1), composed_fact(Cond2). composed_fact(Cond1 or Cond2) :- composed_fact(Cond1) ; composed_fact(Cond2). :- op(800, fx, if). :- op(700, xfx, then). :- op(300, xfy, or). :- op(200, xfy, and). ileriye doğru çıkarım Kitchen_dry Hall_wet Bathroom_dry Window_closed No_rain No_water_from_outside Problem_in_kitchen Leak_in_bathroom Leak_in_kitchen ?- forward. Derived:problem_in_kitchen Derived:no_water_from_outside Derived:leak_in_kitchen No more facts. Yes ?- forward. No more facts. ?- fact(X). X = hall_wet ; X = bathroom_dry ; X = window_closed ; X = problem_in_kitchen ; X = no_water_from_outside ; X = leak_in_kitchen ; No

10 olasılıklar if hall_wet and kitchen_dry then leak_in_bathroom:0.8. if hall_wet and bathroom_dry then problem_in_kitchen:0.9. ifwindow_closed or no_rain thenno_water_from_outside:0.98. ifproblem_in_kitchen and no_water_from_outside thenleak_in_kitchen:0.5. given(hall_wet,1). % Hall is wet given(bathroom_dry, 1). % Bathroom is dry given(kitchen_dry, 0). % Kitchen is not dry given(no_rain, 0.8). % Probably no rain, but not sure given(window_closed, 0). % Window not closed

11 olasılıklar certainty(P, Cert) :- given(P, Cert). certainty(Cond1 and Cond2, Cert) :- certainty(Cond1, Cert1), certainty(Cond2, Cert2), min(Cert1, Cert2, Cert). certainty(Cond1 or Cond2, Cert) :- certainty(Cond1, Cert1), certainty(Cond2, Cert2), max(Cert1, Cert2, Cert). certainty(P, Cert) :- if Cond then P : C1, certainty(Cond, C2), Cert is C1 * C2. if P1 then P2:X ise c(P2)=c(P1)*X c(P1 and P2)=min(c(P1),c(P2)) c(P1 or P2)=max(c(P1),c(P2)) max( X, Y, Max) :- X >= Y, !, Max = X ; Max = Y. min( X, Y, Min) :- X =< Y, !, Min = X ; Min = Y. :- op(800, fx, if). :- op(700, xfx, then). :- op(300, xfy, or). :- op(200, xfy, and).

12 ?- certainty(leak_in_kitchen,H). H = ; Kitchen_dry : 0 Hall_wet : 1 Bathroom_dry : 1 Window_closed : 0 No_rain: No_water_from_outside: 0.98 = : Problem_in_kitchen : 0.9 = 0.9 0: Leak_in_bathroom:0.8= Leak_in_kitchen 0.5 =0.392

13 GS vs. FB ifgs_nin_kalecisi_mondi thengs_nin_defans_saglam:0.8. ifgs_de_necati_oynuyor or gs_de_hakansukur_oynuyor then gs_nin_hucum_saglam:0.9. if fb_de_nobre_oynuyor thenfb_nin_defans_saglam:0.7. iffb_de_nobre_oynuyor and fb_de_alex_oynuyor thenfb_nin_hucum_saglam:0.9. ifgs_nin_defans_saglam and gs_nin_hucum_saglam thengs_yener:0.8. if fb_nin_defans_saglam and fb_nin_hucum_saglam thenfb_yener:0.9. given(gs_de_necati_oynuyor,1). given(fb_de_nobre_oynuyor,1). given(fb_de_alex_oynuyor,1). given(gs_de_hakansukur_oynuyor,0). given(gs_nin_kalecisi_mondi,1). certainty(P, Cert) :- given(P, Cert). certainty(Cond1 and Cond2, Cert) :- certainty(Cond1, Cert1), certainty(Cond2, Cert2), min(Cert1, Cert2, Cert). certainty(Cond1 or Cond2, Cert) :- certainty(Cond1, Cert1), certainty(Cond2, Cert2), max(Cert1, Cert2, Cert). certainty(P, Cert) :- if Cond then P : C1, certainty(Cond, C2), Cert is C1 * C2. Yukarıdaki Prolog programı consult edildikten sonra ?-certainty(fb_yener,H). sorusuna prolog “H = 0.63” şeklide cevap vermektedir. a) ?-certainty(fb_nin_defans_saglam,H). b) ?-certainty(gs_nin_hucum_saglam,H). c) ?-certainty(gs_yener,H). max( X, Y, Max) :- X >= Y, !, Max = X ; Max = Y. min( X, Y, Min) :- X =< Y, !, Min = X ; Min = Y. :- op(800, fx, if). :- op(700, xfx, then). :- op(300, xfy, or). :- op(200, xfy, and).

14 çözüm a. 0.7 b. 0.9 c ifgs_nin_kalecisi_mondi thengs_nin_defans_saglam:0.8. ifgs_de_necati_oynuyor or gs_de_hakansukur_oynuyor then gs_nin_hucum_saglam:0.9. ifgs_nin_defans_saglam and gs_nin_hucum_saglam thengs_yener:0.8. gs_nin_kalecisi_mondi  gs_nin_defans_saglam ( 0.8 ) gs_de_necati_oynuyor (1) gs_de_hakansukur_oynuyor (0) max(1,0)=1  gs_nin_hucum_saglam ( 1*0.9=0.9 ) gs_nin_defans_saglam and gs_nin_hucum_saglam (0.8 and 0.9) min (0.8,0.9)=0.8  gs_yener 0.8*0.8 = 0.64.

15 Semantik Ağlar’da Miras alma ust(somut,canli). ust(canli,memeli). ust(memeli,insan). ust(memeli,kedigiller). ust(insan,erkek). ust(insan,kadin). ust(kedigiller,evkedisi). ust(kedigiller,kaplan). ust(kedigiller,aslan). oz(somut,yerkaplar). oz(canli,urer). oz(memeli,sutverir). oz(insan,konusur). oz(kedigiller,kuyruguvar). ust2(X,Z) :- ust(X,Z). ust2(X,Z) :- ust(X,Y),ust2(Y,Z). oz2(N,X):-oz(N,X). oz2(N,X):-ust2(Y,N),oz(Y,X). Somut (yer kaplar) Canlı (ürer) Memeli (süt verir) İnsan (konuşur)Kedi (kuyruğu var) ErkekKadın Ev kedisiKaplanAslan ?- oz2(D,G). % diye sorsak üstten miras nasıl alınır mı?

16 Semantik Ağlar’da Miras alma D = erkek, G = urer ; D = erkek, G = yerkaplar ; D = kadin, G = konusur ; D = kadin, G = sutverir ; D = kadin, G = urer ; D = kadin, G = yerkaplar ; D = evkedisi, G = kuyruguvar ; D = evkedisi, G = sutverir ; D = evkedisi, G = urer ; ?- oz2(D,G). D = somut, G = yerkaplar ; D = canli, G = urer ; D = memeli, G = sutverir ; D = insan, G = konusur ; D = kedigiller, G = kuyruguvar ; D = canli, G = yerkaplar ; D = memeli, G = urer ; D = memeli, G = yerkaplar ; D = insan, G = sutverir ; D = insan, G = urer ; D = insan, G = yerkaplar ; D = kedigiller, G = sutverir ; D = kedigiller, G = urer ; D = kedigiller, G = yerkaplar ; D = erkek, G = konusur ; D = erkek, G = sutverir ; D = evkedisi, G = yerkaplar ; D = kaplan, G = kuyruguvar ; D = kaplan, G = sutverir ; D = kaplan, G = urer ; D = kaplan, G = yerkaplar ; D = aslan, G = kuyruguvar ; D = aslan, G = sutverir ; D = aslan, G = urer ; D = aslan, G = yerkaplar ; false.

17 Özet Uzman Sistem –Hangi Hayvan? Hipotez doğrulama –Sızıntı Nerede? Geriye / ileriye doğru çıkarım –Olasılıklar Semantik Ağlar’da Miras

18 Kaynaklar PROLOG Programming for Artificial Intelligence, Bratko, I., 3rd Edition, Addison-Wesley, prolog_tutorial/2_17.html CIS310/Programs/kr.txt


"Prolog 5 M.Fatih Amasyalı Web :" indir ppt

Benzer bir sunumlar


Google Reklamları