inference with production rules
Download
Skip this Video
Download Presentation
Inference with Production Rules

Loading in 2 Seconds...

play fullscreen
1 / 24

Inference with Production Rules - PowerPoint PPT Presentation


  • 145 Views
  • Uploaded on

Inference with Production Rules. The way in which the knowledge base is used is determined by the inference engine It is a basic principle of production systems that each rule should be an independent item of knowledge and essentially ignorant of other rules

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Inference with Production Rules' - ocean


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
inference with production rules
Inference with Production Rules
  • The way in which the knowledge base is used is determined by the inference engine
    • It is a basic principle of production systems that each rule should be an independent item of knowledge and essentially ignorant of other rules
    • The inference engine could then simply "fire" rules at any time when its premises are satisfied.
inference with production rules2
Inference with Production Rules
  • Forward and Backward chaining through the rules may be used
  • The two systems each have their advantages and disadvantages and in fact answer different types of question
  • For example in Mycin
    • a forward chaining system might answer the question "what do these symptoms suggest?"
    • a backward chaining system might answer the question "does this patient suffer from amnesia?"
inference with production rules3
Inference with Production Rules
  • Before looking at Forward and Backward chaining in more detail we need to clarify some things
  • There are two main issues involved in the implementation of a rule-based system
    • How is conflict resolution implemented?
      • Various strategies
    • How are facts matched to rules?
      • Pattern matching required
      • And many more issues need to be resolved
matching facts to rules
Matching facts to rules
  • First of all we need to define a syntax for the rules and the facts
  • In the following slides we will discuss pattern matching assuming a forward chaining system is used
rule based representation example
Rule-based Representation Example
  • R0:
    • IF mortgage is due

AND checking account has enough money to pay mortgage

THEN pay mortgage

AND reduce checking balance by amount of mortgage

rule based representation example6
Rule-based Representation Example
  • The previous rule uses natural language
  • In reality we must restrict the rule-base representation to a limited machine-processable representation
  • There is no standard rule syntax
  • For example:
    • We can think of the LHS of a rule as being a list that contains the name of an object followed by pairs of attributes and values associated with that object
rule based representation example7
Rule-based Representation Example
  • R0:
    • IF (bill  name mortgage  status due  amount 500)

AND (account  name checking  balance 500)

THEN (assert (pay  item mortgage))

AND (remove (bill  name mortgage  status due  amount 500))

AND (remove (account  name checking  balance 500))

AND (assert (account  name checking  balance 0))

rule based representation example8
Rule-based Representation Example
  • Assume the working memory has the following contents
  • WM:
    • (bill  name mortgage  status due  amount 500  account  name checking  balance 500)
  • The rule will fire
rule based representation example9
Rule-based Representation Example
  • bill is an object
  • name, status, amount are attributes followed by their values
  • remove and assert are primitives used to remove and add facts to working memory
  • Problem:
    • A rule would have to be created for each amount and each type of bill
    • To solve it we can introduce variables and operations
rule based representation example10
Rule-based Representation Example
  • R0:
    • IF (bill  name  status due  amount )

AND (account  name checking  balance  ())

THEN (assert (pay  item ))

AND (remove (bill  name  status due  amount ))

AND (remove (account  name checking  balance ))

AND (assert (account  name checking  balance ( - )))

rule based representation example11
Rule-based Representation Example
  • Assume the working memory has the following contents
  • WM:
    • (bill  name electric  status due  amount 100  account  name checking  balance 400)
  • The rule will fire
    • The fact balance 300 will be added to the working memory
rule based representation example disjunctions
Rule-based Representation Example (disjunctions)
  • R0:
    • IF (bill  name  status [due over_due]  amount )

AND (account  name checking  balance  ())

THEN (assert (pay  item ))

AND (remove (bill  name  status due  amount ))

AND (remove (account  name checking  balance ))

AND (assert (account  name checking  balance ( - )))

rule based representation example disjunctions13
Rule-based Representation Example (disjunctions)
  • Assume the working memory has the following contents
    • (bill  name mortgage  status due  amount 700)

(bill  name electric  status over_due  amount 200)

(bill  name water  status not_due  amount 50) (account  name checking  balance 900)

  • How many times will the rule fire?
matching facts to rules14
Matching facts to rules
  • Once a rule syntax has been defined we must specify how the matching of facts to conditions of rules will be performed
    • I.e. trying to determine if the LHS of a rule is satisfied by the facts in working memory
  • It has been estimated that 90% of a rule-based system’s run time is spent on performing repetitive pattern matching between rules and facts in the working memory
the rete matching algorithm
The Rete Matching Algorithm
  • What is a solution to this pattern matching problem?
    • Try exhaustively to match rules to facts one by one
    • Use indexing techniques
  • The Rete algorithm was the first efficient solution to the facts-rules pattern matching problem
    • It stores information about matches in a network structure
the rete matching algorithm16
The Rete Matching Algorithm
  • Nodes of the network correspond to individual condition elements
    • Conditions and conjunctions of conditions
  • Each node has two sets associated with it
    • The first set contains all the working memory elements that the condition node matches
    • The second set contains combinations of working memory elements and the bindings which produce a consistent match of the conditions that chain up to the node condition
the rete matching algorithm17
The Rete Matching Algorithm
  • With this configuration repetitive testing of all rule conditions in each cycle is avoided
    • Only the nodes affected by a newly inserted or modified fact are checked
    • For example, consider the rules
      • IF a(X,1) and b(X,Z) THEN g1(X,Z)

IF a(X,2) and b(X,Z) THEN g2(X,Z)

the rete matching algorithm18
The Rete Matching Algorithm

Initially the working memory

is empty

start

b(X,Z)

a(X,Y)

- There is a starting node and a node for each of the rule conditions and conjunctions of conditions.

- Arcs are labeled with

variable bindings

Y=1

Y=2

a(X,2),b(X,Z)

a(X,1),b(X,Z)

the rete matching algorithm19
The Rete Matching Algorithm

Fact a(3,1) is added to

the working memory

start

a(3,1)

b(X,Z)

a(X,Y)

a(3,1) is deposited

in the node labeled

a(X,Y) and will propagate through the arc labeled Y=1

Y=1

Y=2

a(3,1)

a(X,2),b(X,Z)

a(X,1),b(X,Z)

Rule doesn’t match

the rete matching algorithm20
The Rete Matching Algorithm

Fact b(3,4) is added to

the working memory

start

a(3,1)

a(X,Y)

b(X,Z)

b(3,4)

b(3,4) is deposited

in the node labeled

b(Y,Z) and will propagate through the arcs labeled Y=1 and Y=2

Y=1

Y=2

a(3,1),b(3,4)

b(3,4)

a(X,2),b(X,Z)

a(X,1),b(X,Z)

Rule matches

Rule doesn’t match

the rete matching algorithm21
The Rete Matching Algorithm

Fact a(3,2) is added to

the working memory

start

a(3,1),a(3,2)

a(X,Y)

b(X,Z)

b(3,4)

a(3,2) is deposited

in the node labeled

a(X,Y) and will propagate through the arc labeled Y=2

Y=1

Y=2

a(3,1),b(3,4)

a(3,2),b(3,4)

a(X,2),b(X,Z)

a(X,1),b(X,Z)

Rule matches

Rule matches

the rete matching algorithm22
The Rete Matching Algorithm
  • The Rete algorithm (and extensions) are widely used in rule-based systems
  • It allows for an efficient matching process (on average)
  • A naïve algorithm that tries all combinations of rules and facts has exponential complexity
inference with production rules23
Inference with Production Rules
  • There are two main issues involved in the implementation of a rule-based system
    • How is conflict resolution implemented?
      • Various strategies
    • How are facts matched to rules?
      • Pattern matching required
      • And many more issues need to be resolved
inference with production rules24
Inference with Production Rules
  • There are many issues to be decided when implementing the inference mechanism
    • In what order do we check rules?
    • In what order do we check facts?
    • Algorithms may produce facts that are irrelevant to goals. How do we avoid producing such facts?
      • Backward chaining does not suffer from this problem
ad