Download - ISAT 252 : Analytical Methods IV Knowledge-Based Systems (KBS) and Declarative Programming
1
ISAT 252: Analytical MethodsISAT 252: Analytical Methods IV IV
Knowledge-Based Systems (KBS)Knowledge-Based Systems (KBS)and and
Declarative Programming Declarative Programming
KBS development KBS development
and and
KBSDT DetailsKBSDT Details
Reading AssignmentReading Assignment: : Corvid Quick Start ManualCorvid Quick Start Manual
2
Outline
1. Lecture 1:Introduction to KBS and declarative programming
2. Lecture 2: Knowledge-based systems (KBS): definition and requirements
overview
3. Lecture 3: KBS development and programming detailsExamples
1. Snow board package2. Guitar selection
3. Auto audio system
3
Objectives Students should be able to:
Explain the steps involved in the EKBS development methodology
State and explain how to determine whether a problem is a good candidate for an EKBS solution
Represent declarative knowledge as a decision tree(s)
Generate a rule base from decision trees
Generate a forest of decision trees from a rule base
4
KBS Development Methodology CycleKBS Development Methodology Cycle
ready for finalevaluation?
design assumptioncorrect?
final evaluation
define problem & goals
design & construct prototype
analyze & correct
test/use system
failed
passed
no yes
no
yes
Prototype evolution:
• define the problem
• design & construct a prototype
• test/use the system
• analyze & correct
• if design assumptions are no longer correct. go to step 2; otherwise,
• if the system in not ready for final testing, go to step 3; otherwise,
• final test: if the system fails the final test, go to step 4; otherwise; implement the system.
5
Knowledge-based systems Knowledge-based systems developmentdevelopment
ready for finalevaluation?
design assumptioncorrect?
final evaluation
define problem & goals
design & construct prototype
analyze & correct
test/use system
failed
passed
no yes
no
yes
Selecting an appropriate problem requires a clear description of the problem and an assessment as to the FEASIBILITY of a KBS solution.
Step 1: problem definition
6
Feasibility Guidelines Include:
1. The need must justify the cost and effort
2. The knowledge in not available in all situations where it is needed
3. The problem may be solved using reasoning
4. The domain is well structured and does not require common sense
5. The problem may not be better solved using other computing methods
6. Domain expertise exists, for example, a cooperative & articulate domain expert is available
7. The problem is of proper size and scope
7
What makes for a good domain?
ALL MUST BE TRUE!
Genuine experts exist
Experts must generally agree about goals/choices
Experts must be able to articulate and explain their method
Problem must require cognitive not physical skills
Task cannot be too difficult
Problems should not require common sense
8
Knowledge-based systems Knowledge-based systems developmentdevelopment
ready for finalevaluation?
design assumptioncorrect?
final evaluation
define problem & goals
design & construct prototype
analyze & correct
test/use system
failed
passed
no yes
no
yes
• Design and prototype construction includes the following knowledge engineering tasks:
2.1 acquiring the domain knowledge
2.2 representing the domain knowledge
2.3 designing the prototype
2.4 coding the prototype
• These knowledge engineering tasks are interrelated and may require several iterations to set up step 3: test/use.
Step 2: design & prototype construction
9
Knowledge-based systems Knowledge-based systems developmentdevelopment
ready for finalevaluation?
design assumptioncorrect?
final evaluation
define problem & goals
design & construct prototype
analyze & correct
test/use system
failed
passed
no yes
no
yes
Step 3: test/use the system
Step 4: analyze and correct problems found in Step 3
Step 5: check the corrections against the design assumption and iterate through Steps 2 - 5 until there is nothing to correct.
Step 6: decide if the system is ready for the final evaluation: if not, return to Step 3; otherwise,
Step 7: perform final evaluation: if it fails, return to Step4; otherwise, Quit
Steps 3 - 7:
10
Step 2 and Declarative Step 2 and Declarative ProgrammingProgrammingA declarative program provides the computer with a set of declarative statements (facts, relationships) about a domain and the system infers conclusions that logically follow.
To accomplish this involves the interrelated tasks mentioned in Step 2 above:
1. knowledge acquisition - acquiring the knowledge about the subject matter domain;
2. knowledge representation - representing the knowledge such that it can be used by the humans involved and the computer system;
3. prototype design - that is, designing a solution that the client is OK with – show the client;
4. programming - that is, entering the knowledge-base into the system (coding the prototype) – show the client.
11
Knowledge Knowledge RepresentationRepresentation
There are several formalisms to represent declarative knowledge Each formalism has representational advantages over the others
IF-THEN Rules Many people express their knowledge in this way Easy to implement It may be hard to verify
Decision Trees A graphical way to represent knowledge for reviewing with the
expert from who it was obtained A decision tree represents a collection of decisions made by
the expert in a certain order Easy to verify
12
1. IF The customer's income is less than 25,000.
THEN The customer's line of credit is denied.
2. IF The customer's income is at least 25,000.
AND The customer's credit rating is excellent.
THEN The customer's line of credit is approved.
3. IF The customer's income is at least 25,000.
AND The customer's credit rating is good.
AND The customer has been in their present job less than 2.5 years.
THEN The customer's line of credit is denied.
4. IF The customer's income is at least 25,000.
AND The customer's credit rating is good.
AND The customer has been in their present job at least 2.5 years.
THEN The customer's line of credit is approved.
5. IF The customer's income is at least 25,000.
AND The customer's credit rating is poor.
THEN The customer's line of credit is denied.
EXSYS Corvid
variables
values
goal-variables
PSEUDO CODE RULES PCR the language in the GLS!
13
CORVID Goals:
gV1: The customer's line of credit is
1. approved.
2. denied.
CORVID Variables and VALUES:
1. V2: The customer's credit rating is
1. excellent.
2. good.
3. poor.
• V3: The customer has been in their present job 1. less than 2.5 years.2. at least 2.5 years.
• V4: The customer's income is 1. less than 25,000.2. at least 25,000.
1. IF The customer's income is less than 25,000.
THEN The customer's line of credit is denied.
2. IF The customer's income is at least 25,000.
and The customer's credit rating is excellent.
THEN The customer's line of credit is approved.
3. IF The customer's income is at least 25,000.
and The customer's credit rating is good.
and The customer has been in their present job less than 2.5 years.
THEN The customer's line of credit is denied.
4. IF The customer's income is at least 25,000.
and The customer's credit rating is good.
and The customer has been in their present job at least 2.5 years.
THEN The customer's line of credit is approved.
5. IF The customer's income is at least 25,000.
and The customer's credit rating is poor.
THEN The customer's line of credit is denied.
KBS Assistant: DICTIONARY/GLOSSARY!
14
Assign Reading: Corvid Quick Start Manual
Class Activity: Illustrate Corvid Using the Credit Example?
15
CORVID Goals:
gV1: The customer's line of credit is
1. approved.
2. denied.
CORVID Variables and VALUES:
1. V2: The customer's credit rating is
1. excellent.
2. good.
3. poor.
• V3: The customer has been in their present job 1. less than 2.5 years.2. at least 2.5 years.
• V4: The customer's income is 1. less than 25,000.2. at least 25,000.
1. IF The customer's income is less than 25,000.
THEN The customer's line of credit is denied.
2. IF The customer's income is at least 25,000.
and The customer's credit rating is excellent.
THEN The customer's line of credit is approved.
3. IF The customer's income is at least 25,000.
and The customer's credit rating is good.
and The customer has been in their present job less than 2.5 years.
THEN The customer's line of credit is denied.
4. IF The customer's income is at least 25,000.
and The customer's credit rating is good.
and The customer has been in their present job at least 2.5 years.
THEN The customer's line of credit is approved.
5. IF The customer's income is at least 25,000.
and The customer's credit rating is poor.
THEN The customer's line of credit is denied.
KBS Assistant: DICTIONARY/GLOSSARY!
16
Conventions for Constructing Conventions for Constructing a KBS Decision Treea KBS Decision Tree
1. Trees are constructed to read from top to
bottom (or left to right)
2. Nodes are labeled with variables
3. Edges are labeled with variables-values.
4. Terminal nodes (leafs) are labeled with
variable-value pairs which represent either
goals or sub-goals
5. Each complete path from the root to a
terminal node (leaf) comprises a rule.
1.The terminal node is the Then-Part of a
rule
2.The path up to the terminal node is the
If-Part of a rule
6. Rules in a tree will be numbered left to right,
rule 1 - rule n. (or top to bottom)
Var 1
Var 2
Var 3
val 1
val 1
val 1 val 2
val 2
gV4-val 1
gV4-val 1
gV4-val-2
V5-val 1
val 2
rule 1
rule 2 rule 3
rule 4
Root
Leaf
Sub-Goal
17
V4: income
gV2: approved
rule 2
gV1: denied
rule 1 V2: credit rating
V3: in job
at least 25K
excellent good poor
less then 2.5 at least 2.5
less than 25K
gV1: denied
rule 3gV2: approved
rule 4
gV1: denied
rule 5
KBS DECISION TREE1-1 with rule-base (pseudo code)
1. IF The customer's income is less than 25,000.
THEN The customer's line of credit is denied.
2. IF The customer's income is at least 25,000.
AND The customer's credit rating is excellent.
THEN The customer's line of credit is approved.
3. IF The customer's income is at least 25,000.
AND The customer's credit rating is good.
AND The customer has been in their present job less than 2.5 years.
THEN The customer's line of credit is denied.
4. IF The customer's income is at least 25,000.
AND The customer's credit rating is good.
AND The customer has been in their present job at least 2.5 years.
THEN The customer's line of credit is approved.
5. IF The customer's income is at least 25,000.
AND The customer's credit rating is poor.
THEN The customer's line of credit is denied.
Apply the definition!
18
HR Authorization ProblemHR Authorization Problem
R1 - If the visitor’s hotel type is C then the price of the hotel type is less than $50
R2 - If the visitor’s hotel is B then the price of the hotel type is between $50 and $100
R3 - If the visitor’s hotel type is A then the price of the hotel is greater than $100.
R4 - If the visitor’s hotel type is AA then the price of the hotel is greater than $100.
R5 - If the visitor’s job title is directorthen the hotel reservation is approved
R6 -If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and the visitor’s department is Accounting then the hotel reservation is approved
R7 - If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and the visitor’s department is not Accountingthen the hotel reservation is denied
R8 - If the visitor’s job title is senior manager and the price of the hotel is between $50 and $100then the hotel reservation is approved
R9 - If (the visitor’s job title is senior
manager or the visitor’s job title is junior manager
and the price of the hotel is less than $50 then the hotel reservation is approved.
R10 - If the visitor’s job title is junior manager
and the price of the hotel is greater or equal $50 then the hotel reservation is denied
Handout!
19
EXSYS Goal Variables and values:
1. The hotel reservation is approved.
2. The hotel reservation is denied.
EXSYS Variables and Values
1. The visitors hotel type is
1. C
2. B
3. A
4. AA
• The visitors job title is 1. director2. senior manager3. junior manager
DICTIONARY/GLOSSARY!
3. The price of the hotel is
1. greater than $100 (> 100)
2. between $50 and $100 (> =50 and < =100)
3. greater than or = $50 (>=50)
4. less than $50 (< 50)
4. The visitors department is 1. accounting2. not accounting
20
Example KBS Decision Tree
Hotel Reservation Authorization
Hotel type
Hotel Price is < $50
R1
C
R1 - If the visitor’s hotel type is C then the price of the hotel type is less than $50
R2 - If the visitor’s hotel is B then the price of the hotel type is between $50 and $100
R3 - If the visitor’s hotel type is A then the price of the hotel is greater than $100.
R4 - If the visitor’s hotel type is AA then the price of the hotel is greater than $100.
Hotel type
B
Hotel Price is > $50 and < $100
R2
Hotel type
Hotel Price is > $100
R3
A
Hotel type
AA
Hotel Price is > $100
R 4
21
HR Authorization ProblemHR Authorization Problem
R1 - If the visitor’s hotel type is C then the price of the hotel type is less than $50
R2 - If the visitor’s hotel is B then the price of the hotel type is between $50 and $100
R3 - If the visitor’s hotel type is A then the price of the hotel is greater than $100.
R4 - If the visitor’s hotel type is AA then the price of the hotel is greater than $100.
R5 - If the visitor’s job title is directorThen the hotel reservation is approved
R6 -If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and
the visitor’s department is Accounting then the hotel reservation is approved
R7 - If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and the visitor’s department is not Accountingthen the hotel reservation is denied
R8 - If the visitor’s job title is senior manager and the price of the hotel is between $50 and $100then the hotel reservation is approved
R9 - If the visitor’s job title is senior manager or the visitor’s job title is junior manager
and the price of the hotel is less than $50 then the hotel reservation is approved.
R10 - If the visitor’s job title is junior manager
and the price of the hotel is greater or equal $50 then the hotel reservation is denied
22
EXSYS Goal Variables and values:
1. The hotel reservation is approved.
2. The hotel reservation is denied.
EXSYS Variables and Values
1. The visitors hotel type is
1. C
2. B
3. A
4. AA
• The visitors job title is 1. director2. senior manager3. junior manager
DICTIONARY/GLOSSARY!
3. The price of the hotel is
1. greater than $100 (> 100)
2. between $50 and $100 (> =50 and < =100)
3. greater than or = $50 (>=50)
4. less than $50 (< 50)
4. The visitors department is 1. accounting2. not accounting
23
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
R5: If the visitor’s job title is director Then the hotel reservation is approved
Job Title
HR is approved
R5
Director
24
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approved
R6
R6: If the visitor’s job title is senior manager
and the price of the hotel is greater than $100
and the visitor’s department is Accounting
Then the hotel reservation is approved
Job Title
HR is approved
R5
Director
25
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
Job Title
HR is approved
R5
Director
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approved
R6 R7: If the visitor’s job title is senior manager
and the price of the hotel is greater than $100
and the visitor’s department is not Accounting
Then the hotel reservation is denied
ot Accounting
HR is denied
R7
26
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
Job Title
HR is approved
Director
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approvedR6
R8: If the visitor’s job title is senior manager and the price of the hotel is between $50 and
$100 Then the hotel reservation is denied
Not Accounting
HR is deniedR7
>=50 and <=100
HR is approvedR8
HR is approvedR5
27
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
Job Title
HR is approvedR5
Director
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approvedR6
R9: If the visitor’s job title is senior manager
and the price of the hotel is less than $50
Then the hotel reservation is approved
Not Accounting
HR is deniedR7
>=50 and <=100
HR is approvedR8
<50
HR is approvedR9
R9 - If the visitor’s job title is senior manager the visitor’s job title is junior manager and the price of the hotel is less than $50 Then the hotel reservation is approved.
OR
28
Reverse Engineering:Reverse Engineering:From Rules to Decision TreeFrom Rules to Decision Tree
Job Title
HR is approvedR5
Director
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approvedR6
Not Accounting
HR is deniedR7
>=50 and <=100
HR is approvedR8
<50
HR is approvedR9
<50
Junior ManagerHotel Price
<50
HR is approvedR10
>=50
HR is deniedR11
R11 - If the visitor’s job title is junior manager and the price of the hotel is equal to or greater than $50 then the hotel reservation is denied
R10 - If the visitor’s job title is junior manager and the price of the hotel is less than $50 then the hotel reservation is approved.
Note: the Rule base has changed!
R9 - If the visitor’s job title is senior manager OR the visitor’s job title is junior manager and the price of the hotel is less than $50 Then the hotel reservation is approved.
29
R1 - If the visitor’s hotel type is C then the price of the hotel type is less than $50
R2 - If the visitor’s hotel is B then the price of the hotel type is between $50 and $100
R3 - If the visitor’s hotel type is A then the price of the hotel is greater than $100.
R4 - If the visitor’s hotel type is AA then the price of the hotel is greater than $100.
R5 - If the visitor’s job title is directorThen the hotel reservation is approved
R6 -If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and the visitor’s department is Accounting then the hotel reservation is approved
Reverse Engineering: RevisedReverse Engineering: RevisedFrom Rule to Decision Tree(s)From Rule to Decision Tree(s)
R7 - If the visitor’s job title is senior manager and the price of the hotel is greater than $100 and the visitor’s department is not Accountingthen the hotel reservation is denied
R8 - If the visitor’s job title is senior manager and the price of the hotel is between $50 and $100
then the hotel reservation is approved R9 - If the visitor’s job title is senior manager
and the price of the hotel is less than $50 then the hotel reservation is approved.
R10 - If visitor’s job title is junior manager and the price of the hotel is less than $50
then the hotel reservation is approved.
R11 - If the visitor’s job title is junior manager
and the price of the hotel is greater or equal $50 then the hotel reservation is denied
30
Verifying the Acquired Knowledge
Using the DT, the expert’s knowledge is easy to check
Incompleteness in a knowledge-base Check whether there are some branches of a tree that are
missing
Minimal Quick Fix for an incomplete knowledge-base “This line of reasoning is under construction.”
31
Example KBS Decision Tree
Hotel Reservation Authorization
What if the Job Title is not Director, Senior Manager or Junior Manager?
HR is undecided, call your supervisor
OthersJob Title
HR is approvedR5
Director
Hotel Price
Senior Manager
>100
Visitor Dept.
Accounting
HR is approvedR6
Not Accounting
HR is deniedR7
>=50 and <=100
HR is approvedR8
<50
HR is approvedR9
Junior ManagerHotel Price
<50
HR is approvedR10
>=50
HR is deniedR11
Again, the rule base must change
32
Example KBS Decision Tree
Hotel Reservation Authorization
Other (BA)
HR is denied
Rule?
Our Department has submitted a HR for a different type of Hotel, BA.
How does the HRA handle this ?
Hotel
Hotel Price is $45
Rule 1
C B AA
Hotel Price is $75
Rule 1
Hotel Price is $120
Rule 3
A
Hotel Price is $250
Rule 4
33
Example KBS Decision Tree
Hotel Reservation Authorization
Lab 1: Enter this into EXSYS Corvid.
Prep to Lab 1: Walk though how to use Corvid using the Credit example.
Hotel type
Hotel Price is $45
Rule 1
C B AA
Hotel Price is $75
Rule 1
Hotel Price is $120
Rule 3
A
Hotel Price is $250
Rule 4
Job Title
HR is approvedR5
Director
Hotel Price
Senior Manager
Visitor Dept.
Accounting
HR is approvedR6
Not Accounting
HR is deniedR7
>=50 and <=100
HR is approvedR8
<50
HR is approvedR9
Junior ManagerHotel Price
<50
HR is approved R10
>=50
HR is deniedR11
<=100