Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Building a Knowledge Base with VPExpert (VPX.exe) see also: vpxguide.doc.

Similar presentations

Presentation on theme: "1 Building a Knowledge Base with VPExpert (VPX.exe) see also: vpxguide.doc."— Presentation transcript:

1 1 Building a Knowledge Base with VPExpert (VPX.exe) see also: vpxguide.doc

2 2 Structure of a rule-based expert system development software

3 3 Sample Problem A business uses the following temperature control policy in a work environment. In spring, summer, autumn and winter during business hours the thermostat settings are 20, 24, 20 and 18C respectively. In those seasons out of business hours the settings are 15, 27, 16 and 14C respectively. The spring months are September, October and November; summer months are December, January and February; autumn months are March, April and May, and winter months are June, July and August. The weekdays are Monday to Friday, and, Saturday and Sunday are weekend days. Business hours are between 9 am and 5 pm.

4 4 Construct a knowledge base representing this policy. 1.Extract the goals 1.Decide on the facts 1.Construct the rules

5 Structure of a Knowledge Base 5 Creating an expert system with VP Expert is basically a question of entering a knowledge base which consists of three parts: ACTIONS RULES QUERY STAEMENTS

6 6 Goals and the Actions Block The FIND statement expresses the goal. The basic form of this statement is: FIND variable This statement activates the inference engine, causing it to consult the knowledge base of rules until a value is found for the variable. FIND Thermostat_setting

7 7 The Actions Block 1.The ACTIONS block consists of statements which control the actions of the shell. 2.These statements are executed in the order in which they appear. 3.In effect, the ACTIONS block is the `code' which controls the execution of the inference engine.

8 8 Example: Actions Block ACTIONS DISPLAY "Thermostat Setting~" FIND Thermostat_setting DISPLAY "Setting is {#Thermostat_setting}"; Note that it begins with the word ACTIONS and terminates with a semicolon (no semicolons between statements). If you want to make sure that the user has time to read a message before it disappears from the screen, insert a "~" as the last character in the message.

9 9 Production Rules The basic form of a rule is as follows: RULE rulename IF antecedent THEN consequent; Every rule must have a unique name (up to 40 chars in length) after the word RULE.

10 10 Example Rule RULE Diagnosis_of_measles IF Diagnosis = measles THEN Treatment = penicillin; In this case, Diagnosis and Treatment are variables, and measels and penicillin are potential values for those variables. In other words, this rule states that if Diagnosis has the value measels we may then assign Treatment the value penicillin.

11 Search Algorithm 11 If the inference engine was currently trying to use this rule to FIND a value for the variable Treatment, it would: Check whether Diagnosis had already been assigned a value. If not, it would use the rules to try to FIND a value for Diagnosis, returning to this rule once it has done so. If the value of Diagnosis is measles, then Treatment is assigned the value penicillin. At that point, the inference engine does no more work n FINDing a value for Treatment. If Diagnosis has some other value (including unknown), then the rule fails, and the inference engine must search for some other rule to give Treatment a value (if there is none, then Treatment is assigned the value unknown).

12 12 Facts Variables representing basic facts which do not appear as the consequent of some rule in the knowledge base (that is, are leafs in the deduction tree), are considered potential questions for the user. If the inference engine attempts to FIND such a variable, the user will be prompted for its value. This is done with ASK and CHOICES statements.

13 13 Ask Statement The form of the prompt for a variable is defined by an ASK statement. It has the form: ASK variable: "prompt"; For example: ASK Month : "Which month is it?"; As with any other program, these prompts should be informative -- that is, they should tell the user how to gather and enter the information.

14 14 Choices Statement CHOICES variable: list of values; For example: CHOICES Month : july, august; A menu is printed out when the question is ASKed. Note that if there is no CHOICES statement for a variable, the user will have to type in a value at the cursor after the prompt (this is how numeric variables are usually handled).

15 15 Rule 2 IF day = workday AND Time = between_9am_and_5pm THEN Operation = business_hours; Rule 3 IF Month = july THEN Season = winter; Rule 4 IF Season = winter AND Operation = business_hours THEN Thermostat_setting = 18_degrees; More rules

16 16 Simple Premises The IF part of a rule consists of one (or more) simple premises of the form: variable relational_operator value where relational_operator is one of the following: =is equal to <>is not equal to (used instead of NOT by VP-Expert) is greater than >=is greater than or equal to The latter four operators are primarily used for numeric values

17 17 Booleans RULE flu IF throat = sore AND temperature = high OR temperature = very_high THEN Diagnosis = flu; is interpreted as (throat = sore) AND (temperature = high OR temperature = very_high).

18 18 Variables VP-Expert does not allow you to declare your variables. It needs some way to tell a variable (such as diagnosis) from a value (such as measles) when used on the right side of the expression. This is done by enclosing the variable on the right side of the expression in parentheses. For example: RULE own_pharmacy IF pharmacy_used = ours THEN perscription = (treatment);

19 19 Multiple answers to queries The inference engine for VP-Expert will stop once it has found the first value of a variable it is trying to FIND. It is possible, however, to force it to find all values for variables instead. This is done with the PLURAL statement (which must be placed before the ACTIONS block): PLURAL: thermostat_setting; In the a medical knowledge base you wish to make treatment and diagnosis plural

20 20 PLURAL inputs It is also possible to set up your ASK statements to allow the user to choose more than one option from the menu by making that variable PLURAL. This is often faster for the user than having to answer multiple questions. For example: PLURAL: symptoms;... ASK symptoms: "Choose all symptoms that you have."; CHOICES symptoms: sore_throat, spots, rash, none; The user can then press ENTER by each one which holds, and press END to confirm the list.

21 21 !Thermostat Example ACTIONS DISPLAY "Thermostat Setting~" FIND Thermostat_setting DISPLAY "Setting is {#Thermostat_setting}"; Rule 1 IF Today = monday THEN day = workday; Rule 2 IF day = workday AND Time = between_9am_and_5pm THEN Operation = business_hours; Rule 3 IF Month = july THEN Season = winter; Rule 4 IF Season = winter AND Operation = business_hours THEN Thermostat_setting = 18_degrees; ASK Month : "Which month is it?"; CHOICES Month : july, august; ASK Time : "What time is it?"; CHOICES Time : between_9am_and_5pm, before_9am; ASK Today : "What day is it"; CHOICES Today : monday, tuesday;

22 22 Explanation and the BECAUSE statement RULE measles IF temperature = very_high AND spots = yesAND innoculated <> yes THEN Diagnosis = measles BECAUSE "A high temperature and spots are the usual symptoms of measles"; The text contained if the BECAUSE statement is printed if this rule is involved in either a how or why query.

23 23 Extracting Explanations for a Consultation VP-Expert also allows you to see explanations of how a variable was set, or why a question was asked. This can be done when the program is running by pressing the / key (which halts execution temporarily) and then selecting the desired option from the menu. If how is selected, VP-Expert will then provide a menu of the variables used in the program. It will then print the BECAUSE part (see below) of the rule used to give that variable its value (if any). If why is selected, VP-Expert will print the BECAUSE part (see below) of the rule responsible for causing the current question to be asked. Chest congestion and nasal congestion without the sore throat can also indicate pneumonia.” IF chest_congestion = yes AND nasal_congestion = yes THEN Diseases = pneumonia CNF 85; BECAUSE Chest and Nasal congestion are indicative of pneumonia

24 24 Alternate Explanation It is perhaps more user friendly to print explanations directly using DISPLAY statements: RULE measles IF temperature = very_high AND spots = yes AND innoculated <> yes THEN Diagnosis = measles DISPLAY "Your extremely high temperature and spots indicate a case of measles."

25 25 Confidence Factors Uncertainty in VP-Expert is represented in terms of ``confidence factors'' (abbreviated CNF), which may take on any value between 0 and 100. These confidences apply to the assignments done by the inference engine -- for example, something of the form diagnosis = flu CNF 80 means that the system believes that diagnosis has the value measles with certainty of 80 out of 100 RULE flu IF temperature > 99 THEN diagnosis = flu CNF 80

26 26 Certainty in VPExpert Combining certainties of rules and premises If both the premise (that is, the ``IF'' part) of a rule and the rule itself are uncertain, then the confidence of the conclusion of the rule is: CNF of premise * CNF of rule / 100 VPExpert uses a minimum to compute the confidence of a conjunction and To compute the confidence of a disjunction cf1 + cf2 -(cf1 * cf2)

27 27 Truth Thresholds This is controlled with the TRUTHTHRESH value in VP-Expert. If the confidence in the premise of a rule is less than TRUTHTHRESH, then it fails and assigns no values. For example, given the rule IF diagnosis = measles THEN treatment = penicillin; If TRUTHTHRESH is 40, and the confidence in the premise diagnosis = measles is 35, then this premise is considered to be FALSE, and the assignment treatment = penicillin is not done. The default value of TRUTHTHRESH is 50. It can be changed in the ACTIONS block or a rule conclusion. For example, to change the threshold to 40, you would use the statement: TRUTHTHRESH = 40

Download ppt "1 Building a Knowledge Base with VPExpert (VPX.exe) see also: vpxguide.doc."

Similar presentations

Ads by Google