Study Notes on building an Expert System Using Prolog (3)
Source: Internet
Author: User
Iii. Backward link non-deterministic reasoning in the real world, things are usually not a simple logical relationship, but a non-deterministic relationship related to experts' experience intuition. Clam, an Expert System for post-link non-deterministic reasoning, has its own unique rule format and inference engine. (1) confidence level (certainty factors)
The most common way to deal with non-deterministic problems is to add confidence to each piece of information in the system. The inference engine automatically updates and maintains the confidence level and uses it as the result of inference. A clam use case: the confidence level (CF) value is-100 (full false) to + 100 (full true ). The following is a small knowledge base in Clam used to diagnose why a car is not ignited. It describes some methods for processing uncertainty. Goal problem. rule 1if not turn_over and battery_badthen problem is battery. rule 2if lights_weakthen battery_bad CF 50. rule 3if radio_weakthen battery_bad CF 50. rule 4if turn_over and smell_gast?problem is flooded CF 80. rule 5if turn_over and gas_gauge is emptythen problem is out_of_gas CF 90. rule 6if turn_over and gas_gauge is lowthen problem is out_of_gas CF 30.ask turn_overmenu (yes no) Prompt 'Does the engine turn over? '. Ask lights_weakmenu (yes no) prompt' are the lights weak? '. Ask radio_weakmenu (yes no) Prompt' is the radio weak? '. Ask smell_gasmenu (yes no) Prompt' Do you smell gas? '. Ask gas_gaugemenu (empty low full) Prompt' what does the gas gauge say? '. Non-deterministic rules the following is the consultation conversation between the user and the automotive Expert System: Consult, restart, load, list, Trace, how, exit: consultdoes the engine turn over?: Yesdo you smell gas?: Yeswhat does the gas gauge say? Emptylowfull: emptyproblem-out_of_gas-cf-90problem-flooded-cf-80done with problem note that this inference engine does not just find an answer as Prolog does, but rather find all reasonable answers and report the credibility of the answer. It can be seen that the confidence level is not a probability value, but simply gives a weight to the credibility of each answer. The user-defined confidence level can be placed into the system: consultdoes the engine turn over?: Yesdo you smell gas?: Yes CF 50 what does the gas gauge say? Emptylowfull: emptyproblem-out_of_gas-cfproblem-flooded-cf-40-90done with problem composite confidence level: consultdoes the engine turn over?: Noare the lights weak?: Yesis the radio weak?: Yesproblem-battery-cf-75done with problem this example uses 2 rules to determine the confidence level of "battery missing" is 75. Applicability of confidence level: ● rules with uncertain conclusions; ● rules with uncertain premise; ● rules with uncertain user input; ● rules with uncertain premise and conclusion; ● use uncertain information, update the uncertain data on the blackboard. ● set the known premise to uncertain. (2) Confidence Level of mycin
(3) Rule format
The internal rule format must be designed for self-built inference engines. The custom rule format must have at least two parameters: one is the premise (LHS), and the other is the conclusion (RHs ). To be more practical, add 3rd parameters, rule number or name. Therefore, the complete rule structure is: Rule (name, LHS, RHS ). conclusion RHS includes a target model and its corresponding confidence level. The premise of CF: RHS (goal, CF), LHS can include many sub-targets for affirming or denying RHS: LHS (goallist) the simplest way to represent a sub-object is to pair with "Attribute-value": Av (attribute, value). The two parameters are simple atoms. The complete rule structure is as follows: Rule (name, LHS ([AV (A1, V1), AV (A2, V2),...]), RHS (AV (ATTR, Val), CF )). the preceding rule 5 (Rule 5) is as follows: Rule (5, LHS ([AV (turns_over, yes), AV (gas_gauge, empty)]), RHS (AV (problem, flooded), 80 )). (4) inference engine
With fixed format rules, you need self-built inference engines to process them. Processing behaviors include: ● combining confidence; ● maintaining a Work Database (blackboard) and updating information as new evidence for reasoning; ● identifying all the specific information required by the user and saving it to the blackboard. The main predicates 3.1 are shown in: Working Database: fact (AV (A, v), CF). Find the value corresponding to the attribute, for example :? -Findgoal (AV (problem, x), CF ). the predicate must handle three cases: ● known "Attribute-value"; ● A predicate can infer "Attribute-value"; ● the predicate must ask the user. You can define a new predicate: askable (live, 'where does it live? '). The question to ask is live. The question is: 'where does it live? Then, you can write the predicate findgoal. Known attribute values: findgoal (AV (ATTR, Val), CF):-fact (AV (ATTR, Val), CF ),!. Ask the user about the attribute values: findgoal (AV (ATTR, Val), CF):-not fact (AV (ATTR, _), _), askable (ATTR, prompt ), query_user (ATTR, prompt ),!, Findgoal (AV (ATTR, Val), CF). The predicate query_user prompts the user to enter the attribute value and confidence level CF, and declares (saves) it as "fact ". This fact is used to call findgoal recursively. Query_user (ATTR, prompt):-write (prompt), read (VAL), read (CF), asserta (fact (AV (ATTR, Val), CF )). deduce the property value using rules: findgoal (goal, curcf):-FG (goal, curcf ). FG (goal, curcf):-rule (n, LHS (iflist), RHS (goal, CF), prove (iflist, tally), adjust (CF, tally, newcf), update (goal, newcf, curcf), curcf = 100 ,!. FG (goal, CF):-fact (goal, CF ). there are three new predicates in FG: ● prove-proves the LHS premise and gives its confidence level CF; ● adjust-combines the CF of LHS and the CF of RHS; ● Update-use a new conclusion to update the values of the existing working database. Prove (iflist, tally):-prov (iflist, 100, tally ). prov ([], tally, tally ). prov ([H | T], curtal, tally):-findgoal (H, CF), min (curtal, CF, Tal), Tal> = 20, prov (t, tal, tally ). min (X, Y, X):-x = <Y ,!. Min (X, Y, Y):-y = <X. after prove succeeds, adjust computes the combined CF Based on The rhs cf and the tally from the LHS. after the proof is successful, adjust the compound CF value. Adjust (CF1, CF2, CF):-X is CF1 * CF2/100, int_round (x, CF ). int_round (X, I):-x> = 0, I is INTEGER (x + 0.5 ). int_round (X, I):-x <0, I is INTEGER (X-0.5 ). then, the predicate update integrates known evidence with new evidence. The first parameter is the inferred "property-value" pair, and the second parameter is its cf. The new CF value returned when the third parameter is merged with CF. Update (goal, newcf, CF):-fact (goal, oldcf), combine (newcf, oldcf, CF), retract (fact (goal, oldcf )), asserta (fact (goal, CF )),!. Update (goal, CF, CF):-asserta (fact (goal, CF )). combine (CF1, CF2, CF):-CF1> = 0, CF2> = 0, x is CF1 + CF2 * (100-CF1)/100, int_round (X, CF ). combine (CF1, CF2, CF):-CF1 <0, CF2 <0, x is-(-CF1-CF2 * (100 + CF1)/100), int_round (X, CF ). combine (CF1, CF2, CF):-(CF1 <0; CF2 <0), (CF1> 0; CF2> 0), abs_minimum (CF1, CF2, OLAP ), X is 100*(CF1 + CF2)/(100-OLAP), int_round (x, CF ). negative CF value: Findgoal (not goal, NCF):-findgoal (goal, CF), NCF is-CF ,!. (5) Implement clam shell super:-repeat, write ('Consult, load, exit '), NL, write (': '), read_line (x ), doit (x), x = exit. doit (consult):-top_goals ,!. Doit (load):-load_rules ,!. Doit (exit ). call top_goals and start inference: top_goals:-top_goal (ATTR), top (ATTR), print_goal (ATTR), fail. top_goals.top (ATTR):-findgoal (AV (ATTR, Val), CF ),!. Top (_):-true. print_goal (ATTR):-nl, fact (AV (ATTR, x), CF), CF> = 20, outp (AV (ATTR, x), CF), NL, fail. print_goal (ATTR):-write ('done with '), write (ATTR), NL, NL. outp (AV (A, v), CF):-output (A, V, printlist), write (a-'cf '-CF), printlist (printlist ),!. Outp (AV (A, v), CF):-write (A-V-'cf'-CF ). printlist ([]). printlist ([H | T]):-write (H), printlist (t ). (6) English-speaking rules load_rules (F):-clear_db, see (F), lod_ruls, write ('rules' loaded'), NL, seen ,!. Lod_ruls:-repeat, read_sentence (L), process (L), L = EOF. Process (EOF ):-!. Process (l):-Trans (R, L, []), assertz (R ),!. Process (l):-write ('translate error on: '), NL, write (L), NL. clear_db:-Abolish (top_goal, 1), abolish (askable, 4), abolish (rule, 3 ).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.