1
Rule based representation M Sasikumar 1 Overview Background - - PowerPoint PPT Presentation
Rule based representation M Sasikumar 1 Overview Background - - PowerPoint PPT Presentation
Rule based representation M Sasikumar 1 Overview Background What/Why RBR Forms of rules Uncertainty Certainty factor Issues 2 Sasikumar M, IIT Bombay Background One of the most well known representation mechanisms.
Sasikumar M, IIT Bombay
2
Overview
- Background
- What/Why RBR
- Forms of rules
- Uncertainty
– Certainty factor
- Issues
Sasikumar M, IIT Bombay
3
Background
- One of the most well known representation
mechanisms.
– Model for how human brain works?!
- Easy to externalise and interpret.
- Good inferencing mechanisms.
- Theoretical basis available to some extent.
Sasikumar M, IIT Bombay
4
What is a rule
- If arrival time > 9.30 and arrival time < 10.00
then insert casual_leave(0.5)
- If symptoms include headache and
headache_duration > 7 days and fever not present then investigate disease_x
- If value_1 > value_2 and ans = value_2-
value_1 then misconception = order_problem
Sasikumar M, IIT Bombay
5
Form of a rule
- If <condition> then <conclusion>
- If <condition> is known to be true then
<conclusion> can be claimed to hold
- Many variations possible on this format.
- Very popular with expert systems literature.
– Can be used for capturing domain knowledge and
student/tutor models in ATS.
Sasikumar M, IIT Bombay
6
Why rules?
- They can be read like English (usually!).
- And hence with minor rewrite makes sense to
the user.
- (Usually) rules are independent of each other.
– Can insert and delete without worrying about other
rules (!)
– No control flow embedded.
- Can be built from outside
Sasikumar M, IIT Bombay
7
Using rules
- Choose a rule whose conditions match with
the current problem state, and perform the action.
– Forward chaining
- Set a goal. Choose a rule whose conclusion
matches with our goal, and check if the conditions can be made true.
– Each condition becomes a sub-goal – Backward chaining
- Can mix them in a system.
Sasikumar M, IIT Bombay
8
Using rules
Rule Interpreter Working Memory Rule Base
Sasikumar M, IIT Bombay
9
Using rules...
- What if there are multiple rules that match?
- Some sense of priority to be used
– Rule order in the system – Manually assigned priority numbers – Specificity
- If A and B then C1
- If A then C2
– Semantic analysis of the candidates
- Who uses what parameters, dependencies, etc
Sasikumar M, IIT Bombay
10
Forms of rules
- Around the basic theme, many variations
proposed and used.
- Variation on
– Structure of a condition – Combining conditions in to a rule – Structure of conclusion – Multiple conclusions – Annotations
Sasikumar M, IIT Bombay
11
Condition
- Matches with information collected in the working
memory.
- Model-1: atomic condition
– heavy_rain, take_umbrella, top_higher_than_bottom
- Model-2: attribute operator value
– Age > 40, fever is true, current_column is “col1” – What kind of operators, and their meaning?
- Model-3: value can also be an attribute
– Top > bottom
- Model-4: add context also
– P1.age > 40, thisvisit.fever is true, column1.top >
column1.bottom
Sasikumar M, IIT Bombay
12
…
- More logic based formations
– Richer operations in the form of predicates – severe(P,pain_intensity) and
high(bloodpressure,P)
– parent(P,P1), cardiac(P1) →
- Richer operations (e.g. OPS5)
– (student ^age >40 ^name “%iar”) – ((student ^name n1 ^mark m),
- (student ^name n2 ^mark >m)) → (winner ^name
n1)
–
Sasikumar M, IIT Bombay
13
Combining conditions
- Single condition is too restrictive
- Conjunction supported by most
– If A and B then ….
- Disjunction also possible.
– If A or B then … – Can be done by two separate rules.
- Negation permitted with some restriction
– Negation may raise semantic problems – student(X) and not passed(X,s1) – not student(X)
Sasikumar M, IIT Bombay
14
Structure of conclusion
- Purpose
– Just infer something is true or false
- Disease includes meningitis
– Compute something
- Increase severity by 0.4
- No side effect...
– Perform an action
- Display message 13
- Side effects?
- Multiple pieces
– Conjunction (usual meaning) – Disjunction
- Complexities of managing multiple paths
Sasikumar M, IIT Bombay
15
Annotations
- A number of annotations can add value to the
simple rule structure.
- Rule groups are often used to manage
interactions and provide structure.
- Rule ID, and priority tags.
- Attributes can be linked to ontologies.
- Applicability context as annotation vs as
additional clauses (Guidon story).
- Translation mappings for display, etc.
Sasikumar M, IIT Bombay
16
Explaining with rules
- Keeping track of which rules were used when,
we can produce meaningful traces to user.
- is(fever,true), less(age,40), is(headache,false)
=> set(disease,abc)
- If fever is true and age less 40 and headache
is false then infer that disease is abc
- If patient has fever and his age is less than 40
and he is not having head ache, then it is possible he may be having abc disease.
- ….
Sasikumar M, IIT Bombay
17
….
- Attach translation to attributes, operators,
conclusions, and so on.
- Translation can be simple mapping, or
contextual mapping.
- Possible to generate fairly good readable
paraphrasing of the rule automatically.
- Similarly, the control structure can also be
translated...
Sasikumar M, IIT Bombay
18
….
- Where are you? Why do you want to know?
– I am trying to check if you have disease abc, and
there is a rule R1 which can be used for this. I am verifying its conditions.
- How did you know...
– This information was provided by you earlier for
my question …
– This information was arrived at from rules r1, r14,
and r20.
Sasikumar M, IIT Bombay
19
Rules in an uncertain world..
- Symptom disease mapping, behaviour error
mapping, etc usually not fully certain.
- Uncertainty part of life in these cases.
- Rules need to factor this in.
- Certainty factor based model is common.
- Probability based systems, fuzzy rules etc also
used.
Sasikumar M, IIT Bombay
20
Certainty factor in rules
- If A then B with confidence cf
- What does cf mean?
– Maximum confidence B can get from here
- A itself may be uncertain
– Should reflect in the confidence of B
- Multiple rules may suggest B
– Some way to aggregate support from multiple
sources.
Sasikumar M, IIT Bombay
21
Certainty factor
- A bounded number: 0 to 1, -1 to 1, 0 to 100,
etc
– -1 to +1: negative indicates false, positive
indicates true.
– 0 to 1: rules of probability can be used.
- Increasing CF means increasing belief in its
truth, and reverse for decrease.
Sasikumar M, IIT Bombay
22
CF calculus
If A then B with CF=x1. A has CF = y1.
- CF of B (b1) = x1 * y1
If C then B with CF= x2. B gets CF = b2 Net: b1+b2? b1+b2*(1-b1)? max(b1,b2)? etc
Sasikumar M, IIT Bombay
23
The rule!
- If a1 and a2 or a3 then c1 and c2 with
confidence cf1 and cf2 respectively, priority class B.
- Various syntactic frameworks possible
– Usually well delimited to make parsing easy – OPS-5 rich production rules
- Almost like a programming language
– Prolog format
- Logic programming model
Sasikumar M, IIT Bombay
24
The rule
Context: col = 1, top = 5, bottom = 3, ans = ?, carry = ? current_focus(col) and greater(top, bottom) and first_column(col) => ans = top – bottom, carry = 0 (rule (and (current_focus ^col) (values ^col ^top ^bottom) (> ^top ^bottom) (first_column ^col)) (insert (result ^col (- ^top ^bottom) /* ans */ 0 /* carry */))
Sasikumar M, IIT Bombay
25
….
In a procedural language, this could be: get_values(current_focus, &top, &bot); if (top > bot) && (current_focus == 1) ans = top – bottom; carry = 0; set_values(current_focus, top, bot, ans, carry); current_focus++;
Sasikumar M, IIT Bombay
26
Rules in ATS
- Rules as knowledge units provide a lot of
flexibility.
- Useful for domain model, student model and
tutor model.
- Eg.: can build student model around this.
– Does he know rule x?
- The simple and uniform structure facilitates
– Malrules, error diagnosis, corrective action, etc
Sasikumar M, IIT Bombay
27
More on rules
- Store rules externally, and build a parser to build an
internal representation.
– For languages like python, can do as part of program
itself!
- Sample python rulebase:
rules = { "r1":([("age",">",40),("fever","is","true")], ("disease","abc")), "r2":(2,2), "r3":(3,3) }
- Dictionary → tuple → list → tuple
- Inspectable, and executable.
Sasikumar M, IIT Bombay
28
….
def display(rid): rule = rules[rid]; (ante,conse) = rule; print “Rule “+rid+”: “; print “IF “; for i in ante: /* each condition */ (attr, opr, value) = I; print attr+” “+opr+” “+value+” and”; print “Then conclude that ..”; …..
Sasikumar M, IIT Bombay
29
...
- Can perform automated analysis for
consistency, completeness, subsumption, etc
– Common problems with knowledge bases
- Can also be induced from examples
– Rule induction in machine learning
Sasikumar M, IIT Bombay
30
Why not rules?
- Independence is not realistic in general.
- Managing control flow in large rulebases is a
problem.
- Procedural knowledge is difficult to capture and use.
- Different types of knowledge and one type of
representation
– Good or bad.
- Cognitive fidelity is difficult to achieve in case of
ATS/ITS
– ACT-R?
Sasikumar M, IIT Bombay
31
Wrapping up
- The simple if-then rules provide a rich and
powerful representation for knowledge representation (in ITS).
- Choose an appropriate structure for syntax to
limit the parsing and interpreting complexity.
- There are frameworks like JESS available, if
your requirement matches.
- Building one is also possible.
Sasikumar M, IIT Bombay
32