cours syst me expert jess 2015.ppt [mode de compatibilit ])picard/cours/ai/chapter-jess.pdf ·...

44
Institut Mines-Télécom Expert System Flavien Balbo 1

Upload: lemien

Post on 03-Apr-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Institut Mines-Télécom

Expert System

Flavien Balbo1

Institut Mines-Télécom

Plan

� Introduction

� Expert system

• Architecture

• Inference algorithm

� Implementation

• JESS

2

Institut Mines-Télécom

IntroductionExpert Systems

� Definition

• Expert systems are computer programs that try to replicate knowledge and skills of human experts in some area, and then solve problems in this area (the way human experts would).

Expert System

Problem

Deduction / Resolution

3

Institut Mines-Télécom

Expert SystemUse case

� A restrained expertise domain

• There are experts,

• The problem is well defined

• There is no efficient algorithm.

� Most applications of expert systems will fall into one of the following categories

• Interpreting and identifying

• Predicting

• Diagnosing

• Designing

• Planning• Monitoring• Debugging and testing• Instructing and training• Controlling

4

Institut Mines-Télécom

Expert SystemProduction rule

� Description

• A production rule is an:

─ IF situation / premise / antecedent THEN action / conclusion / consequent

• with

─ situation / premise / antecedent

• Conjunction of conditional elements

─ Action / conclusion / consequent

• Modification of the working memory: addition, deletion or modification of facts

• Every other, possible actions.

� Algorithms

• Forward chaining: data driven reasoning

─ start with known data and progress to a conclusion

• Backward chaining: goal driven reasoning

─ start with a possible conclusion and try to prove its validity by searching for evidence.

5

Institut Mines-Télécom

Expert SystemsFirst Systems

� DENDRAL (Lederberg, 1965): chemical-analysis expert system.

• Starting from spectrographic data obtained from the substance, DENDRAL would hypothesize the substance's molecular structure.

• Only heuristics and specialized knowledge.

� MYCIN (Shortliffe, 1974): assist physicians in the diagnosis of infectious diseases

• Introduction of the uncertainty notion

• Introduction of an explanation process

6

Institut Mines-Télécom

Expert SystemRules and Knowledge

� Business rules are statements that describe the policies of a company. Examples of business rules can include the following:

• All customers that buy more than $100 worth of products at one time or who are over the age of 65 receive a 10% discount.

• A sales department is notified when inventory quantity is lower than ten and there are more than five pending orders on a given day.

• If the annual income of a customer is less than $10,000, a loan request is denied.

• If a customer submitted a late payment for a previous purchase, an additional charge of 2% is added to their next purchase.

7

Institut Mines-Télécom

Expert SystemRules and Coordination

� if current time between 8am and 6pm then prime schedule.

� if current time between 6pm and 8am then standard schedule.

� if current time between 0am and 4am then optional maintenance schedule.

� if prime schedule then the service level "average availability“ has a low value of 98%, a median of 99% and a high value of 100% and a response time which must be below 4 seconds.

� ...

� if standard schedule then the responsible role for service outages is the second admin. Paschke, A., & Kozlenkov, A. (2008). A Rule-based Middleware for Business

Process Execution. In Multikonferenz Wirtschaftsinformatik.

8

Institut Mines-Télécom

Expert SystemRules

if ((user.isMemberOf(AdministratorGr) && user.isMemberOf(teleworkerGr))

|| user.isSuperUser()

{ // more checks for specific cases

if( (expenseRequest.code().equals("B203")||

(expenseRequest.code().equals("A903")

&&(totalExpenses<200) &&(bossSignOff> totalExpenses)

) &&(deptBudget.notExceeded)) {

//issue payments

} else if {

//check lots of other conditions

}

} else {

// even more business logic

}

� How to maintain the rules ?

� How to test the rules ?

� How to share the rules ?

www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=1

9

Institut Mines-Télécom

Joaquín Abellán, Griselda López, Juan de Oña, Analysis of traffic accident severity using Decision Rules via Decision Trees,

Expert Systems with Applications, Volume 40, Issue 15, 1 November 2013, Pages 6047-6054

10

Institut Mines-Télécom

Expert SystemRules and Artificial Intelligence

11

Institut Mines-Télécom

Expert SystemRules and Artificial Intelligence

Skillen, K. L., Chen, L., Nugent, C. D., Donnelly, M. P., Burns, W., & Solheim, I. (2014). Ontological user modelling and semantic rule-based reasoning for personalisation of Help-On-Demand services in pervasive environments. Future

Generation Computer Systems, 34, 97-109.

12

Institut Mines-Télécom

Expert systems

Architecture

Inference algorithm

13

Institut Mines-Télécom

Expert SystemArchitecture

www.cs.bham.ac.uk/~jxb/IAI/w9.pdf

14

Institut Mines-Télécom

Expert SystemProduction rule

� Description

• A production rule is an:

─ IF situation / premise / antecedent THEN action / conclusion / consequent

• with

─ situation / premise / antecedent

• Conjunction of conditional elements

─ Action / conclusion / consequent

• Modification of the working memory: addition, deletion or modification of facts

• Every other, possible actions.

� Algorithms

• Forward chaining: data driven reasoning

─ start with known data and progress to a conclusion

• Backward chaining: goal driven reasoning

─ start with a possible conclusion and try to prove its validity by searching for evidence.

15

Institut Mines-Télécom

AlgorithmForward chaining

Procedure ForwardChainig (DD,RB)

ConflictSet ���� Detection(DD,RB)

While (ConflictSet ≠ ∅∅∅∅)

R ���� Resolution(ConflictSet )

RB ���� RB – {R}

DD ���� DD ∪∪∪∪ Conclusion(R)

If Inconsistent(DD) then exit end If

ConflictSet ���� Detection(DD,RB)

End While

End

1.Matching: Compare rules with known facts and find rules that are satisfied.

2.Conflict Resolution: More than one rule may be satisfied. Conflict resolution is the process of selecting one of them.

3.Execution: The rule selected is executed (fired). This may result in a new fact(s) to be added and the process continues forward.

16

Institut Mines-Télécom

AlgorithmConflict Resolution

Heuristics

� Its rank in the source,

� A priority order according to the goal

� A priority order according to the fact

� The complexity of the rule,

� A time value for its last use

� A time value for the used facts.

� …

Example� DD: {B,C}

� RB:

R1: B ∧ D ∧ E => F

R2: G ∧ D => A

R3: C ∧ F => A

R4: B => X

R5: D => E

R6: X ∧ A => H

R7: C => D

R8: X ∧ C => A

R9: X ∧ B => D

� Heuristic

• The complexity order

• First rule in the source17

Institut Mines-Télécom

Algorithmbackward chaining

1. Form a stack consisting of all the possible goals.

2. Try to prove the first goal on the top of stack. Find all the rules that can satisfy this goal.

3. Examine the premises of each rule a. if all premises of the rule are satisfied then fire the rule and remove the

corresponding goal from the stack and then go to step 2.

b. if one or more of the premises can not be satisfied using the current facts then find rules that can satisfy the premise and put their action parts as subgoals on the top of the stack. And go to step 2.

c. if no rules can be found in b then ask the user and add that to the working memory if the value given by the user satisfies the premise otherwise try the next rule.

� 4. If all the rules that can satisfy the goal have failed then remove the goal from the stack and go to 2. If stack empty then stop.

18

Institut Mines-Télécom

Algorithmbackward chaining

Fonction backwardChaining (b, DD, RB)

if b ∈∈∈∈ DD then return true

else

ConflictSet = detection(b, DD, RB)

for (R ∈∈∈∈ ConflictSet)

bool ���� true;

Condition ���� condition(R)

while( Condition ≠ ∅∅∅∅) and bool)

bool ���� backwardChaining (first(Condition),DD,RB)

Condition ���� Condition – first(Condition);

endWhile

if bool then

DD ���� DD ∪∪∪∪ {b};

return true;

endif

endfor

if askable(b) then return answer(b);

else return false;

endif

end

19

Institut Mines-Télécom

Backward Chaining Conflict resolution

� Conflict resolution between rules (node or)

• The order in the source

• random

• the less unknown conditions

• With priority order

• Meta-rules

• …

� Conflict resolution between facts (node and)

• The order in the source

• “Askable” first

• “askable” last

• …

20

Institut Mines-Télécom

Example

� DD: {G,R,F,L}

� Goal: X

� Heuristic

• Rules

─ With the less of unknown facts

─ First in the source.

• Facts

─ Order of the rule

R1 A∧B ���� X

R2 F∧S ���� C

R3 L∧H ���� I

R4 E ���� A

R5 L ���� D

R6 G∧H ���� B

R7 G ���� S

R8 G∧I ���� E

R9 D∧C ���� X

R10 D∧R ���� B

R11 E∧F ���� X

21

Institut Mines-Télécom

Implementation

JESS

http://www.jessrules.com/jess/

22

Institut Mines-Télécom

JESS Features

� First order logic

� Non-monotonic logic

� “Not” management by absence

� Complex premises

� Forward chaining and backward chaining.

� RETE algorithm

� JAVA compatible

23

Institut Mines-Télécom24

Institut Mines-Télécom

Plan

� Jess

• Langage description

• Matching process

• Conflict Resolution

� Jess and Java

25

Institut Mines-Télécom

SyntaxTypes

� Atom• Every string without guillemet and blank

• One, one, one2three, …

� Number• Based on java.lang.Integer and java.lang.Double

• 1, -1.5, 125, …

� String• Character strings are denoted using double quotes ("). Backslashes (\) can

be used to escape embedded quote symbols. Note that Jess strings are unlike Java strings in several important ways. First, no "escape sequences" are recognized. You cannot embed a newline in a string using "\n", for example. On the other hand, real newlines are allowed inside double-quoted strings; they become part of the string.

� List

• (1 2 3) ; (TheList 1 a e 2)

26

Institut Mines-Télécom

SyntaxFact

� Ordered fact or pattern:• (<symbole> <valeur1> … <valeur n>)

� Structured fact or template

(deftemplate template-name ["Documentation comment"]

(slot | multislot slot-name

[(type ANY | INTEGER | FLOAT | NUMBER | SYMBOL | STRING | LEXEME | OBJECT | LONG)]

[(default default value)]

)

27

Institut Mines-Télécom

FactModeling choice

� Ordered facts

• Advantage─Can be used without declaration

• Disadvantage─No control on the type of the data

─ Inexplicit

� Structured facts:

• Advantage: ─Explicit

─Control of the type of data

• Disadvantage─ Must be declared in the source

28

Institut Mines-Télécom

SyntaxVariables

� Local variable

• Type: atom, number, string, list

• Name: ?<VariableName>

• Declaration: (bind ?< VariableName> <value>)

� Global varaible

• Type: atom, number, string, list

• Name: ?*<VariableName>*

• Declaration: (defglobal [?< VariableName>=<value>]+)

� Remise à zéro

• (reset)

29

Institut Mines-Télécom

FunctionPredicates

� Type Predicates • (numberp <expr>) (integerp <expr>) …

� Comparison Predicates • (eq <expr> <expr>+) (neq <expr> <expr>+) (=

<expr> <expr>+) (> <expr> <expr>+) (<> <expr> <expr>+)…

� Boolean Predicates• (and <exp>+) (or <exp>+) (not <exp>+)

� Other predicates• (oddp <expr>) (evenp <expr>)

• ……

30

Institut Mines-Télécom

FunctionsLists processing

1. ?*liste*

2. (create$ a b c d)

3. (length$ ?*liste*)

4. (first$ ?*liste*)

5. (rest$ ?*liste*)

6. (nth$ 2 ?*liste*)

7. (member$ b ?*liste*)

1. (a b c d)

2. (a b c d)

3. 4

4. (a)

5. (b c d)

6. b

7. 2

herzberg.ca.sandia.gov/jess/docs/70/functions.html

(defglobal ?*liste* = (create$ a b c d))

31

Institut Mines-Télécom

FunctionsLists processing

1. (insert$ ?*liste* 2 #)

2. (insert$ ?*liste* 2 ?*liste*)

3. (delete$ ?*liste* 2 3)

4. (subseq$ ?*liste* 2 3)

5. (replace$ ?*liste* 2 3 #)6. (subsetp (create$ b c) ?*liste*)

7. (implode$ ?*liste*)

8. (explode$ "a b c d")

1. (a # b c d)

2. (a a b c d b c d)

3. (a d)

4. (b c)

5. (a # d)

6. TRUE

7. "a b c d"

8. (a b c d)

32

Institut Mines-Télécom

SyntaxDD modification

� Domain Database creation(deffacts deffacts-name ["Documentation comment"] (fact)* )

� Add new facts

(assert < RHS-pattern>)

� Delete facts

(retract <fact-index-or-fact-address>+)

� Modify the value of slots

(modify <fact-index-or-fact-address> < RHS-slot>*)

33

Institut Mines-Télécom

RuleDeclaration

(defrule rule-name

["Documentation comment"]

[(declare (salience value)

(conditional element)*

=>

(function call)*

)

34

Institut Mines-Télécom

Matching

Condition

� Pattern-Conditional Element

Structure with constant(s), wildcard(s) and/or variable(s)1. Constant: symbolic or (alpha-) numerical data

2. Wildcard: monovalued ( ? ) or multivalued ( $? )

3. Variable: monovalued ( ?toto ) or multivalued ( $?titi )

� Pattern matching: compare CE and facts 1. Constants are equals to themselves

2. Wildcards are unified to data that are at the same position

3. Free variables are unified to data that are at the same position

4. Linked variables are compared with data that are at the same position

35

Institut Mines-Télécom

Matching

complex operators

(or <conditional element>+)

(and <conditional element>+)

(not <conditional element>)

(exists <conditional element>)

(test <conditional element>+)

(forall <conditional element> <conditional element>+)

36

Institut Mines-Télécom

MatchingSetting

� Deftemplate

• (declare (slot-specific TRUE | FALSE))

� Defrule

• (declare (no-loop TRUE | FALSE))

37

Institut Mines-Télécom

Conflict Resolution

Priority

� Principle

• A priority is declared for the rules

• Declaration

─ (declare (salience <priority>))

• Setting

─ Default value: 0.

─ Values interval: [-10 000; 10 000]

38

Institut Mines-Télécom

JESS et JAVA

39

Institut Mines-Télécom

IntegrationNull

� Executionjava –classpath jess.jar jess.Main

� Commandes• (batch <nom fichier>)

• (reset)

• (run [<integer>])

• assert; retract; modify

� There is no access to java objects

40

Institut Mines-Télécom

Integration

Weak

� A rule-based system is used by a java object.

� Package: jess.*;

� Class: Rete, Fact,

� API (Rete):

• run(); reset();

• assertFact(Fact f); retract (Fact f);

• executeCommand(“ command jess ");

41

Institut Mines-Télécom

IntegrationWeak

� Addition of facts in DD

• Jess API─ Fact creation

• Constructor: Fact(“name", Expert system reference)

─Slots

• Single slot

o setSlotValue("slot name", Value)

• Multi slot,

o setSlotValue("_ _data", new Value(<list referene>, RU.LIST))

─ Fact addition

• Method: assertFact of Rete

• With command line─Method executeCommande("command")

42

Institut Mines-Télécom

Integration

Strong

� Expert system is used by java objects and reciprocally

� Package Importation• (import mypackage.*)

� Java class use• Declaration

─ (defclass <tag> <java class name> [extends <tag>])

• Instance addition─ (definstance <tag> < java object> [static|dynamic])

• Methode call─ (call (<external-address>| <string-expression>) <string-expression> <call-

arguments>+)

43

Institut Mines-Télécom

Expert SystemConclusion

� Advantages• Expressibility

• Simplicity of inference procedures

• Modifiability*

• Explainability

� Disadvantages

• Difficulties in expressibility

• Undesirable interactions among rules

• Difficult debugging

• Expert Systems are expensive to design & maintain

• Slow

• Expertise can be hard to extract from humans

44