710 likes | 726 Views
CSCI 4310. Lecture 7: Rule Systems. Book. Winston Chapter 7. Knowledge Representation. General problem-solving techniques are useful, but effectiveness often depends on extensive, domain-specific knowledge. Knowledge-based systems use a KNOWLEDGE BASE (KB) of facts about the world
E N D
CSCI 4310 Lecture 7: Rule Systems
Book • Winston Chapter 7
Knowledge Representation • General problem-solving techniques are useful, but effectiveness often depends on extensive, domain-specific knowledge. • Knowledge-based systems use a KNOWLEDGE BASE (KB) of facts about the world • Knowledge usually comes from “experts” in the domain.
Examples of knowledge • Diagnosing a programming bug • Ex: checking for base cases in recursive routines • Requires domain knowledge
Using Knowledge Representations • Contents of KB is part of cognitive model Questions, requests Examples, Statements Answers, analyses Inference Mechanism(s) Learning Mechanism(s) Knowledge Base
Knowledge Representation (KR) language • Expressiveness • can all the knowledge required for the problem be represented adequately? • Naturalness • Does the representation allow the knowledge to be input and manipulated in a natural fashion?
Knowledge Representation (KR) language continued • Efficiency • Can the system access and process the domain knowledge efficiently? • Inference • Does the representation support the generation of inferences? (new knowledge)
A knowledge-based (or expert) system is: An AI program Capable of representing and reasoning about some knowledge-rich domain With a view to solving problems and giving advice Definition
KB system levels We can talk about knowledge-based systems at different levels: Knowledge Logical Implementation
KB system levels continued • The knowledge level describes what is known independent of representation. • knowing in an abstract sense that robins are birds • The logical level describes the statement(s) in the Knowledge Representation model that represent a fact. • isa(robin,bird)
KB system levels continued • The implementation level refers to the way in which the knowledge is encoded • isa(robin,bird) might be encoded as • List • Array • Database record • Something more abstract
Getting started • What types of information need to be represented? • Which knowledge representation model should we use? • How should information be encoded in the knowledge representation model? • How will the information be accessed?
Types of Knowledge • Declarative: facts about the world. • ex: Robins have wings • Procedural: Operations embodying knowledge • ex: an algorithm for addition • Analogy: Associating knowledge about different things. • ex: Robins can fly. Robins are like sparrows. So I suspect that sparrows can fly too.
Types of Knowledge cont. • Generalization: Making generalizations from specific examples: • ex: Robins can fly, sparrows can fly, cardinals can fly…I suspect all birds can fly. • Meta-level Knowledge: Knowledge about what is known. • ex: I don’t know Jim Rogers, so I probably don’t know his phone number. • Rough definition of meta: one level higher
Explicit vs. Implicit Knowledge • Explicit knowledge is information that is encoded directly in the representation. • ex: has_part(robin,wing) • Implicit knowledge is information that can be derived from the representation. • explicit: has-part(bird,wing) • explicit: is-a(robin,bird) • implicit: has-part(robin,wing)
Explicit vs. Implicit Knowledge • Trade-off: Relying on implicit knowledge can reduce the size of the knowledge base, but it can increase the access time…. • Similar to using opening chess moves calculated offline. • Time vs. space once again
Explicit vs. Implicit Knowledge • Trivial example previously is deceptive • This can be prohibitively expensive • Satisfiability (SAT) problem • The granddaddy NP-complete problem • Graph coloring can be encoded as SAT • Many planning and scheduling problems also
Knowledge Representation Models • Propositional Logic • Predicate Calculus • Production Systems (rule-based systems) • Semantic networks • Frames • Bayesian Networks
Example • http://www.aiinc.ca/demos/whale.html
Components of a rulebased system • Working memory • Knowledge base of current assertions sometimes called context • Things that are believed to be true about the world. • This will change as rules are evaluated • Overlap with concepts from Automata Theory
Components of a rulebased system cont. • Rule base: set of inference rules • Each rule (sometimes called a production) is a conditionaction pair. • All predicates in the condition must be true for the rule to fire. • An action can add or delete facts from the working memory. • Rule interpreter • Determines which rules to apply and executes actions.
Forward Reasoning Until no rule can fire or goal state is achieved: 1. Find all rules whose left sides match assertions in working memory. 2. Pick some to execute; modify working memory by applying right sides of rules. • There is no point executing multiple rules that take identical actions. • Rules may be implicitly ordered in terms of likelihood, importance, etc. • Choose the first or highest priority satisfied rule 3. Iterate
Example • If A or B then C • If C or (D and E) then F • If C and F then G • If G or H then I Working Memory: A E Which rules will follow? Cycle 1: Cycle 2: Cycle 3: etc.
Three Parts to the ForwardChaining Rule Interpreter Match: identify which rules are applicable at any given point in the reasoning Conflict Resolution: select which (of possibly many rules) should be applied at any given point in the reasoning Execute: execute the righthand side of the chosen rule
Three Parts to the ForwardChaining Rule Interpreter cont. Heart of Rule-Based Systems • The Knowledge Base • Matching algorithm • Conflict Resolution
Matching for ForwardChaining Simply search all rules incrementally Problems: • A large rule base would lead to a very slow search. • Satisfaction of the rule's preconditions may not be obvious. • Could view as a search through all possible variable bindings and use depthfirst search, for example. It's not obvious what sort of heuristics would help.
Forward Chaining Example unknown IF X & Y & Z THEN C
Pros and Cons of Forward Reasoning • Forward reasoning has no goal in mind so it can generate a lot of irrelevant assertions in undirected fashion. • Think of all the info you discard when you add something to your working memory • I am driving… • On a road • Roads are made of asphalt • My tires are making contact with the road • None of this is relevant. • Humans detect relevancy to prune the search space • Some mental disorders cloud this ability
Pros and Cons of Forward Reasoning • Forwardchaining systems often require user to encode heuristic knowledge to guide the search. • Rule base often consists of both domain knowledge and control knowledge.
If (?x has hair) then (?x is mammal) If (?x has feathers) then (?x is bird) If (?x files) and (?x lays eggs) then (?x is bird) If (?x is mammal) and (?x eats meat) then (?x is carnivore) If (?x is mammal) and (?x eats grass) then (?x is herbivores) If (?x is mammal) and (?x has hooves) then (?x is herbivores) If (?x is carnivore) and (?x has tawny color) then (?x is tiger) If (?x is herbivores) and (?x has black/white color) then (?x is zebra) If (?x is bird) and (?x swims) then (?x is penguin) If (?x is bird) and (?x files) and (?x black/white color) then (?x is albatross) Rules
Facts F1: (Subject has hair) F2: (Subject eats grass) F3: (Subject has black/white color) Stored in Working Memory
Backward Reasoning • Start with an hypothesis and… • Some assertions in working memory • Work backward from the hypothesis • Tries to counter the undirected nature of forward-chaining
Backward Reasoning Until the hypothesis has been satisfied, or until no more rules are applicable, do the following: 1. Find all rules whose right side matches the hypothesis.
Backward Reasoning part 2 2. For each matching rule: • Try to support each of the rule's conditions by matching against assertions in working memory, or generating subhypotheses and backward chaining recursively. • If all the rule's conditions are satisfied, then success!
Control: Backward Chaining • IF A THEN C • IF B THEN C • IF C THEN D • If we want to establish D as being true, then we should establish C as being true. • To do this we need to show that A is true or that B is true • Eventually we have to • ask the user of the system • go to a database • interrogate a sensor • ...
Rules form a search tree • R1: IF A and B and C and D THEN E • R2: IF X and Y THEN A • R3: IF Z THEN B • R4: IF W THEN C • R5: IF F THEN D • R6: IF G THEN D • R7: IF H THEN G Prove E? Facts: X, Y, Z, W, H
Rules drawn as a tree X R2 A Y Z R3 B E R1 W R4 C F R5 D H R7 R6 AND G
Search aspects of backward chaining • What search strategy do we use • normally depth first • When two rules are available to prove a conclusion, which one do we use first? • if A then C • if B then C • When a premise consists of multiple components, what order do we work on them? • If A and B and C then D
If (?x has hair) then (?x is mammal) If (?x feeds young milk) then (?x is mammal) If (?x has feathers) then (?x is bird) If (?x flies) and (?x lays eggs) then (?x is bird) If (?x is mammal) and (?x eats meat) then (?x is carnivore) If (?x is mammal) and (?x has pointed teeth) and (?x has claws) and (?x has eyes point forward) then (?x is carnivore) If (?x is mammal) and (?x eats grass) then (?x is herbivore) If (?x is mammal) and (?x has hooves) then (?x is herbivore) Knowledge about animals (1)
If (?x is carnivore) and (?x has tawny color) and (?x has dark spots) then (?x is cheetah) If (?x is carnivore) and (?x has tawny color) and (?x has dark stripes) then (?x is tiger) If (?x is herbivore) and (?x has tawny color) and (?x has dark spots) and (?x has long neck) then (?x is giraffe) If (?x is herbivore) and (?x has black/white color) then (?x is zebra) If (?x is bird) and (?x has long neck) then (?x is ostrich) If (?x is bird) and (?x swims) and (?x is black/white color) then (?x is penguin) If (?x is bird) and (?x flies) and (?x is black/white color) then (?x is albatross) Knowledge about animals (2)
Want to know what species george is Information available on request: (george has hair). (george lays unknown). (george, unknown). (george eats unknown). (george has pointed teeth). (george has claws). (george has eyes point forward). (george tawny color). (george has dark spots). (george neck short). What species is george?
Matching for Backward Chaining With forward chaining we can generate all applicable rules and then select one using a welldefined conflict resolution strategy. Backward chaining is more complicated because...
Matching for Backward Chaining • The hypothesis must be matched against WM assertions and rule consequents. • The hypothesis can contain variables. • More than one rule can provide a variable binding. • Backward chaining typically uses DFS with backtracking to select individual rules.
Fan Out • A set of facts can lead to many conclusions • A higher degree of fan out argues for backward chaining
Fan In • A higher degree of fan in argues for forward chaining
Pros and Cons of Backward Reasoning • Backwardchaining is best when there is a distinct goal state that is likely to be obtainable. (If there are many acceptable goal states, then forward chaining might be fine.) • Backward reasoning can be efficient when the branching factor of the initial working memory is higher than the branching factor of the assertions that lead to the conclusion. • Backward reasoning only asks for information when it is relevant, which is extremely useful when knowledge is expensive to access.
Rule-based Systems • Many problems are best characterized by a set of rules. If-then rules (implication) are the focus of problem-solving. • Problem-solving systems that use rule-based knowledge representation and rule-based reasoning are sometimes called production systems. • This is not how humans do it, though
Rule-based Systems • Production systems may use a somewhat less formal representation scheme, use an incomplete inference procedure, and treat the consequents of rules as logical actions rather than logical conclusions. • Book refers to this as a reaction system • Need conflict-resolution procedure to decide which action to take
In principle, anything that an expert can do, and can be persuaded to articulate. It is useful to distinguish between analytic tasks which involve analysing something which already exists, and synthetic tasks which involve creating something which doesn’t. What can an expert system do?