m1/m4

34
M1/M4 CIS 479/579 Bruce R. Maxim UM-Dearborn

Upload: matia

Post on 10-Feb-2016

30 views

Category:

Documents


0 download

DESCRIPTION

M1/M4. CIS 479/579 Bruce R. Maxim UM-Dearborn. What is it?. Expert system shell for developing medium size applications Written in C/C++ Allows interface to external functions written in C/C++ and VB Allows access to database applications as well. Features. Symbolic Variables - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: M1/M4

M1/M4

CIS 479/579Bruce R. MaximUM-Dearborn

Page 2: M1/M4

What is it?

• Expert system shell for developing medium size applications

• Written in C/C++• Allows interface to external functions

written in C/C++ and VB• Allows access to database applications

as well

Page 3: M1/M4

Features• Symbolic Variables • Certainty factors• Backward chaining (mostly) • Limited forward chaining allowed (pre-suppositions)• Rule order used for conflict resolution• Cache (WM) manipulation allowed• Symbolic List processing • Debugging Environment • Explanation Facilities • Meta knowledge

Page 4: M1/M4

How does M1 find work?

M1 seeks to determine values found in a goal or initialdata statement

1. Obtain value of expression computed by M1

2. Look for value already in cache3. Inference rules (searching and

matching)4. Prompts user for value if first 3 fail

Page 5: M1/M4

Examples• Goal statement

goal = wine.

• Initialdata statementinitialdata = [preferred-color, preferred-body].

• Rulerule-5: if has-sauce = yes and sauce = cream then best-body = medium and best-body = full.

Page 6: M1/M4

Getting Started

• You need copies of the files m1.exe and m1.cfg

• You may find it helpful to examine the knowledge bases “wine”, “vine”, “cwine”

• There is also an M1 Short Guide written by a former student posted on the course web page

Page 7: M1/M4

Syntax

• Use lowercase for everything except variables

• Identifiers begin with characters, may contain numbers and hyphens

• To comment use /* */• Rules can have multiple antecedents

and make use of “and”, “or”, “not”• Rules can have multiple consequents

Page 8: M1/M4

Certainties

• Similar to ad hoc approach described earlier

-100 < CF < 100100 completely certain20 default threshold for true0 neutral-100 completely false

Page 9: M1/M4

Certainties

• If antecedents do not have an explicit CFif x = y then z = w cf 50M1 uses 20 as threshold for truth of cache

expression “x = y” and adds “z = w” to cache• If antecedents have explicit CF

if x = y cf 30 then z = w cf 50M1 uses 30 as threshold for truth of cache

expression “x = y” and adde “z = w” to cache

Page 10: M1/M4

Certainties

• What CF value is assigned to “z = w” ?• We take the product of the antecedent

certainty and the rule certainties• If CF = 20 for “x = y” and CF = 50 in rule

consequent thenCF = (CF 20 * CF 50) = (0.2 * 0.5) = (0.1) = 10

Page 11: M1/M4

Certainties

• For conjunction, use the minimum of all the antecedent CF valuesif x = y and a = bthen z = w

Page 12: M1/M4

Certainties

• For disjunction, we use the CF value of the antecedent that triggered the rule or the maximum of all antecedent CF values if x = y or a = bthen z = w

Page 13: M1/M4

Meta-facts• Multivalued (needed with CF)

multivalued(sauce). • Questions

question(sauce) = 'What kind of sauce does the meal have?'.

• Answerslegalvals(sauce) = [spicy, sweet, cream].

• Automatic menuautomaticmenu(sauce).

• Enumerated answersenumeratedanswers(sauce).

Page 14: M1/M4

Meta-facts

• Explanation

rule-16: if the main component = poultry and has turkey = no then the best color = white cf 90 and the best color = red cf 30. explanation(rule-16) = [nl, 'For poultry dishes, I recommend white wines. Turkey, ', 'however, goes very well with some red wines.', nl].

Page 15: M1/M4

Wine has lots of similar rulesrule-14: if best-body = light then recommended-body = light. rule-15: if best-body = medium then recommended-body = medium. rule-16: if best-body = full then recommended-body = full.

Page 16: M1/M4

Wine has lots of similar rulesrule-21: if best-color = red then recommended-color = red. rule-22: if best-color = white then recommended-color = white.

Page 17: M1/M4

Wine has lots of similar rulesrule-26: if best-sweetness = dry then recommended-sweetness = dry. rule-27: if best-sweetness = medium then recommended-sweetness = medium. rule-28: if best-sweetness = sweet then recommended-sweetness = sweet.

Page 18: M1/M4

Using variables in Vine we can replace 27 rules with these 3.

v-rule-1: if best-X = V then recommended-X = V. v-rule-2: if best-X is unknown and preferred-X = V then recommended-X = V. v-rule-3: if best-X is unknown and preferred-X is unknown and default-X = V then recommended-X = V.

Page 19: M1/M4

Default values are used when M1 can’t find values

noautomaticquestion(default-X). default-body = medium. default-color = red cf 50.default-color = white cf 50. default-sweetness = medium.

• Sometimes we need to turn off automatic question generation to prevent user from entering values and allow M1 to skip searching the rule-base

Page 20: M1/M4

Wine has lots of specific rulesrule-33: if recommended-color = red and recommended-body = medium and recommended-sweetness = medium or recommended-sweetness = sweet then wine = gamay.

Page 21: M1/M4

Vine makes use of tables to reduce number of rules

multivalued(wine(COLOR,BODY,SWEETNESS)).

v-rule-4: if recommended-color = C and recommended-body = B and recommended-sweetness = S and wine(C,B,S) = W then wine = W.

Page 22: M1/M4

Sample Table Entrieswine(red,medium,medium) = gamay.wine(red,medium,sweet) = gamay.wine(white,light,dry) = chablis.wine(white,medium,dry) = 'sauvignon blanc'.wine(white,light,medium) = riesling.wine(white,light,sweet) = riesling.wine(white,medium,medium) = riesling.wine(white,medium,sweet) = riesling.wine(red,light,ANY) = valpolicella.wine(red,ANY,dry) = 'cabernet sauvignon'.wine(red,ANY,dry) = zinfandel.wine(red,ANY,medium) = 'cabernet sauvignon'.wine(red,ANY,medium) = zinfandel.wine(red,medium,medium) = 'pinot noir'.wine(red,full,ANY) = burgundy.

Page 23: M1/M4

Variable Scope

• Variables restricted to the rule itself• M1 puts facts (e.g. recommended-color =

preferred-color) in cache not values• This means we have to write

v-rule-2: if best-X is unknown and preferred-X = V then recommended-X = V.

and notbad-2: if best-color is unknown and then recommended-color = preferred-color.

Page 24: M1/M4

Comparing Numeric Facts

• Correctif age N and N > 20

then category = adult.

• Incorrectif age > 20then category = adult.

Page 25: M1/M4

Arithmetic• Correct

if distance = D and fare-mile = M and

M * D = Rthen total-fare = R.

• Incorrecttotal-fare = distance * fare-mile.

Page 26: M1/M4

Additional Features

• User defined syntax lets you skip hyphensprefix best.prefix has. infix to. postfix ends.prefix main. infix with.prefix preferred.

• Assigning string to identifierbegin-message = [nl, nl, ‘hello’, nl, nl].

• Nocache prevents M1 from saving factnocache(begin-message).

• Presupostionpresupposition(sauce) = has-sauce.

Page 27: M1/M4

Cwineinitialdata = [begin the consultation, end the consultation ].question(begin signal) = [nl,'Are you ready to begin the consultation (y/n)?']. legalvals(begin signal) = [yes,no]. rule-1: if begin message = M and display(M) and begin signal and display('\f') then begin the consultation. rule-2: if not begin signal and display("Issue 'go' command when ready to begin.") and do(abort) then begin the consultation.

Page 28: M1/M4

Cwinerule-3: if the wine for cycle N is known and user informed of selection N and user happy with selection N then consulting ends with cycle N. rule-4: if the wine for cycle N is unknown and display(['Sorry, not able to recommend any wines.', nl]) then consulting ends with cycle N.

rule-5: if positiveinteger = I and consulting ends with cycle I and display([nl,nl,'The consultation is over.', nl]) then end the consultation.

Page 29: M1/M4

Cwinerule-30: if listof(the wine for cycle N) = [ONLYONE] and display([nl,'The best wine for this meal is ', ONLYONE, '.', nl,nl]) then the winelist for N is displayed.

 rule-31: if listof(X,ordered(the wine for cycle N) = X) = [ONE,TWO] and display([nl,'The best wines for this meal are ', ONE, ' and ', TWO, '.', nl,nl]) then the winelist for N is displayed.

Page 30: M1/M4

Cwinequestion(user happy with selection N) = ['Are you happy with these?']. legalvals(user happy with selection N) =

[yes,no]. rule-33: if the description for N is given and the winelist for N is displayed then user informed of selection N.

Page 31: M1/M4

Cwinerule-9: if M > 1 and M - 1 = N then previouscycle to M = N.

question(the new value for X for cycle N) = ['What ', X ,' would you prefer?']. legalvals(the new value for color for cycle N) = [red, white]. legalvals(the new value for body for cycle N) = [light, medium, full]. 

Page 32: M1/M4

Cwine legalvals(the new value for sweetness for cycle N) = [dry, medium, sweet]. automaticmenu(the new value for ANY for cycle N). enumeratedanswers(the new value for ANY for cycle N).

Page 33: M1/M4

Cwinerule-26: if previouscycle to M = N and not(the fault with cycle N = X) and the recommended X for cycle N = V then the recommended X for cycle M = V.  rule-27: if previouscycle to M = N and the fault with cycle N = X and the new value for X for cycle M = V then the recommended X for cycle M = V.

Page 34: M1/M4

Cwinerule-28: if the recommended color for cycle N = C and the recommended body for cycle N = B and the recommended sweetness for cycle N = S and wine(C,B,S) = W then the wine for cycle N = W.

rule-29: if the recommended color for cycle N = white and the recommended body for cycle N = full and feature = spiciness then the wine for cycle N = gewuerztraminer.