1 Knowledge Based Systems (CM0377) Lecture 11 (Last modified 26th March 2001)

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
(Fuzzy Set Operations)
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Copyright © Cengage Learning. All rights reserved.
Bellwork If you roll a die, what is the probability that you roll a 2 or an odd number? P(2 or odd) 2. Is this an example of mutually exclusive, overlapping,
Artificial Intelligence: Natural Language and Prolog
Inference in First-Order Logic
Introductory Mathematics & Statistics for Business
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
ZMQS ZMQS
Richmond House, Liverpool (1) 26 th January 2004.
Randomized Algorithms Randomized Algorithms CS648 1.
ABC Technology Project
TV Show Trivia Princeton Puzzle Hunt Do NOT flip over your answer sheet!
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
© S Haughton more than 3?
Quadratic Inequalities
Twenty Questions Subject: Twenty Questions
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
1 Declarative Programming Motivation Warm Fuzzies What is Logic?... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses,
1 Logic Programming Technical Foundation Second part of Cmput325 Fall 2004 R Greiner + B Price.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Modelling uncertainty in 3APL Johan Kwisthout Master Thesis
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using.
1 Using one or more of your senses to gather information.
Test B, 100 Subtraction Facts
U2 L5 Quotient Rule QUOTIENT RULE
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
We will resume in: 25 Minutes.
Less Than Matching Orgad Keller.
1 Unit 1 Kinematics Chapter 1 Day
Testing Hypotheses About Proportions
Introduction to Recursion and Recursive Algorithms
MA 1165: Special Assignment Completing the Square.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
EXPERT SYSTEMS AND KNOWLEDGE REPRESENTATION Ivan Bratko Faculty of Computer and Info. Sc. University of Ljubljana.
1 Inferences with Uncertainty Decision Support Systems and Intelligent Systems, Efraim Turban and Jay E. Aronson Copyright 1998, Prentice Hall, Upper Saddle.
Rulebase Expert System and Uncertainty. Rule-based ES Rules as a knowledge representation technique Type of rules :- relation, recommendation, directive,
1 DCP 1172 Introduction to Artificial Intelligence Chang-Sheng Chen Topics Covered: Introduction to Nonmonotonic Logic.
Inferences The Reasoning Power of Expert Systems.
B. Ross Cosc 4f79 1 Forward chaining backward chaining systems: take high-level goal, and prove it by reducing it to a null goal - to reduce it to null,
Artificial Intelligence Lecture No. 16
Chapter 12: Expert Systems Design Examples
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
INTELLIGENT SYSTEMS Rule based systems 1. Aims of session To understand  Basic principles  Forward chaining  Problems with rule-based systems  Backward.
COM362 Knowledge Engineering Inferencing 1 Inferencing: Forward and Backward Chaining John MacIntyre
Knowledge Based Information System
Artificial Intelligence: Applications
Intelligent Systems Rule based systems 1. Aims of session To understand Basic principles Forward chaining Problems with rule-based systems Backward chaining.
CHAPTER 5 Handling Uncertainty BIC 3337 EXPERT SYSTEM.
Presentation transcript:

1 Knowledge Based Systems (CM0377) Lecture 11 (Last modified 26th March 2001)

2 Implementation of expert systems In this lecture we shall see: –a simple backward-chaining interpreter –a simple way of handling uncertainty (using certainty factors) –a simple forward-chaining interpreter

3 A simple backward chaining interpreter (Simpl.pl) This one is so simple it doesn’t even remember the answers to the questions it asks you! Based around rules of the form: if_then([ ], ) Where there is an implicit and between the conditions. E.g. if_then(['it is mammal','it is tawny', 'it is carnivore','it has black stripes'], 'it is a tiger').

4 Example session Remember to use load_files with compilation_mode(assert_all). | ?- run. Select a knowledge base...'Simpl2'. {consulting e:/lect99~1/kbs/lect11~1/simpl2.pl...} The procedure if_then/2 is being redefined. Old file: e:/lect99~1/kbs/lect11~1/simpl1.pl New file: e:/lect99~1/kbs/lect11~1/simpl2.pl Do you really want to redefine it? (y, n, p, or ?) y {e:/lect99~1/kbs/lect11~1/simpl2.pl consulted, 10 msec 720 bytes} Note that I had previously used simpl1.pl.

5 Example session (ctd.) Type in a goal...'it is a tiger'. Is it true that it has hair? |: no. Is it true that it gives milk? |: yes. Is it true that it is tawny? |: yes. Is it true that it is carnivore? |: yes. Is it true that it has black stripes? |: yes. Proved! yes | ?-

6 The program... The run predicate simply clears everything from previous runs, determines file of Prolog if_then facts to consult, consults it and then tries to prove the user-specified hypothesis: run:- retractall(if_then(_,_)), write('Select a knowledge base...'), read(KB), load_files([KB], [compilation_mode(assert_all)]), write('Type in a goal...'), read(Goal), prove(Goal), write('Proved!'), nl, !. run:- write('Not proved!'), nl.

7 Proving... It’s true if either you can find an if-then rule, and all the conditions are satisfied, or the result of asking about it is ‘yes’. prove(Fact):- if_then(Conditions,Fact), infer_each(Conditions). prove(Fact):- ask(Fact). And all conditions are satisfied if the first one is and all the others are: infer_each([]). infer_each([Fact|Rest]):- prove(Fact), infer_each(Rest).

8 Asking... This predicate succeeds only if the user types ‘yes.’: ask(Fact):- write('Is it true that '), write(Fact), write('?'), nl, read(Ans), Ans=yes.

9 Uncertainty There are various ways of handling uncertainty, including: –textually –using Bayesian inference (based on the idea of conditional probabilities) –using certainty factors We’ll only look at certainty factors

10 Combining uncertain knowledge We can assign a certainty factor between 0 and 1 to each of the pieces of knowledge supplied to the system, and assume that: –cf(a and b) = min(cf(a), cf(b)) –cf(a or b) = max(cf(a), cf(b)) –cf(not a) = 1 - cf(a) Note that only the cf for ‘not’ is actually probabilistically sound. This is a limited application of ‘fuzzy logic’

11 Example session with the new program (cf.pl) | ?- run. Select a knowledge base...'Simpl2'. {consulting e:/lect99~1/kbs/lect11~1/simpl2.pl...} {e:/lect99~1/kbs/lect11~1/simpl2.pl consulted, 0 msec 368 bytes} Type in a goal...'it is a tiger'. Please give certainty for it has hair... |: 0.3. Please give certainty for it is tawny... |: 0.5. Please give certainty for it is carnivore... |: 0.2. Please give certainty for it has black stripes... |: 0.7. Certainty is 0.2 yes | ?-

12 The revised program... Now we always obtain a certainty, so only one run clause: run:- retractall(if_then(_,_)), write('Select a knowledge base...'), read(KB), load_files([KB], [compilation_mode(assert_all)]), write('Type in a goal...'), read(Goal), prove(Goal, Cert), write('Certainty is '), write(Cert), nl, !.

13 Proving... Needs an auxiliary min clause... prove(Fact, Cert):- if_then(Conditions,Fact), infer_each(Conditions, Cert). prove(Fact, Cert):- ask(Fact, Cert). infer_each([], 1). infer_each([Fact|Rest], Cert):- prove(Fact, C1), infer_each(Rest, C2), min(C1, C2, Cert). min(X, Y, X):- X < Y, !. min(X, Y, Y).

14 Asking... Ask for a certainty value, not for whether something is true or false: ask(Fact, Cert):- write('Please give certainty for '), write(Fact), write('...'), nl, read(Cert).

15 A forward chaining system (fwd.pl) The scenario: want to do a variation on bubble sort on a list of numbers. The rules in English: –If X is to the left of something that is to the left of Y and X > Y then swap them –If X is to the left of Y and X > Y then swap them –If there isn’t any X to the left of any Y where X > Y then stop We always try the rules in the order they are given. E.g. | ?- go. Initial state: [5,3,2,4,1] Swap performed: [2,3,5,4,1] Swap performed: [2,3,1,4,5] Swap performed: [1,3,2,4,5] Swap performed: [1,2,3,4,5] yes | ?-

16 Rules Rules of the following form, where any antecedent/consequent goals can be specified: rule(,, ) So for our example: rule(1,[left_of(A,B),left_of(B,C), bigger_than(A,C)], swap(A,C)). rule(2,[left_of(A,B),bigger_than(A,B)], swap(A,B)). rule(3,[no_left_of_and_bigger],stop). Rely on a current_list fact: go:- retractall(current_list(_)), retractall(stopped), assert(current_list([5,3,2,4,1])), current_list(X), write('Initial state: '), write(X), nl, run_rules.

17 Recognise-act procedure If still running, get list of rules that could fire (CList), choose rule, fire it, repeat: run_rules:- \+(stopped),!, conflict_set(CList), choose_rule(CList,Rule), fire_rule(Rule), run_rules.

18 Determining conflict set Conflict set is all rules belonging to the conflict set: conflict_set(CList):- findall(R, belongs_to_c_set(R), CList). Those which belong to the conflict set are those whose condition is satisfied: belongs_to_c_set(rule(N, Cond, Act)):- rule(N, Cond, Act), satisfy(Cond). Conditions satisfied if each is satisfied individually: satisfy(Conditions):- satisfy_each(Conditions),!. satisfy_each([]). satisfy_each([H|T]):- call(H), satisfy_each(T).

19 Choosing and firing The world’s simplest conflict resolver! choose_rule([R|Ignore], R). Fire a rule by calling: fire_rule(rule(N, Cond, Act)):- call(Act),!.

20 Predicates used in rules (The predicates can be anything) left_of(A,B):- current_list(L), split(L,A,[B|_]). split([H|T],H,T). split([H|T],A,List):- split(T,A,List). bigger_than(A,B):- A>B. no_left_of_and_bigger:- \+(some_left_of_and_bigger). some_left_of_and_bigger:- left_of(A,B), bigger_than(A,B).

21 Predicates used in rules (ctd.) swap(A,B):- retract(current_list(L)), list_with_swap(L,A,B,New), assert(current_list(New)), write('Swap performed: '), write(New),nl. stop:- assert(stopped). list_with_swap([],_,_,[]). list_with_swap([A|T],A,B,[B|T1]):- list_with_swap(T,A,B,T1). list_with_swap([B|T],A,B,[A|T1]):- list_with_swap(T,A,B,T1). list_with_swap([H|T],A,B,[H|T1]):- \+(H=A),\+(H=B), list_with_swap(T,A,B,T1).