Top Banner

of 45

14666_6_representing Knowledge Using Rules (Lecture 23-26)

Apr 07, 2018

Download

Documents

Pragyan Mishra
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    1/45

    R EPRESENTING KNOWLEDGEUSING RULES

    Chandra Prakash

    Lpu

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    2/45

    P ROCEDURAL V / S DECLARATIVE K NOWLEDGE

    A Declarative representation is one in which knowledge isspecified but the use to which that knowledge is to be put in, isnot given.

    A Procedural representation is one in which the control

    information that is necessary to use the knowledge is consideredto be embedded in the knowledge itself.

    To use a procedural representation, we need to augment it withan interpreter that follows the instructions given in theknowledge.

    The difference between the declarative and the procedural viewsof knowledge lies in where control information resides.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    3/45

    Consider the example

    man(Mohit)

    man (ron)

    Person(Shyam)

    Vx : man(x) person(x)

    Now we want to extract from this knowledge base the ans to thequestion :

    y : person (y)

    Mohit, ron or shyam can be the answers

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    4/45

    As there is more than one value that satisfies the predicate, butonly one value is needed, the answer depends on the order inwhich the assertions are examined during the search of aresponse.

    If we view the assertions as declarative, then we cannot depicthow they will be examined. If we view them as procedural, thenthey do.

    Let us view these assertions as a non deterministic programwhose output is simply not defined, now this means that there isno difference between Procedural & Declarative Statements. Butmost of the machines dont do so, they hold on to what evermethod they have, either sequential or in parallel.

    The focus is on working on the control model.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    5/45

    Logic programming

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    6/45

    Logic Programming

    Logic programming is a programming language paradigm inwhich logical assertions are viewed as programs, e.g : PROLOG

    A PROLOG program is described as a series of logical

    assertions, each of which is a Horn Clause.A Horn Clause is a clause that has at most one positive literal.

    Eg p, p V q etc are also Horn Clauses.

    The fact that PROLOG programs are composed only of Horn

    Clauses and not of arbitrary logical expressions has twoimportant consequences.

    Because of uniform representation a simple & effective interpretercan be written.

    The logic of Horn Clause systems is decidable.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    7/45

    Logic Programming

    Even PROLOG works on backward reasoning.

    The program is read top to bottom, left to right and search isperformed depth-first with backtracking.

    There are some syntactic difference between the logic and thePROLOG representations as mentioned

    The key difference between the logic & PROLOG representationis that PROLOG interpreter has a fixed control strategy, soassertions in the PROLOG program define a particular searchpath to answer any question.

    Where as Logical assertions define set of answers that they justify, there can be more than one answers, it can be forward orbackward tracking .

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    8/45

    Logic Programming

    Control Strategy for PROLOG states that we begin with aproblem statement, which is viewed as a goal to be proved.

    Look for the assertions that can prove the goal.

    To decide whether a fact or a rule can be applied to the currentproblem, invoke a standard unification procedure.

    Reason backward from that goal until a path is found thatterminates with assertions in the program.

    Consider paths using a depth-first search strategy and usebacktracking.

    Propagate to the answer by satisfying the conditions.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    9/45

    WHAT IS P ROLOG ?

    Logic programming is a programming languageparadigm in which logical assertions are viewedas a programProlog is described as a series of logicalassertions or it is a logic-based languageWith a few simple rules, information can beanalyzed.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    10/45

    Representation in logic

    x : pet(x) small (x) apartment(x)x : cat(x) dog(x) pet(x)x : poodle(x) dog(x) small(x)

    Poodle(abs)Representation in PROLOG

    Apartment (x) :- pet(x), small(x)Pet (x) :- dog (x)Dog (x) :- poodle (x)Small(x) :- poodle (x)Poodle(abs)

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    11/45

    S YNTAX

    .pl files contain lists of clausesClauses can be either facts or rules

    male(bob).male(harry).child(bob,harry).

    son(X,Y):-male(X),child(X,Y).

    Predicate, arity 1 (male/1)

    Terminates a clause

    Indicates a rule

    and

    Argument to predicate

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    12/45

    RULES

    Rules combine facts to increase knowledge of thesystem

    son(X,Y):-male(X),child(X,Y).

    X is a son of Y if X is male and X is a child of Y

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    13/45

    QUESTIONS

    In Prolog the queries are statements called directiveSyntactically, directives are clauses with an emptyleft-hand side.

    Example : ? - grandparent(X, W).

    This query is interpreted as : Who is a grandparent of X ?The result of executing a query is either success or

    failureSuccess, means the goals specified in the query

    holds according to the facts and rules of theprogram.Failure, means the goals specified in the query doesnot hold according to the facts and rules of theprogram

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    14/45

    Ask the Prolog virtual machine questionsComposed at the ?- promptReturns values of bound variables and yes or no

    ?- son(bob, harry).yes?- king(bob, france).no

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    15/45

    QUESTIONS [CONT D]

    Can bind answers to questions tovariablesWho is bob the son of? (X=harry)

    ?- son(bob, X).Who is male? (X=bob, harry)

    ?- male(X).

    Is bob the son of someone? (yes)?- son(bob, _).

    No variables bound in this case!

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    16/45

    B ACKTRACKING

    How are questions resolved??- son(X,harry).

    Recall the rule:son(X,Y):-

    male(X),child(X,Y).

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    17/45

    B ACKTRACKING [CONT D]

    Y is bound to the atom harry by the question.

    male(X) child(X,Y)

    X=harry Y=harry

    child(harry,harry)?

    child(bob,harry)?X=bob

    Y=harry

    no

    yes - succeeds

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    18/45

    A PPLICATIONS

    Intelligent systemsComplicated knowledge databasesNatural language processing

    Logic data analysis

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    19/45

    CONCLUSIONS

    Strengths:Strong ties to formal logicMany algorithms become trivially simpleto implement

    Weaknesses:

    Complicated syntaxDifficult to understand programs at firstsight

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    20/45

    ISSUES

    What applications can Prolog excel at?

    Is Prolog suited for large applications?

    Would binding the Prolog engine to another languagebe a good idea?

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    21/45

    F ORWARD V /S B ACKWARD CHAINING :

    Infer means " to derive as a conclusion from facts orpremises".

    There are 2 common rules for deriving new facts fromrules and known facts.These are

    Modus Ponens and Modus Tollens.

    7.1.1 MODUS PONENS*most common inference strategy*simple ,reaoning based on it is easily understood.

    The rule states that when A is known to be true and if a rule states " If A then B "

    it is valid to conclude that B is true.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    22/45

    7.1.2 MODUS TOLLENS

    When B is false, rule If A, then Bthen A is false.

    E.g: Rule : IF Ahmet's CAR IS DIRTYTHEN Ahmet HAS BEEN DRIVINGOUTSIDE ANKARA

    Given fact : Ahmet has not been outside Ankara.New rule : Ahmet car is not dirty.This conclusion seems quite obvious but cannot be

    reached by most expert systems. Because they usemodus ponens for deriving new facts from rules.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    23/45

    Inference engine performs 2 major tasks:1) examines existing facts and rules and adds new

    facts when possible

    2) decides the order in which inferences are made.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    24/45

    TWO REFERENCING METHODS :

    Forward ChainingBackward chaining

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    25/45

    F ORWARD V / S BACKWARD R EASONING

    The objective of any search is to find a path through a problemspace from the initial to the final one.

    There are 2 directions to go and find the answer

    Forward

    Backward

    8-square problem

    Reason forward from the initial states : Begin building a treeof move sequences that might be solution by starting with the

    initial configuration(s) at the root of the tree. Generate the nextlevel of tree by finding all the rules whose left sides match theroot node and use the right sides to create the newconfigurations. Generate each node by taking each nodegenerated at the previous level and applying to it all of the ruleswhose left sides match it. Continue.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    26/45

    F ORWARD V / S BACKWARD R EASONING

    Reason backward from the goal states : Reason backwardfrom the goal states : Begin building a tree of move sequencesthat might be solution by starting with the goal configuration(s)at the root of the tree. Generate the next level of tree by findingall the rules whose right sides match the root node and use theleft sides to create the new configurations. Generate each nodeby taking each node generated at the previous level and applyingto it all of the rules whose right sides match it. Continue. This isalso called Goal-Directed Reasoning.

    To summarize, to reason forward, the left sides(pre conditions)are matched against the current state and the right sides(theresults) are used to generate new nodes until the goal is reached.

    To reason backwards, the right sides are matched against thecurrent node and the left sides are used to generate new nodes.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    27/45

    Forward chaining : also called data driven.It starts with the facts, and sees what rules apply.

    Backward chaining : also called goal driven.

    It starts with something to find out, and looks forrules that will help in answering it.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    28/45

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    29/45

    Problem: Does situation Z exists or not ?

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    30/45

    F ORWARD CHAINING A LGORITHM

    Given m facts F 1,F2,....,F m? N RULES R 1,R2,......R nrepeat for i ?- 1 to n do

    if one or more current facts match the antecedent of Rithen

    1 ) add the new fact(s) define by the consequent2 ) flag the rule that has been fired3 ) increase m until no new facts have been produced.

    until no new facts have been produced.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    31/45

    B ACKWARD CHAINING :

    With this inference method the system starts with what itwants to prove, e.g.,that situation Z exists, and onlyexecutes rules that are relavent to establishing it.Figure following shows how bacward chaining wouldwork using the rules from the forward chaining example.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    32/45

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    33/45

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    34/45

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    35/45

    B ACKWARD CHAINING ALGORITHM :

    Prove goal G :If G is in the initial facts , it is proven.Otherwise, find a rule which can be used toconclude G, and try to prove each of that rule'sconditions.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    36/45

    Factors that influence whether to choose forward or backwardreasoning :

    Are there more possible start states or goal states? We would like togo from smaller set of states to larger set of states.

    In which direction is the branching factor (the average number of nodes that can be reached directly from a single node) greater? We

    would like to proceed in the direction with the lower branchingfactor.

    Will the program be asked to justify its reasoning process to theuser? It so, it is important to proceed in the direction thatcorresponds more closely with the way user will think.

    What kind of event is going to trigger a problem-solving episode?If it is the arrival of a new fact , forward reasoning should be used.If it a query to which response is desired, use backward reasoning.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    37/45

    Forward v/s Backward Reasoning

    Home to unknown place example.

    MYCIN

    Bidirectional Search ( The two searches must pass each other)Forward Rules : which encode knowledge about how to respondto certain input configurations.

    Backward Rules : which encode knowledge about how toachieve particular goals.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    38/45

    Forward v/s Backward Reasoning

    Backward-Chaining Rule Systems

    PROLOG is an example of this.

    These are good for goal-directed problem solving.

    Hence Prolog & MYCIN are examples of the same.Forward Chaining Rule Systems

    We work on the incoming data here.

    The left sides of rules are matched with against the statedescription.

    The rules that match the state dump their right side assertions intothe state.

    Matching is more complex for forward chaining systems.

    OPS5 is the examples of the same.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    39/45

    Combining Forward v/s Backward Reasoning

    Patients example of diagnosis.

    In some systems ,this is only possible in reversible rules.

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    40/45

    QUESTION

    A NSWERING

    PROLOG:

    Only Horn sentences are acceptable

    The occur-check is omitted from the unification: unsound

    test P(x, x)

    P(x, f(x))

    Backward chaining with depth-first search: incomplete

    P(x, y) Q(x, y)P(x, x)

    Q(x, y) Q(y, x)

    40

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    41/45

    QUESTION

    A NSWERING

    PROLOG:

    Unsafe cut: incomplete

    A B, C A

    B D, !, E

    D B, C

    D, !, E, C

    !, E, C

    41

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    42/45

    QUESTION

    A NSWERING

    PROLOG:

    Unsafe cut: incomplete

    A B, C A

    B D, !, E

    D B, C

    D, !, E, C

    !, E, C

    Negation as failure: P if fails to prove P 42

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    43/45

    KNOWLEDGE REPRESENTATION

    43

    Matching with Variables

    The problem of selecting applicable rules is made more difficult whenpreconditions are not stated as exact descriptions of particular situationsbut rather describe properties that the situations must have.

    Then we need to match a particular situation and the preconditions of a

    given situation.In many rules based systems, we need to compute the whole set of rules

    that match the current state description. Backward Chaining Systemsusually use depth-first backtracking to select individual rules, but forwardchaining systems use Conflict Resolution Strategies.

    One efficient many to many match algorithm is RETE

    C h

    an

    d r

    aP r

    ak a s h

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    44/45

    KNOWLEDGE REPRESENTATION

    44

    Complex & Approximate Matching

    A more complex matching process is required when the preconditions of a rule specify required properties that are not stated explicitly in thedescription of the current state. In this case, a separate set of rules must beused to describe how some properties can be inferred from others.

    An even more complex matching process is required if rules should beapplied if their preconditions approximately match the current situation.Example of listening to a recording of a telephonic conversation.

    For some problems, almost all the action is in the matching of the rulesto the problem state. Once that is done, so few rules apply that theremaining search is trivial. Example ELIZA

    C h

    an

    d r

    aP r

    ak a s h

  • 8/3/2019 14666_6_representing Knowledge Using Rules (Lecture 23-26)

    45/45

    KNOWLEDGE REPRESENTATION

    45

    Conflict Resolution

    The result of the matching process is a list of rules whose antecedentshave matched the current state description along with whatever variablebinding were generated by the matching process.

    It is the job of the search method to decide on the order in which therules will be applied. But sometimes it is useful to incorporate some of thedecision making into the matching process. This phase is called conflictresolution.

    There are three basic approaches to the problem of conflict resolution inthe production system

    Assign a preference based on the rule that matched.

    Assign a preference based on the objects that matched.

    Assign a preference based on the action that the matched rule wouldperform.

    C h

    an

    d r

    aP r

    ak a s h