Theme 2-3 Knowledge Information Processing
Subject Learning how to develop knowledge bases or problem solving systems using OPS5 production system. Learning how to develop problem solving systems using C language Learning about a difference between concepts of declarative programming and concepts of procedural programming.
About OPS5 For constructing production systems. Production system is the tool for constructing expert systems, that is a substitute of experts. The first coming of ops5 is 1970s. The feature of ops5 is very poor. Declarative programming language.
Declarative Programming ant. Procedural Programming Process sequential processes in order. Such as C, Basic, etc. Declarative Programming: User will declare rules to solve a problem. This concept is familiar with the knowledge used in A.I. It has been used in the research field of AI.
Image Procedual Process commands in order Declarative Each rules are independent. When rule’s conditions are satisfied, the rule The order is not defined. command1 rule1 command2 rule2 command3 rule3
OPS5’s archtecture OPS5 consists of 3 parts. Match WM and PM, then execute the rule. Inference Engine (Matching & Rule Execution) Working Memory (Store Variables or status, temporary) Production Memory(Store Rules) It corresponds to human’s short-term memory It corresponds to human’s long-term memory
Operation of OPS5 OPS5 repeats following operations until the goal status is satisfied. Matching WM and PM, then select rules which conditions are satisfied.(Condition Matching) Choose only one rule from rules selected in above process. (Conflict Resolution) Execute the rule. After execution, status or values in WM will be changed. Then, back to 1. (Execution)
Let’s try to execute a sample. Please refer chap.6 and chap.7 of the textbook. 第6章「コンパイラの設定」 Read the chapter and setup the ops5 compiler. 第7章「例題1」 Input the sample program and compile, then execute.
Image of Example.1 Ball is comming Watching… If ball is red colored, Paint it blue. Watching… Watching… If ball is blue colored, Paint it white If ball is white colored, It is a goal.
Grammar of OPS5
Knowledge Expression Rules(in Production Memory) Represents Knowledge Data(in Working Memory) Represents variable factors
Data expression Data consists of “Class Name” and pairs of “Attribute Name” and “Attribute Value”. Class Name:Name of the data (Like as a structure name of C) Attribute Nam:Name of the parameter (A member name of a structure) Attribute Value:Value of the parameter (A value of member ) Format: (ClassName ^attr1 value1 ^attr2 value2 ……. )
Examples of data Ex.1 (Weather ^place Kanazawa ^weth rain ^temp 18 ^hum 80) Data related weather: It represents weather, temperature and humidity in Kanazawa. Ex.2 (Weather ^place Tokyo ^weth clear ^temp 22 ^hum 30) Data related weather: It represents weather, temperature and humidity in Tokyo.
Rule Expression Rules are represented in IF〜THEN… structure. Format of rule: (p rulename ー> ) Condition part Command part Describe conditions and commands in before and after a arrow (-->).
Condition description Condition part consists of condition elements. Condition element describes conditions to be satisfied by data in Working Memory. Format is like as data format. (ClassName ^attr predicate ^attr predicate ………………) Replace “value” by “predicate” in data format. “Predicate” means a condition for value to satisfy.
Example of condition element (Weather ^place <P> ^weat clear ^temp { >= 18 <= 22} ^hum {<H> < 80} ) Describe a condition to be satisfied by attribute value, such as “clear”. (Constant) Multiple conditions are represented putting “{” and “}” around conditions. All conditions must be satisfied. (Conjunction) A letter surrounded “<” and “>” is condition variable, such as <P>, <H>. Any values satisfy the condition. Meanings of the condition element above. Is there the data in the WM which ClassName is “Weather” and, the value of attribute “place” is arbitrary, the value of attribute “weat” is “clear”, the value of attribute “temp” is more than or equal to 18 and less than or equal 22, the value of attribute “hum” is arbitrary and less than 80
Example of condition element (2) (Student ^name <N> ^class << 1 2 >> ^score > 80 ) The meaning of the condition element. Is there the data in the WM which ClassName is “Student” and, the value of attribute “name” is arbitrary, the value of attribute “class” is “1” or “2” (disjunction) the value of attribute “score” is more than 80.
Command Part In the command part, commands executed when all condition elements in the condition part are satisfied is described. OPS5 has some kinds of command, we should combine these command. (The number of command is only 6 or 7.) Mainly, commands are make, reduce and modify data, and print texts.
Examples of command Make data(Make new data and store it in WM) 例:(make weather ^place <P> ^weat clear ^temp 15 ^hum <H>) Remove data(remove the data that satisfies condition element) 例:(remove 3) Modify data(modify the data that satisfies condition element) 例:(modify 2 ^temp (accept) ^hum 50) Calculation 例:(compute <H> + 1)
Example of a Rule Caution (p sample-rule (Weather ^place <X> ^weat clear ^hum >20) (Sight ^place <X> ^famous <Y> ^visit no) --> (make Plan ^go <X> ^subject <Y>) (write |Go to| <Y> |in| <X> (crlf)) ) Caution In the condition part, same variables must be same values. ー>Variable restriction In the command part, value of variable is inherited the value in the condition part. The scope of variable is in one rule.
Description of OPS5 program The program consists of 3 part. Declaration part Classes are declared in this part. (literalize ClassName AttrName AttrName …) Startup Rule(Initialize) The rule executed at first. This rule is used for initializetion. Rule Describe user’s rules. Please refer sample programs for details.
cmd filename (.l is not needed) Others An extention of program is “.l” How to compile, cmd filename (.l is not needed) After completion of compile, an executable file which name is “filename” is created. How to execute, ./filename
Example 2 There are 5 parts, size of them are different. Make a product using 3 parts of 5 kinds of parts. Smaller parts can put on bigger parts, but it is impossible bigger one on the smaller one. Which parts should be used to make a product.
Operation in the example 2 Rule to decide parts1 execution Executable rules Rule for parts2
Operation in the example 2 Rule for parts1 Rule for parts2 Rule for part3
Operation in the example 2 Rule for parts1 backtrack Rule for parts2 Execute the rule that is executable and not executed backtrack Rule for parts3 backtrack Repeat when no rule can be executed. It is dead-end.
Example 3 In the example 3, please complement rules.(Not all rule are described in the textbook, it is not enough to solve the problem. ) Please refer the textbook.
Image of ex.3 Red or white ball will be passed to someone, A-E. A B E Persons will pass the ball to next person. If the color is red, pass it to right side person, otherwise to left side person. C D
Image of ex.3 A B E C D
Image of ex.3 A B E C D
Image of ex.3 A B E C D
Image of ex.3 A B E C D
Image of ex.3 A If it is 2nd time to get the ball, put the ball on the table. B E C D
Image of ex.3 A B E C D It is finished when the ball is on the table.