Académique Documents
Professionnel Documents
Culture Documents
Lecture 2: Knowledge
E. Tyugu Spring 2003
Enn Tyugu 1
Prolog
Prolog is a logic-based programming language, i.e. a language for logic programming. Its statements are Horn clauses. Examples: A program: ancestor(X,Z):-parent(X,Z). ancestor(X,Z):-parent(Y,Z),ancestor(X,Y). A program: state(1,0). state(S,T):-state(S1,pred(T)), nextstate(S,S1,pred(T)). nextstate(X+1,X,T). A goal: ?- state(X,3).
Enn Tyugu
Prolog interpreter
prog - program to be executed; goals - list of goals, which initially contains the goal given by a user;
Enn Tyugu
Prolog interpreter
A.1.3: exec(prog,goals,success)= if empty(goals) then success( ) else goal:= head(goals); goals:= tail(goals); L: {rest:= prog; while not empty(rest) do U:=unifier(goal,head(head(rest)); if U nil then goals1:= (apply(U,tail(head(rest))); exec(prog,goals1,success); if success then exit L fi fi; rest:=tail(rest); od; failure( ) }; exec(prog,goals, succes) fi Enn Tyugu
Semantic networks
Linguists noticed long ago that the structure of a sentence can be represented as a network. Words of the sentence are nodes, and they are bound by arcs expressing relations between the words. The network as a whole represents in this way a meaning of the sentence in terms of meanings of words and relations between the words. This meaning is an approximation of the meaning people can assign to the sentence, analogous in a way to other approximate representations of the meaning, for instance, how floating point numbers represent the approximate meaning of real numbers.
Enn Tyugu
Example
John must pick up his report in the morning and have a meeting after lunch. After the meeting he will give the report to me.
before morning at the time lunch after
give
Example continued
Inferences can be made, depending on the properties of the relations of a semantic network. Let us consider only time relations of the network in our example, and encode the time relations by atomic formulas as follows:
before(lunch,morning) after(morning,lunch) after(lunch,have a meeting) after(have a meeting,give) at-the-time(morning,pick up)
Enn Tyugu
= general knowledge
= specific knowledge
Example continued
Inference rules: before(x,y) before(y,z) before(x,z) after(x,y) before(y,x) at-the-time(x,z) before(y,z) before(y,x) Applying these rules, we can infere after(lunch,have a meeting) before(have a meeting,lunch) at-the-time(pick up,morning) before(lunch,pick up)
and
before(lunch,morning) etc.
Enn Tyugu 8
Frames
1. The essence of the frame is that it is a module of knowledge
about something which we can call a concept. This can be a situation, an object, a phenomenon, a relation.
2. Frames contain smaller pieces of knowledge: components, attributes, actions which can be (or must be) taken when conditions for taking an action occur. 3. Frames contain slots which are places to put pieces of knowledge in. These pieces may be just concrete values of attributes, more complicated objects, or even other frames. A slot is being filled in when a frame is applied to represent a particular situation, object or phenomenon.
Enn Tyugu
Inheritance
An essential idea developed in connection with frames was inheritance. Inheritance is a convenie way of reusing existing knowledge in describing new frames. Knowing a frame f, one can describe a new frame as a kind of f, meaning that the new frame inherits the properties of f, i.e. it will have these properties in addition to newly described properties described. Inheritance relation expresse very precisely the relation between super- and subconcepts.
ideas even ts actions state s thing s abstra ct th ings polygons triangles quadrangles parallelograms re ctan gles rh omb uses
Enn Tyugu
10
Default theories
A default has the following form
Enn Tyugu
11
Examples
1. bird(x): flies(x)
--------------------flies(x)
Enn Tyugu
12
Enn Tyugu
13
Rules
Rules are a well-known form of knowledge which is easy to use. A rule is a pair
(condition, action) which has the meaning: "If the condition is satisfied, then the action can be taken." Also other modalities for performing the action are possible - "must be taken", for instance.
Enn Tyugu
14
Using rules
Let us have a set of rules called rules and functions cond(p) and act(p) which select the condition part and action part of a given rule p and present them in the executable form. The following is a simple algorithm for problem solving with rules:
A.1.5
while not good do found := false; for p rules do if cond(p) then act(p); found:=true fi od; if not found then failure fi od
Enn Tyugu 15
Decision trees
A simple way to represent rules is decision tree: a tree with nodes for attributes and arcs for attribute values. Example:
legs two four no bird no man
hands
yes furry yes monkey
furry no
table
yes animal
Enn Tyugu
16
Rete algorithm
Rete algorithm uses a data structure that enables fast search of applicable rules. We shall consider it in two parts: knowledge representation, knowledge management (i.e. introduction of changes into the knowledge base). Any rule that is reachable in the Rete graph (see below) via nonempty relation nodes can be fired.
Rete algorithm is used in JESS (Java Expert System Shell) and its predecessor CLIPS (both developed in NASA.)
Enn Tyugu
17
2. patterns, e.g.
(goal ?x simplify) (expr ?y 0 ?op ?a2) (parent ?x ?y) ...
Enn Tyugu
18
expr
expr * y
2
expr + y
3 5
...
x y e1 3 e2 5
*** R1
R2
Enn Tyugu
19
root predicate names layer patterns layer - alpha nodes (with one input) beta-nodes (with two inputs) rules layer - one node for every rule
Enn Tyugu 20
Enn Tyugu
21
Enn Tyugu
22
Enn Tyugu
23
Plausibilities
A.1.6 c:=1; while not good do x:=cm; for p rules do if cond(p) and c(p) > x then a:=act(p); x:=c(p) fi od; c:=c*x; if c > cm then a else failure fi od; success
Enn Tyugu 24
KNOWLEDGE SYSTEMS
Enn Tyugu
26
Exercise
Facts: parent(pam,bob).
parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim).
Questions and answers: ?- parent(bob,pat). ?- parent(liz,pat). ?- parent(X,liz). ?- parent(bob,X). ; ; yes no X = tom X = ann X = pat no
Enn Tyugu 27
Bibliography
Bratko, I. (2001) Prolog Programming for Artificial Intelligence. Addison Wesley. http://herzberg.ca.sandia.gov/jess/docs/ (Jess ja rete algoritm) Genesereth, M., Nilsson, N. (1986) Logical Foundations of Artificial Intelligence. Morgan Kauffmann.
Enn Tyugu
28