Download presentation
Presentation is loading. Please wait.
Published byMarion Snow Modified over 8 years ago
1
1 Chapter 3 Knowledge Representation
2
2 Chapter 3 Contents l The need for a good representation l Semantic nets l Inheritance l Frames l Object oriented programming l Search trees l Combinatorial explosion l Problem reduction
3
3 The Need for a Good Representation l A computer needs a representation of a problem in order to solve it. l A representation must be: nEfficient – not wasteful in time or resources. nUseful – allows the computer to solve the problem. nMeaningful – really relates to the problem.
4
4 Semantic Nets l A graph with nodes, connected by edges. l The nodes represent objects or properties. l The edges represent relationships between the objects.
5
5 A Simple Semantic Net
6
6 Inheritance l Inheritance is the process by which a subclass inherits properties from a superclass. l Example: nMammals give birth to live young. nFido is a mammal. nTherefore fido gives birth to live young. l In some cases, as in the example above, inherited values may need to be overridden. (Fido may be a mammal, but if he’s male then he probably won’t give birth).
7
7 Frames l A frame system consists of a number of frames, connected by edges, like a semantic net. l Class frames describe classes. l Instance frames describe instances. l Each frame has a number of slots. l Each slot can be assigned a slot value.
8
8 Frames: A Simple Example
9
9 FOR EXPERT SYSTEMS l Advantage of frame based system over rule based system is that all the info is stored in one place.
10
10 inherited and overridden values l Frame Slot Slot value Mammal *number legs 4 Dog subclass Mammal Cat subclass Mammal Fido is a Dog number legs 3 Fang is a Cat
11
11 Multiple inheritance can lead to conflicts l Frame Slot Slot value Cheese is smelly Wrapped in foil is not smelly Cheddar is a Cheese is a Wrapped in foil
12
12 Procedures and Demons l A procedure is a set of instructions associated with a frame (or a slot). l The procedure can be run upon request. l A demon is a procedure that is run automatically, usually triggered by an event such as when a value is: nRead nWritten nCreated nChanged
13
13 Object Oriented Programming l Object oriented programming languages such as Java, C++. l Use ideas such as: ninheritance nmultiple inheritance noverriding default values nprocedures and demons l Languages such as IBM’s APL2 use a frame based data structure.
14
14 Example Implementation OOP Class animal { animal (); Eye *eyes; Leg *legs; Head head; Tail tail; }
15
15 Example Implementation OOP Animal an_animal = new animal(); Class dog : animal { bark(); }
16
16 Search Trees l Semantic trees – a type of semantic net. l Used to represent search spaces. l Root node has no predecessor. l Leaf nodes have no successors. l Goal nodes (of which there may be more than one) represent solutions to a problem.
17
17 Search Trees: An Example l A is the root node. l L is the goal node. l H, I, J, K, M, N and O are leaf nodes. l There is only one complete path: l A, C, F, L
18
18 Example: Missionaries and Cannibals l Three missionaries and three cannibals l Want to cross a river using one canoe. l Canoe can hold up to two people. l Can never be more cannibals than missionaries on either side of the river. l Aim: To get all safely across the river without any missionaries being eaten.
19
19 A Representation l The first step in solving the problem is to choose a suitable representation. l We will show number of cannibals, missionaries and canoes on each side of the river. l Start state is therefore: n3,3,10,0,0
20
20 A Simpler Representation l In fact, since the system is closed, we only need to represent one side of the river, as we can deduce the other side. l We will represent the finishing side of the river, and omit the starting side. l So start state is: n0,0,0
21
21 Operators l Now we have to choose suitable operators that can be applied: 1.Move one cannibal across the river. 2.Move two cannibals across the river. 3.Move one missionary across the river. 4.Move two missionaries across the river. 5.Move one missionary and one cannibal.
22
22 The Search Tree l Cycles have been removed. l Nodes represent states, edges represent operators. l There are two shortest paths that lead to the solution.
23
23 Combinatorial Explosion l Problems that involve assigning values to a set of variables can grow exponentially with the number of variables. l This is the problem of combinatorial explosion. l Some such problems can be extremely hard to solve (NP-Complete, NP-Hard). l Selecting the correct representation can help to reduce this, as can using heuristics (see chapter 4).
24
24 Problem Reduction l Breaking a problem down into smaller sub- problems (or sub-goals). l Can be represented using goal trees (or and- or trees). l Nodes in the tree represent sub-problems. l The root node represents the overall problem. l Some nodes are and nodes, meaning all their children must be solved.
25
25 Problem Reduction: Example l E.g. to solve the Towers of Hanoi problem with 4 disks, you can first solve the same problem with 3 disks. l The solution is thus to get from the first diagram on the left, to the second, and then to apply the solution recursively.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.