94
인인인인 (Artificial Intelligence) Week2 . Search 최 최 최

인공지능 (Artificial Intelligence)

  • Upload
    kenda

  • View
    208

  • Download
    0

Embed Size (px)

DESCRIPTION

Week2 . Search 최 윤 정. 인공지능 (Artificial Intelligence).  가지 않은 길 R. 프로스트  노란 숲 속에 두 갈래 길이 있었습니다 나는 두 가지 길을 다 가지 못하는 것을 안타깝게 생각하면서 오랫동안 서서 한 길이 굽어 꺾여 내려간 데까지 바라볼 수 있는 데까지 멀리 바라다 보았습니다 그리고 똑같이 아름다운 다른 길을 선택 했습니다 그 길에는 풀이 더 많고 사람이 걸은 자취가 적어 아마 더 걸어야 될 길이라고 나는 생각했었던 거지요 - PowerPoint PPT Presentation

Citation preview

Page 2: 인공지능 (Artificial Intelligence)

2

Prologue 가지 않은 길  R. 프로스트

노란 숲 속에 두 갈래 길이 있었습니다

나는 두 가지 길을 다 가지 못하는 것을 안타깝게 생각하면서

오랫동안 서서 한 길이 굽어 꺾여 내려간 데까지

바라볼 수 있는 데까지 멀리 바라다 보았습니다

 

그리고 똑같이 아름다운 다른 길을 선택 했습니다

그 길에는 풀이 더 많고 사람이 걸은 자취가 적어

아마 더 걸어야 될 길이라고 나는 생각했었던 거지요

그 길을 걸으므로 , 그 길도 거의 같아질 것이겠지만

 

그날 아침 두 길에는 낙엽을 밟은 자취는 없었습니다

아 .... 나는 다음날을 위하여 한길은 남겨 주었습니다

길은 길에 이어져 끝이 없으므로

내가 다시 돌아 올 수 있는지를 의심 하면서

 

오랜 세월이 흐른 훗날에

나는 한숨을 쉬면서 이야기 할 것입니다

숲 속에 두 갈래 길이 있었다고

나는 사람이 적게 가는 길을 택하였다고

그리고 그것 때문에 모든 것이 달라졌다고

희망이란 ..

본래 있다고도 할 수 없고 없다고도 할 수 없다 .

그것은 마치 땅 위의 길과 같은 것이다 .

본래 땅 위에는 길이 없었다 .

한 사람이 먼저 가고

걸어가는 사람이 많아지면

그것이 곧 길이 되는 것이다 .

- 루쉰의 ' 고향 ' 중에서 ..

Page 3: 인공지능 (Artificial Intelligence)

3

!!

탐색 : 문제해결을 위해 적용하는 아주 흔한 기법 .!

만약 우리가 문제 해결을 위해서 취해야 할 행동들이 무엇인지 알고 있지만 어떤 순서로 행동을

취해야 문제가 해결되는지 알지 못한다면 가능한 모든 순서의 조합을 다 시도해 보아야 한다 .

상태공간에서의 문제 풀이과정

목표 : 과제를 수행하는 프로그램

제약조건 :

사용 가능한 컴퓨터언어 , 처리시간 및 메모리 용량 .

인간의 문제풀이 과정을 상태공간의 개념으로 형식화

Page 4: 인공지능 (Artificial Intelligence)

4

Problem State Space What is Problem State Space?

What is valid move within the space?

Rule of the Game

Characteristic of the State Space

How to find the Solution Path in the State Space?

Search Methods

Page 5: 인공지능 (Artificial Intelligence)

5

What is Problem State Space?

상태공간 (State Space):

표현방식을 설정하는 풀이 과정에서 발생하는 모든 가능한 매 순간의 문제상태들의 집합

변수를 사용하여 수식으로 표현하거나 , 논리식으로서 표현

초기상태 (Initial State) : 문제 풀이과정이 시작되는 최초의 상태

목표상태 (Goal State) : 문제 풀이과정에서 최종적으로 도달하여야 할 목표상태

동작자 (operator) 의 정의

동작자를 적용하여 문제의 상태를 다른 상태로 변환

동작자는 주어진 제약 조건을 만족해야 한다 .

Page 6: 인공지능 (Artificial Intelligence)

6

8-Puzzel

23

45 67

8 111

11

22

22

3

3 3

344

44

5

55

566

66

77

77

8

8

8 8

a b c

List Representation (2 0 3 1 8 4 7 6 5) : Initial State (1 2 3 8 0 4 7 6 5) : Goal State (0 2 3 1 8 4 7 6 5) : Intermediate States (2 8 3 1 0 4 7 6 5) (2 3 0 1 8 4 7 6 5)

Page 7: 인공지능 (Artificial Intelligence)

7

State Space of 8-Puzzle(2)

Position Function Pos(1, 1) = 2 Pos(1, 2) = 8 ….Or Predicate? Pos(1, 1, 2) = True Empty(3, 2) = True

List (2 0 3 1 8 4 7 6 5) (0 2 3 1 8 4 7 6 5) (2 0 3 1 8 4 7 6 5) (2 8 3 1 0 4 7 6 5) (2 0 3 1 8 4 7 6 5) (2 3 0 1 8 4 7 6 5)

Predicate (empty 1 2) (pos 1 1 x) (empty 1 1) (pos 1 2 x)

Valid Moves of 8-Puzzle

Page 8: 인공지능 (Artificial Intelligence)

8

Water Jug Problem 2 water jugs : 4 liter, 3 liter Need to get exactly 2 liters of water

State space? (0, 0) : initial (2, 0) : Goal

Valid move? (4,0) (1, 3) (0, 1)(4, 1) (2,3) (2,0 ) (0,3) (3, 0) (3, 3) (4, 2) (0, 2) ..?

Page 9: 인공지능 (Artificial Intelligence)

9

Examples Tower of Hanoi : C or Java

Missionaries & Cannibals Problem : LISP

Maze & Blocks world : C or Java

Page 10: 인공지능 (Artificial Intelligence)

10

Tower of Hamoi 문제는 막대 A 에 쌓여있는 원판 3 개를 막대 C 로 옮기는 것이다 . 단 다음의 조건을

지켜야 한다 .

한 번에 하나의 원판만 이동할 수 있다

맨 위에 있는 원판만 이동할 수 있다

크기가 작은 원판위에 큰 원판이 쌓일 수 없다 .

중간의 막대를 임시적으로 이용할 수 있으나 앞의 조건들을 지켜야 한다 .

A B C

Page 11: 인공지능 (Artificial Intelligence)

11

A B C

A B C

A B C

A B C

3 개의 원판인 경우의 해답

A B C

A B C

A B C

A B C

1. 3 개중 위 2 개의 원판을 A->B

2. A 의 제일 큰 원판을 A->C

3. B 에 있는 2 개의 원판을 B->C

Page 12: 인공지능 (Artificial Intelligence)

12

n 개의 원판인 경우 문제의 일반화

n-1 개의 원판을 A 에서 B 로 옮기고

n 번째 원판을 A 에서 C 로 옮긴 다음 ,

n-1 개의 원판을 B 에서 C 로 옮긴다 .

필요한 변수 원판의 개수 : n

어디에서 어디로 ? : from to

임시막대 1 개 : tmp

따라서 , 함수의 prototype

A B C

n-1 개의 원판

1 개의 원판

A B C

A B C

A B C

void hanoi_tower(int n, char from, char tmp, char

to)

Page 13: 인공지능 (Artificial Intelligence)

if (n==1)

1. 1 번 원판을 fromto 즉 , AC 로 옮긴다 .

else n>=1 이면 {

2. from 의 맨 아래 원판을 제외한 (n-1) 개의 원판을 fromtmp, 즉 AB 로

옮긴다 .

3. 2 번에서 옮기지 않은 from 의 1 번원판을 fromto, AC 로 옮긴다 .

4. 임시막대인 tmp 의 원판들을 to 로 옮긴다 .

}

13

void hanoi_tower(int n, char from, char tmp, char to) ?

2. hanoi_tower(n-1, from, to, tmp);

4. hanoi_tower(n-1, tmp, from, to);

Page 14: 인공지능 (Artificial Intelligence)

하노이탑 실습 ( 전공 및 4 학년 제외 )

14

#include <stdio.h>

void hanoi_tower(int n, char from, char tmp, char to)

{

if( n==1 ) printf(" 원판 1 을 %c 에서 %c 으로 옮긴다 .\n",from,to);

else {

hanoi_tower(n-1, from, to, tmp);

printf(" 원판 %d 을 %c 에서 %c 으로 옮긴다 .\n",n, from, to);

hanoi_tower(n-1, tmp, from, to);

}

}

int main(void)

{

hanoi_tower(4, 'A', 'B', 'C');

}

Page 15: 인공지능 (Artificial Intelligence)

15

Missionaries & Cannibals Problem

3 명의 선교사와 3 명의 식인괴물 (cannibal) 이 강 한 쪽편에 있어요 .

보트를 이용해 강을 건너야 하는데 , 보트는 1 개이고 1 번 건너갈 때 최대 2 명을 태울 수 있어요 그러니까 1 명은 노를 저어야 합니다 .

만약 식인괴물 수가 선교사보다 많으면 ( 같으면 괜찮아요 ) 선교사가 괴물한테 잡아 먹힙니다 . 선교사를 무사히 살려서 6 명 모두 강을 건너는 퀴즈 .

이런 문제는 C 나 Java 로도 물론 할 수 있겠으나 일련의 규칙과 조건을 표현하는 데 용이한 언어를 이용하면 쉽게 (?) 해결됩니다 .

Page 16: 인공지능 (Artificial Intelligence)

16

Lisp 코드 ( 실습시간에 돌려봅니다 )(defun main () (print-actions (solve)) 'done)

(defun solve () (labels ((iter (state path) (if (goal-test state) (reverse path) (let ((ss (remove-cyclic (successors state) path))) (and ss (some #'(lambda (s) (iter (cdr s) (cons s path))) (suffle ss))))))) (iter (make-cannibal-state) (list (cons 'Begin (make-cannibal-state))))))

(defun remove-cyclic (succs path) (remove-if #'(lambda (s) (member s path :test #'(lambda (a b) (equal (cdr a) (cdr b))))) succs))

(defun print-actions (path) (format t "~&~10A ~{~4S~}" "Action" '(m1 c1 b1 m2 c2 b2)) (mapc #'(lambda (p) (format t "~&~10A~{~4d~}" (car p) (cdr p))) path))

(defun suffle (lst) (sort (copy-list lst) #'> :key #'(lambda (x) (declare (ignore x)) (random 1.0))))

;;;; The Missionaries and Cannibals Domain

(defun goal-test (state)

"The goal is to have no missionaries or cannibals left on the first

side."

(= 0 (m1 state) (c1 state)))

(defun successors (state)

"Return a list of (action . state) pairs. An action is a triple of the

form (delta-m delta-c delta-b), where a positive delta means to

move from

side 1 to side 2; negative is the opposite. For example, the ac-

tion (1 0 1)

means move one missionary and 1 boat from side 1 to side 2."

(let ((pairs nil))

(loop for action in '((+1 0 +1) (0 +1 +1) (+2 0 +1) (0 +2 +1)

(+1 +1 +1)

(-1 0 -1) (0 -1 -1) (-2 0 -1) (0 -2 -1) (-1 -1 -1))

do (let ((new-state (take-the-boat state action)))

(when (and new-state (not (cannibals-can-eat? new-state)))

(push (cons action new-state) pairs))))

pairs))

Page 17: 인공지능 (Artificial Intelligence)

17

Lisp 코드(defstruct (cannibal-state (:conc-name nil) (:type list)) "The state says how many missionaries, cannibals, and boats on each side. The components m1,c1,b1 stand for the number of mission-aries, cannibals and boats, respectively, on the first side of the river. The components m2,c2,b2 are for the other side of the river." ;; We need to represent both sides (rather than just one as on [p 68]) ;; because we have generalized from 3+3 people to M+C. Inci-dently, we ;; also generalized from 1 boat to B boats. (m1 3) (c1 3) (b1 1) (m2 0) (c2 0) (b2 0))

(defun take-the-boat (state action) "Move a certain number of missionaries, cannibals, and boats (if possible)." (destructuring-bind (delta-m delta-c delta-b) action (if (or (and (= delta-b +1) (> (b1 state) 0)) (and (= delta-b -1) (> (b2 state) 0))) (let ((new (copy-cannibal-state state))) (decf (m1 new) delta-m) (incf (m2 new) delta-m) (decf (c1 new) delta-c) (incf (c2 new) delta-c) (decf (b1 new) delta-b) (incf (b2 new) delta-b) (if (and (>= (m1 new) 0) (>= (m2 new) 0) (>= (c1 new) 0) (>= (c2 new) 0)) new nil)) nil)))

(defun cannibals-can-eat? (state) "The cannibals feast if they outnumber the missionaries on either side." (or (> (c1 state) (m1 state) 0) (> (c2 state) (m2 state) 0)))

CL-USER 1 > (main)Action M1 C1 B1 M2 C2 B2 BEGIN 3 3 1 0 0 0(0 2 1) 3 1 0 0 2 1(0 -1 -1) 3 2 1 0 1 0(0 2 1) 3 0 0 0 3 1(0 -1 -1) 3 1 1 0 2 0(2 0 1) 1 1 0 2 2 1(-1 -1 -1) 2 2 1 1 1 0(2 0 1) 0 2 0 3 1 1(0 -1 -1) 0 3 1 3 0 0(0 2 1) 0 1 0 3 2 1(-1 0 -1) 1 1 1 2 2 0(1 1 1) 0 0 0 3 3 1DONE

CL-USER 2 >

Page 18: 인공지능 (Artificial Intelligence)

18

Maze Problem n×m 행렬 M

미로의 입구를 M[0,0], 미로의 출구를 M[n-1,m-1]

현재 위치 :

- {(x, y)| x = 0,1,...,n-1,y = 0,1,...,m-1} 으로

표현 가능

- 초기 상태 : 시작상태로서 (x, y) = (0,0)

- 목표 상태 : 미로의 출구에 있는 상태 , 즉 (x, y) = (n-

1,m-1)

상태 공간의 정의 동작자 전제 조건 다음 상태

위로 이동(x-1,y) = 0

위쪽으로 길이 있다 . (x-1,y)

아래로 이동(x+1,y) = 0

아래쪽으로 길이 있다 .(x+1,y)

右로 이동(x, y+1) = 0

우측으로 길이 있다 .(x, y+1)

左로 이동(x, y-1) = 0

좌측으로 길이 있다 .(x, y-1)

동작자 정의의 예

Page 19: 인공지능 (Artificial Intelligence)

19

탐색트리와 탐색그래프 (1) 탐색트리

노드 : 상태

근 (root) 노드 : 초기상태

자식 (child) 노드들 : 하나의 노드에 동작자를 적용하였을 때 생기는 결과 상태들

문제를 풀어나가는 과정 Root 노드들로부터 적용 가능한 동작자들을 선정하여 적용

노드가 목표상태가 될 때까지 노드의 선택 - 확장과정을 반복

탐색 트리의 예 초기의 문제 상태 : 거북이가 미로의 M(0,0) 에 위치

밑줄을 그은 노드들은 탐색 트리의 다른 부분에 중복

초기상태에서 목표상태에 도달하는 경로를 추적하기 위하여 , 자식노드에는 부모노드를 가리키는 역방향 arc 표시

(0,0)

(1,0) (0,1)

(1,1) (0,0) (0,0) (1,1)

(1,0) (0,1) (2,1) (1,2) (1,0) (0,1) (1,0) (0,1) (1,0) (0,1) (2,1) (1,2)

(0,0)

(1,0) (0,1)

(1,1) (0,0) (0,0) (1,1)

(1,0) (0,1) (2,1) (1,2) (1,0) (0,1) (1,0) (0,1) (1,0) (0,1) (2,1) (1,2)

Page 20: 인공지능 (Artificial Intelligence)

20

탐색트리와 탐색그래프 (2) 탐색 그래프

단순히 존재하는 노드간의 연결

순환하는 경로 , 즉 사이클 (cycle) 허용 -> 그래프

자식노드에서 부모노드로의 역방향 아크의 설정시 여러 개의 부모 노드가 가능

Main Strategy :

탐색 트리 / 그래프 상에서 , 초기 상태로 부터 목표상태로 도달하는 경로 (path) 를 발견하는 방식

점진적인 트리의 확장 : 탐색 트리 혹은 그래프상에 존재 하는 노드들 중 하나의 노드를 선택

자식노드들을 정해진 전략에 따라 순서대로 기존의 탐색 트리에 추가

문제 : 기존노드의 선택 및 자식노드의 확장 순서를 결정하는 방법 노드의 확장 방향 ? : 너비우선 , 깊이우선… .

초기상태 -> 목표상태 , 목표상태 -> 초기상태

(0,0)

(1,0) (0,1)

(1,1)

(2,1) (1,2)

(0,0)

(1,0) (0,1)

(1,1)

(2,1) (1,2)

경험적 지식 (heuristic knowledge) 을 사용할 수 있는가 ?

Page 21: 인공지능 (Artificial Intelligence)

Characteristic of State SpaceStrategy of State Space Search

Algorithms ..Hill climbing, game tree ..

Page 23: 인공지능 (Artificial Intelligence)

23

Characteristics of State Space

Decomposable? goal -- subgoals

Blind vs Informed (heuristic) Search

Revocable vs Irrevocable backtracking

Predictable vs Stochastic

Optimal vs Plausible SolutionSlide 맨 뒷장 보충자료 참고합니다 .

Page 24: 인공지능 (Artificial Intelligence)

24

Search Algorithm Guarantee to find a solution ?

Always terminate ?

Guarantee the solution to be optimal -- admissible?

Complexity - time and space

How can the complexity be reduced ?

Characteristics of the space?

State Space Search !

Page 25: 인공지능 (Artificial Intelligence)

25

Strategies of SS Search Data-Driven vs. Goal Driven

Forward chaining / Backward chaining

Symptom diagnosis : Forward

eg. Fever, cough flu

Goal/Sub-goal : Backward

eg. Good Husband? Girl?

Rich? Or Handsome & Pretty ,,,

Page 26: 인공지능 (Artificial Intelligence)

26

Forward vs Backward Factors deciding Forward/Backward

Size of the known states: initial, goal small to big

Branching Factor : converging computational simplicity

eg. Water jug problem When is forward (backward) better? Bi-Directional

초기상태(A 도시)

목표 상태(B 도시)

(a)

(b)

초기상태(A 도시)

목표 상태(B 도시)

초기상태(A 도시)

목표 상태(B 도시)

(a)

(b)

초기상태(A 도시)

목표 상태(B 도시)목표 상태(B 도시)목표 상태(B 도시)

▶ 어느 방식을 적용할 것인가는 문제의 특성에 의존적 : 예 ) 선택해야 할 경우의 수가 적은가 ?

Bi-Directional( 양방향 ) 추론 : 순방향 추론과 역방향 추론을 혼용한 방식▶ 초기상태와 목표상태 양쪽에서 동시에 상대편 상태 쪽으로 경로를 찾아 나가는 방식▶ 평균적으로 계산시간이 감소되며 , 경로가 어긋나는 경우 , 추론 과정을 반복

Page 27: 인공지능 (Artificial Intelligence)

27

Implementing Search(1) Blind Search

Search does not depend on the nature of the positional value

Systematic Search Method Breadth-First Search Depth-First Search Iterative Deepening Search Lowest Cost First Search (blind 와 heuristic 의 경계 )

Heuristic Search

Page 28: 인공지능 (Artificial Intelligence)

28

Implementing Search(2) Blind Search Heuristic Search

Hill Climbing Best First Search A* Algorithm

Page 29: 인공지능 (Artificial Intelligence)

29

Blind Search Abstract Data Type – Tree ( 참고만 해보세요 .)

(defun make-TREE(label value children) (list ‘tree label value children))

(defun TREE-label (tree) (second tree)) (defun TREE-value(tree) (third tree)) (defun TREE-children(tree)(fourth tree)) (defun TREE-print(tree)

(princ(TREE-label tree)))Depth-First Search Example

1

2 3 4

5 6 7 8 9

Breadth-First Search Exam-ple

1

2 3 4

5 6 7 8 9

Page 30: 인공지능 (Artificial Intelligence)

30

Depth First Search

1. 빈 큐 (Queue) 에 초기상태 노드를 넣는다 .

2. 큐가 비어 있지 않고 답 = 찾지못함 이면 다음을 반복한다 .

3. 큐에서 하나의 노드 N 을 빼낸다 .

4. N 과 N 의 부모노드를 쌍 (Pair) 으로 만들어 LIST 에 넣는다 .

5. 만약 N 이 목적상태노드 이면 답 = 찾음 으로한다 .

6. N 의 자식노드가 있으면 자식노드중 LIST 에 없는 자노드만 큐에 넣는다 .

LIST = { } ; 초기의 리스트는 비어 있음 답 = 찾지못함 .

(e.g., QUEUE ={ 도서관 })

(e.g., QUEUE ={ 병원 초등학교 })

(e.g., 리스트 ={( 도서관 , NIL)}

(defun dfs(nodes goalp next) (cond ((null nodes) nil) ((funcall goalp (first nodes)) (first nodes)) (t (dfs (append (funcall next (first nodes)) (rest nodes)) goalp next ) ) ) )

Lisp 코드의 예

Page 31: 인공지능 (Artificial Intelligence)

31

Function DFS > (setq tree (make-TREE ‘a 6 (list (make-TREE ‘b 3 (list(make-TREE ‘d 5 nil) (make-TREE ‘e 4 nil))))))

// 이 부분은 인공지능 실습시간에 실습해 봅니다 .

> (dfs (list tree) #’(lambda(x) (TREE-print x) (eq ‘g (TREE-label x))) #’TREE-children)

Page 32: 인공지능 (Artificial Intelligence)

32

DFS 에서의 Stack 과 QUEUE상태

1) QUEUE = { 도서관 }, 답 = 찾지못함 LIST={ } .

2) QUEUE = { 병원 초등학교 }, 답 = 찾지못함 LIST ={( 도서관 , NIL)} .

3) QUEUE = { 초등학교 공원 중학교 }, 답 = 찾지못함 LIST ={( 병원 , 도서관 )( 도서관 , NIL)}

4) QUEUE = { 공원 중학교 상가 }, 답 = 찾지못함 LIST ={( 초등학교 , 도서관 )( 병원 , 도서관 )( 도서관 , NIL)}

5) QUEUE = { 중학교 상가 }, 답 = 찾지못함 LIST ={( 공원 , 병원 ) ( 초등학교 , 도서관 )( 병원 , 도서관 )( 도서관 , NIL)}

6) QUEUE = { 상가 대학교 교회 }, 답 = 찾지못함 LIST ={( 중학교 , 병원 )( 공원 , 병원 ) ( 초등학교 , 도서관 )( 병원 , 도서관 )( 도서관 , NIL)}

7) QUEUE = { 대학교 교회 }, 답 = 찾지못함 LIST ={( 상가 , 초등학교 )( 중학교 , 병원 )( 공원 , 병원 ) ( 초등학교 , 도서관 )( 병원 , 도서관 ) ( 도서관 , NIL)}

8) QUEUE = { 교회 }, 답 = 찾음 LIST ={( 대학교 , 중학교 )( 상가 , 초등학교 )( 중학교 , 병원 )( 공원 , 병원 )( 초등학교 , 도서관 ) ( 병원 , 도서관 )( 도서관 ,

NIL)}

Page 33: 인공지능 (Artificial Intelligence)

33

Breadth First Search (defun bfs(nodes goalp next) (cond ((null nodes) nil) ((funcall goalp (first nodes)) (first nodes)) (t (bfs (append (rest nodes) (funcall next (first nodes))) goalp next ) ) ) )

Page 34: 인공지능 (Artificial Intelligence)

34

Comparison of BFS and DFS BFS always terminate if goal exist

cf. DFS on infinite tree BFS Guarantee shortest path to the goal (admissi-

ble) Backtracking ? Multiple Goals

Space requirement BFS - Exponential DFS - Linear

DFS 의 특징 중 하나는 시작노드에서 목적노드까지의 가장 짧은 거리를 처음에 찾는 것을 보장 할 수 없다는 것이다 . 하나의 길이 찾아진 후에 더 짧은 길이 발견될 수 있는 것이다 . ( 그래프에서 두 노드를 연결하는 길은 하나 이상이 있을 수 있다 .) 하지만 BFS 탐색은 DFS 탐색과는 달리 처음 찾은 길이 가장 짧은 길이 된다 .

Which is better ? BFS or DFS ?

Page 35: 인공지능 (Artificial Intelligence)

35

Iterative Deepening Search Compromise of BFS and DFS Branch and Bound Set the Limit then DFS If Fail, extend the limit (one step) Save on Storage, guarantee shortest path

Page 36: 인공지능 (Artificial Intelligence)

36

Lowest Cost First Search Borderline between Blind and Heuristic Search Cost value is assigned to each arc Moveset (candidate list) is a priority queue ordered by path

cost Eg. Dijkstra’s algorithm When Arc cost is unit value, BFS

(Supplement : Slide - 72)

Page 37: 인공지능 (Artificial Intelligence)

37

Method Find Solu-tion Optimal Complexity 비고

DFS No No O(bd)  

DFS w/o loop Yes No O(bd)  

BFS Yes Yes O(bd) 최단경로

균일비용 Yes Yes O(bd) 최소경로

Hill Climbing No No O(bd)  

Best First Yes No O(bd)  

A* Yes Yes O(bd) No Overestimate

Search Summary

Page 38: 인공지능 (Artificial Intelligence)

38

Heuristic Search Blind search assumes no information about the do-

main – Too expensive Heuristic Information can be helpful Heuristic Function f(n) = g(n) + h(n) f: total cost g: cost from start to node n (real value) h: cost from node n to goal (usually unknown)

Page 39: 인공지능 (Artificial Intelligence)

Cost : 거리 = 휴리스틱

39

(Supplement : Slide - 84)

Page 40: 인공지능 (Artificial Intelligence)

40

Heuristic Function

Heuristics : Knowledge obtained from human ex-

perience

Heuristic function h : SS number

a preference measure for each position of the

state space

What is the heuristic function for CUBE Puzzle?

Necessary for Informed Search (cf. Blind)*Heuristic : 예 ) 예전에 경험을 토대로 , 누가 그러던데 .. .. 일단 한번 시도해 볼까 ?

탐색공간에 관한 정보를 활용하여 탐색공간을 줄이거나 ,

정확한 ( 최선의 ) 답은 아닐지라도 사용 가능한 근사치를 빨리 찾을 수 있도록 하는 유용한 정보- 모호성이 큰 경우 , 모든 경우를 찾아보기에 시간이 부족한 경우 적용할 수 있다 .

- 항상 ‘ true’ 라는 보장은 없으며 최적의 ‘해’ 임을 증명하지 못하는 경우가 많으나 ,

- ‘ 좋은 답’을 구하게 되는 경우가 많다 . 얼마나 좋은가 ? 에 관한 ’평가함수’의 구현에 달려있다 .

Page 41: 인공지능 (Artificial Intelligence)

41

Generate & Test British Museum Algorithm

Guess a Solution & Test if it is right

DENDRAL : molecular structure analysis

plan-generate-test (constraint)

AM (Automated Mathematician)

Number Theory – generate a conjecture

Generate & Test is especially useful when combined with

other strategy

Page 42: 인공지능 (Artificial Intelligence)

42

Best First Search ( 현재까지 탐색되어온 노드들 중에서 목표 상태로 이끌 가능성이 가장 높은 노드를 선택해서 탐색을

계속하는 방식 )

Moveset (candidate list) is a priority queue ordered by

heuristic cost h(n)

Does not guarantee the Shortest Path

Does not always terminate even though there is a solution

Performance depends on the h function

Page 43: 인공지능 (Artificial Intelligence)

43

Hill Climbing 목표상태를 언덕의 꼭대기에 비유하고 , 각 노드에서 언덕 꼭대기에 가장 빨리 도달할 수

있는 다음 노드를 선택하는 방법 .!

Greed Method , Iterative Improvement Algorithm

Select the Best Looking Candidate : Use heuristic function

Stop when no more better looking candidates Assume it is

the Goal!

No Backtracking : Simplicity!! 휴리스틱 : 목표까지 남아있는 거리 !

DFS 와 유사하지만 , 유망한 자녀노드의 선택을 위해 평가함수를 사용한다 .

이 값에 근거하여 최선의 노드를 택한 후에는 부모 , 자녀노드에 대한 참고는 더 이상 하지 않는다 .

Page 44: 인공지능 (Artificial Intelligence)

44

Hill Climbing Issues Low Memory Requirement

No backtracking

Moveset (next move) design is critical

Evaluation Function design is critical

If the number of move is too big

Inefficient

Too small?

Easily stuck (plateau)

Hill-climbing: Attempt to maximize

Eval(X) by moving to the highest con-

figuration in our moveset.

1. Let X := initial config

2. Let E := Eval(X)

3. Let N = moveset_size(X)

4. For ( i = 0 ; i<N ; i := i+1)

Let Ei := Eval(move(X,i))

5. If all Ei’s are ≤ E, terminate, return X

Else let i* = argmax Ei

6. X := move(X, i*)

7. E := Ei*

8. Goto 3

Hill Climbing Algorithm

Page 45: 인공지능 (Artificial Intelligence)

45

Problems of Hill Climbing 문제점 : 목표상태로 접근하기 위한 상태를 변화시킬 수 없는 경우가 발생 !

Local Maxima ( 지역최적화 ) 인접한 근처의 모든 상태들보다는 나은 ( 우수한 , 가까운 ) 상태 . 백트래킹이 필요함

Plateau( 고원 ) 인접한 상태들이 모두 같은 값을 갖는 탐색공간의 평탄한 지역 . 같은 방식으로 최적방향의 결정이 불가능 .

해당 공간을 벗어나기 위한 연산자 적용이 필요 .!

Ridge( 산등성이 ) 주위 지역보다는 높지만 , 하나의 움직임만으로는 일정한 방향으로 탐색을 계속 수행할 수 없는 공간 .

( 이상적인 목표 예 ) : Global Maxima 찾기

Page 46: 인공지능 (Artificial Intelligence)

46

Avoiding Problems in H.C.

Many Starting Points

Random Jump : Mutation

Genetic Algorithm

Simulated Annealing

Stochastic Method

Page 47: 인공지능 (Artificial Intelligence)

47

Simulated Annealing

If Ei >= E then definitely accept the change. If Ei < E then accept the change with probability exp (-(E - Ei)/Ti) (called the Boltzman distribution) …where Ti is a “temperature” parameter that gradually decreases.

High temp: accept all moves (Random Walk) Low temp: Stochastic Hill-Climbing

When enough iterations have passed without improvement, terminate.

Page 48: 인공지능 (Artificial Intelligence)

48

Means Ends Analysis(1)

Bi-Directional Method

GPS(General Problem Solver) – Newell

Operator, Pre-condition, Result Table

Choose the operator that reduce the difference

most

Recursively reduce the first and rest parts with

other operators

Page 49: 인공지능 (Artificial Intelligence)

49

Means Ends Analysis(2)GPS(I, G, O); I:initial, G: goal, O: op table select o from O which reduce the difference GPS(I, pre-condition(o), O) print(o) GPS(result(o), G, O) end Going to Central Park, N.Y

GPS(Konkuk, C.Park, O-Table) Operation Table op pre result ------------------------------------------------ AirPlane Inchon J.F.K AirBus 버스터미널 Inchon Taxi Konkuk univ. 버스터미널 Subway J.F.K C.Park

Page 50: 인공지능 (Artificial Intelligence)

50

A* Algorithm Best First Search only considers h Lowest Cost First only considers g A* algorithm takes f (note. f(n) = g(n) + h(n)) A* is optimal if h never overestimates the (opti-

mistic) cost : h is admissible

See the extra slide about A* algorithm ( slide 82)

f(n) = g(n) + h(n) :

g(n) : 초기노드에서 현재 노드 n 까지의 cost

h(n) : 노드 n 에서 목표노드까지 도달하기 위한 비용의 추정치 , heuristic func-

tion

f(n) 은 초기 상태에서 노드 n 을 거쳐 목표 상태에 도달하는 전체 경비의 추정치

Page 51: 인공지능 (Artificial Intelligence)

51

A* Algorithm 노드의 확장시 , 동일한 순간에 선택된 노드의 모든 자식노드들을 한번에

open 하여 부모와 연결시킨다 .

F=0+h=5

F=1+4=5

F=1+5=6

F=1+3=4

F=2+4=6

F=2+5=7

A B C CBA

5 5

5 6 4

(a)

(b)

(c)

F=0+h=5

F=1+4=5

F=1+5=6

F=1+3=4

F=2+4=6

F=2+5=7

A B C CBA

5 5

5 6 4

(a)

(b)

(c)

F=0+h=5

F=1+4=5

F=1+5=6

F=1+3=4

F=2+4=6

F=2+5=7

A B C CBA

5 5

5 6 4

(a)

(b)

(c)

4 5 3 4 5 3

4 5

Page 52: 인공지능 (Artificial Intelligence)

52

A* 알고리즘의 허용성과 단조 증가성 Admisibility( 허용성 ) : 시작노드에서 목적노드사이에 최단경로가 존재할 때 이를 항상 찾을

수 있는가 .

A* 알고리즘에서 사용하는 평가함수 f*(n) = g(n) + h’(n) 에서

h’(n)( 예측값 ) h(n) ( 최적 추정치 ) 이므로 A* 알고리즘은 허용성이 있다 .

만약 h’(n) = 0 이면 A* 알고리즘은 너비우선 알고리즘과 같아진다 .

Monotonicity( 단조증가성 ) : 어떤 휴리스틱 알고리즘을 사용하여 탐색을 수행하는 중 , 한번 찾은 노드를 더 짧은 경로로 다시 발견할 수 없는가 ?

조건 :

목적노드의 평가함수 값이 0 인경우 .

h(parent) –h(child) 이 부모노드 i 에서 자식노드 j 를 거쳐 가는 실제 cost( 거리 ) 보다 적을 경우 .

Page 53: 인공지능 (Artificial Intelligence)

53

Admissible Heuristics :

For Example: the 8-Puzzleh1(n) = number of misplaced tiles

h2(n) = total Manhattan distance = number of squares from desired location

Start State Goal State

h2(S) = ??

h1(S) =?? 7 ( 9 개중 2 개는 제자리 )

4+0+3+3+1+0+2+1 = 14

Page 54: 인공지능 (Artificial Intelligence)

정리 : Best-first Search & A* 알고리즘 BestFS : 백트래킹 안 한다 !!!

지역적으로 확장된 트리의 모든 노드 중 , 가장 좋은 노드부터 탐색 시작 산의 최고지점을 찾기 위해 여러 팀이 협동하여 움직이는 것과 비슷함 .

기본적으로 우선 순위가 정해져야 하고 , 많은 메모리가 필요하며 구현 방법이 복잡 리스트관리 : 평가함수 값에 따라 모든 노드를 정렬해 둔다 . ( 가장 유망한 노드가 맨 앞에 )

Hill Climbing 가 다른 점 : 현재 진행방향의 자식노드중 가장 유망한 노드를 확장하지만 , BestFS 에서는 전체노드를

대상으로 선택한다 .

A* : 백트래킹 한다 !!!

출발노드로부터 목표노드까지의 최적경로를 탐색하기 위한 것으로 , 각각의 노드에 대한 평가함수를 정의 .

f(n) = g(n) + h(n)

g(n) : 출발노드로부터 노드 n 까지의 경로 h(n) : 노드 n 으로 부터 목표노드까지의 경로 But, h(n) 은 아직 탐색하지 않은 경로이므로 정확히 계산하기 어려우나 경험적 규칙이 사용될 수 있다 .

휴리스틱에 의한 예측값을 h’(n) 이라 하면 f(n) = g(n) + h’(n) , h’ <= h 이라면 optimal 경로를 찾는다 .

54

Page 55: 인공지능 (Artificial Intelligence)

55

Game Tree Search

Game Tree : Special case of AND/OR Graph

Objective of Game Tree Search

To find good first move

Static Evaluation Function e

Measure the worth of a tip node

if p is win for MAX, then e(p) = infinity

if p is win for MIN, then e(p) = - infinity

Page 56: 인공지능 (Artificial Intelligence)

56

Game Tree Search 게임은 8- 퍼즐게임처럼 한 사람이 하는 게임도 있지만 , 상대가 있는 게임도 많다 .

상대가 있는 게임은 상대의 의도 까지를 고려해야 하기 때문에 일반적으로 혼자 하는

게임보다 더욱 복잡하다 .

대부분의 게임은 제한된 시간 내에 모든 상태를 전부 탐색 할 수 없으므로 탐색공간을 줄여야

하는데 휴리스틱을 잘 활용하면 탐색공간을 크게 줄일 수 있다 .

http://www.aistudy.com/heuristic/

adversarial_search_nilsson.htm

Page 57: 인공지능 (Artificial Intelligence)

Game Tree 와 MiniMax, Alpha-Beta 프로시저

최적의 움직임을 선택하기 위해서 정적평가함수 ( 상황분석기 ) 를 사용한다 .

게임트리의 득점 (scoring) 정보를 상위노드로 전달하는 프로시저를 MiniMax 프로시저라고 한다 .

주요 아이디어 : 게임의 판세를 단일 숫자인 정적인 값으로 나타내는 사실 ! 게임의 판세를 어떠한 단일 숫자인 수 , 즉 대표값으로 나타내는 것은 심각한 결점을 지닌다 .

숫자가 어떻게 결정되었는가에 대한 언급을 하지 않는다 .

경로를 특별한 정책없이 생성시키고 값을 계산함으로써 비용이 발생

Alpha-Beta 프로시저 : MiniMax 의 개선된 버전 주어진 노드에서 부모노드에 대해 무엇이 알려져 있는지 검사한다 .

주어진 노드 아래를 더 이상 찾지 않아도 될 수 있음

한 노드의 정확한 값이 결정될 때마다 부모에 대해 무엇이 알려져 있는지 검사 부모노드가 바랄 수 있는 최선의 값이 정확히 정해지거나 개선될 수 있음

57

Page 58: 인공지능 (Artificial Intelligence)

58

MiniMax Procedure

Select the maximum worth alternative

Under Assumption of that the opponent do his

best

Back-Up Value(BUV)

1. At tip node p, BUV is e(p)

2. At max node, BUV is max BUV of children

3. At min node, BUV is min BUV of children

Page 59: 인공지능 (Artificial Intelligence)

59

MiniMax 기법 Max level 2

-7 Min level 10 2 -7

100 Max level 10 6 -2 2 -8 -7 20

100

Page 60: 인공지능 (Artificial Intelligence)

60

Alpha-Beta Procedure Improvement of MiniMax Procedure

combining search procedure & evaluation

Alpha-Beta Pruning : 상태공간 중에 탐색시 고려하지 않아도 최종결과에는 영향을 미치지 않는 노드들을 절단하여

탐색공간을 줄이는 기법

AB

S

1 0 -1 1 -2

max

C

Page 61: 인공지능 (Artificial Intelligence)

61

Production System Model of Search and Human Problem Solving

Heavily used in AI (Expert) system

Production System components

Production rules (or production)

also called Long-term memory

Working Memory

also called Short-term memory

Recognize-act cycle

also called control structure, engine

Page 62: 인공지능 (Artificial Intelligence)

62

Production Rules Production

condition part and action part

premise and conclusion

LHS and RHS

Condition Part - pattern matching

Action Part - problem solving step

Good for representing Judgmental knowledge( 지금의 의사결정시스템 )

Page 63: 인공지능 (Artificial Intelligence)

63

Weak Methods General Purpose Control Strategies Simplicity is the KEY of Weak Methods Usually - Not Optimal - No Backtracking - No Guarantee to the Solution

Generate & Test Hill Climbing Best First Search Means-Ends Analysis Etc.

Page 64: 인공지능 (Artificial Intelligence)

64

Epilogue AI 의 Classical 한 이론들을 두루 두루 살펴보았습니다 .

탐색방법의 발전 과정과 흐름으로 볼 때 ,

AI study 에서라도 각 이론 및 keyword 에 대해 찾아보고 읽어보세요 Search : 휴리스틱

적대탐색 http://www.aistudy.com/heuristic/adversarial_search_nilsson.htm

규칙과 생성시스템 :

http://www.aistudy.com/expert/rule_kim.htm

http://www.aistudy.com/heuristic/production_yoo.htm

Page 65: 인공지능 (Artificial Intelligence)

65

과제 #3 : 다음 수업시간 전까지 이제 고전적인 탐색방법을 살폈으니 , 여러분은 각자 , 각 도메인마다 특화된 , ( 더 나은 ) 실체가 되도록

노력해야겠습니다 .

자신을 예로 들어보았을 때 구현되는 형태는 분야별 최적화된 탐색전략 - 알고리즘 또는 규칙들이겠죠 ?

다음 번 주제인 ‘지식생성 및 표현시스템’을 위해 자신을 움직이는 철학 , 가치관 , 규칙 , 노하우에 관한 탐색 , 판단규칙 등에 관해 실체화 해보도록 합니다 .

예 )

조건 1 : 도메인 ( 적용지역 , 분야 ) 자유 . cycle 도 자유

조건 2 : 이왕이면 admissible and revocable 하게

조건 3 : 규칙의 표현형태도 자유 : psuedo code, 순서도 , 자연어 , 그림 모두 가능 .!

개념적으로 잘 만들어서 다음 KM 프로젝트에 활용할 수 있도록 하세요 .

제출물 A : 추상적인 규칙들이나 개념들

예 ) 부모님 말씀 , 경험 , 선인들의 명언 , 삼국지 전쟁전략 등

제출물 B : A 를 구체화 시켜 형식언어로 나타낸 규칙 혹은 데이터

Page 66: 인공지능 (Artificial Intelligence)

Supplement

Page 67: 인공지능 (Artificial Intelligence)

탐색의 개요 대부분의 인공지능 응용에 있어 기본이 되며 , 사실상 문제를 풀이하는 능력은 인간과 기계에 대한

지능을 평가하는 척도로서 자주 사용된다 .

두 가지 형태의 문제 : 계산과 탐색 성공을 보장하는 결정적인 절차 (procedure) 를 사용함으로써 해결될 수 있는 문제 계산 (computation)

이라고 부름 계산에 의한 풀이는 수학에서 그 절차가 존재하는 문제의 형태에 적용할 수 있음 컴퓨터가 실행할 수 있는 알고리즘의 형태로 변환가능

실세계의 문제들은 거의 계산적인 방법으로는 해결할 수 없으므로 탐색에 의한 해를 구하게 됨 .

따라서 , 인공지능으로부터의 접근이 필요 .

탐색방법의 성능 및 평가 척도 얼마나 빨리 해를 발견하는가 ?

발견된 해가 얼마가 좋은가 ?

67

Page 68: 인공지능 (Artificial Intelligence)

Blind Search 사전에 정보가 제공되지 않은 경우

초기 상태 , 연산자 , 목표상태를 판정하기 위한 검사이외에는 아무런 정보도 사용되지 않는다 .

예 ) 사전에 예정된 순서나 무작위로 노드를 탐색하는 방법 ( 나름…조직적이고 체계적인 방법 )

너비우선탐색 (BFS) :

초기노드의 모든 자식노드 , 즉 깊이 1 인 모든 노드들을 탐색 후 다음 깊이 2 인 노드들을 순서대로 탐색 큐의 첫번째 요소가 목표노드가 아니면 그 자식들을 큐에 추가하고 첫번째 요소 제거한다 .

장점 : 해가 존재한다면 , 연산자 적용횟수를 최소로 하는 최단 경로 찾기 보장 단점 : 가지수가 많거나 깊이가 깊은 그래프를 탐색할 경우 , 노드의 수가 기하급수적으로 증가 .. 메모리 공간을 많이

차지함

깊이우선탐색 (DFS) :

일반적으로는 적당한 깊이 제한을 두어 그 이상의 깊이를 갖게되면 해당 노드의 확장은 stop.

장점 : 구현하기 쉽고 , 가지수가 많은 상태공간에서 매우 유용 단점 : 해가없는 경로를 계속 탐색할 수 있기 때문에 필요에 따라 상위노드로 되돌아갈 수 있는 백트랙킹 필요

68

Page 69: 인공지능 (Artificial Intelligence)

BFS vs. DFS

69

A

B C

D E F G

A

B C

D E F G

H I J K L M

Page 70: 인공지능 (Artificial Intelligence)

70

Example of Lowest Cost Search

Closed list:

Open list:

a2 1

0a

Page 71: 인공지능 (Artificial Intelligence)

71

Example of Lowest Cost Search

Closed list:

Open list:

a

b c

2 1

1

2

1

2

2 1b c

a

Page 72: 인공지능 (Artificial Intelligence)

72

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 c

1

2

d e

2 2 3b d e

a c

Page 73: 인공지능 (Artificial Intelligence)

73

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 ccf

1

2

g d e

a c b

2 3 3 4d e f g

Page 74: 인공지능 (Artificial Intelligence)

74

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 ccf

1

2

g d e

3 3 4e f g

a c b d

Page 75: 인공지능 (Artificial Intelligence)

75

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 ccf

1

2

g d e

3 4f g

a c b d e

Page 76: 인공지능 (Artificial Intelligence)

76

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 ccf

1

2

g d e

4g

a c b d e f

Page 77: 인공지능 (Artificial Intelligence)

77

Example of Lowest Cost Search

Closed list:

Open list:

a

c

b c

2 1

1

2 ccf

1

2

g d e

a c b d e f g

Page 78: 인공지능 (Artificial Intelligence)

Forward Reasoning

특징들로부터 동물의 이름을 알아내는 IDENTIFIER

규칙 P1.  IF the animal has hair           THEN it is a mammal

규칙 P2.  IF the animal gives milk         THEN it is a mammal

규칙 P3.  IF the animal has feathers       THEN it is a bird

규칙 P4.  IF the animal flies  AND it lays egg   THEN it is a bird

규칙 P5.  IF the animal is a mammal AND it eats meat    THEN it is a carnivore

규칙 P6.  IF the animal is a mammal  AND it has pointed teeth

            AND it has claws AND its eyes point forward      THEN it is a carnivore

규칙 P7.  IF the animal is a mammal AND it has hoofs THEN it is an ungulate

규칙 P8.  IF the animal is a mammal AND it chew cud           THEN it is an ungulate

규칙 P11. IF the animal is an ungulate AND it has long legs AND it has a long neck

              AND it has a tawny color  AND it has dark spots     THEN it is a giraffe

규칙 P12. IF the animal is an ungulate    AND it has a white color

            AND it has black stripes        THEN it is a zebra

78

포유동물 (mammal)

인가

조류 (bird) 인가 ?

육식동물인가 ?

유제류 (ungulate) 인가 ?

발굽 (hoof) 이 있고 ,

되새김을 한다 .

Page 79: 인공지능 (Artificial Intelligence)

Forward Reasoning vs. Backward Reasoning

79

우유를 주다

포유동물

우유를 주다

되새김

긴 다리

긴 목

P2

P8

짝수발가락

유제품

기린

P11

Forward Reasoning

Rule 이 많으면 BFS 와 비슷한 성격

가능한 모든 추론이 가능 .

Backward Reasoning

Goal 을 먼저 설정하고 주어진 상황 ( 조건 ) 이 맞는지 보는 방법으로 DFS 와

비슷한 성격

Goal 을 찾을 경우 Reasoning 과정이 명확 !

Uncertainty Reasoning

전문가의 조언은 정확히 맞지 않는다 .

의사의 오진율은 평균 30%

Qualitative Reasoning 은 항상 모든 경우에 성립하지 않음 .

그럼에도 불구하고 전문가의 아마도 그럴거야…는 안듣는 것보다 좋다…

Mycin : stanford 의 의학전문가시스템 ( 내과 )

최초로 uncertainty reasoning 사용사람과 비슷한 수준의 처방능력 보이나70 년대 의대에서 사용거부 움직임… job security..

Page 80: 인공지능 (Artificial Intelligence)

Heuristic Search 무정보 탐색방법은 목표노드까지의 경로를 찾는데 상당히 소모적 .!

원칙적으로는 문제에 대한 해를 제공하지만 너무 많은 노드를 확장시키므로 실용적이지 못한 경우가 많음 .

탐색작업을 축소시키기 위해 ,( 항상 옳은 것은 아니지만 ) 잘 맞는 경험에 의한 규칙을 이용함 .

휴리스틱 정보는 비록 부정확하고 보장되지는 않지만 빠르게 해를 발견하거나 최적인 해를 발견하거나 또는 둘 다 만족할 수 있는 가능성을 증가시킨다 .

휴리스틱 정보를 이용할 때는 노드의 확장 순서를 정하기 위해 평가함수를 사용하여 , 노드들에게 순위를 매김으로써 어떤 것이 목표노드가지의 최상의 경로에 있음직한가를 결정한다 .

평가함수를 구하는 방법 :

노드가 가장 우수한 경로상태에 있는 확률을 정의하거나

노드와 목표 노드사이의 거리 또는 차의 척도를 제안하거나 ,

board 를 사용하는 게임의 경우 목표를 향하고 있는 국면에 있는가 어떤가에 관한 특징에 따라 정해짐 .

Hill Climbing , A* 알고리즘 , Game Tree, MiniMax

80

Page 81: 인공지능 (Artificial Intelligence)

81

Best First Search – Lisp Pro-gram

(defun best(nodes goalp next comparep) (cond ((null nodes) nil) ((funcall goalp (first nodes)) (first nodes)) (t (best (sort (append (funcall next (first nodes)) (rest nodes)) comparep) goalp next comparep))))

Page 82: 인공지능 (Artificial Intelligence)

거리 = 휴리스틱

82

Page 83: 인공지능 (Artificial Intelligence)

A* : Bucharest 까지의 경로 찾기

Greedy 알고리즘 h(n) = straight-line distance from n to

Bucharest

83

Sibiu

Arad Fagaras Oradea Rimnicu

Timisoara Zerind

Arad

366 380 193

329 374

253 0

Sibiu

366

253

176

Bucharest AHA: But not optimal!!!!

Page 84: 인공지능 (Artificial Intelligence)

84

A*-Search: An Example

Sibiu

Arad Fagaras Oradea Rimnicu

Timisoara Zerind

Arad

646=280+366 671=291+380 413=220+193

477=118+329 449=75+374

526=366+160 417=317+100

Craiova

366=0+366

393=140+253

415=239+176

Pitesti

553=300+253

Sibiu

591=338+253 450=450+0

Sibiu Bucharest

Optimal:418=418+0

Bucharest

615=455+160

Craiova Rimnicu

607=414+193

Page 85: 인공지능 (Artificial Intelligence)

A* : http://www.gameai.net/Article/Astar/Astar.htm

Lemma: A* expands nodes in order of increasing f-value Gradually adds “f-contours” of nodes (cf. breadth-first adds layers)

85

Page 86: 인공지능 (Artificial Intelligence)

Game Tree & And / Or Graph

Page 87: 인공지능 (Artificial Intelligence)

Game Tree : ' 상대의 손실은 곧 나의 이득 '

Zero-sum game

가정 : 한 플레이어에게 유리한 수는 상대 플레이어에게 불리한 수라는 것 !!

즉 ‘나’의 목표 : 보드의 평가를 내 쪽으로 최대화하는 방향으로 , 그리고 상대쪽으로 최소화하는 방향으로 플레이를 하는 것이다 .

87

Page 88: 인공지능 (Artificial Intelligence)

위와 같은 게임트리에서 ,

한 수준 깊이 검색을 한다면 한 플레이어는 최상의 결과 ( 보드 평가함수에 의해 정의된 ) 를 낼 수 있는 보드 위치로 말을 움직이면 된다 .

두 수준 깊이 검색에서 , 플레이어 1 은 플레이어 2 가 위에서 말한 방식대로 한 수준 깊이 검색을 수행할 것이라고 가정할 수 있다 . 따라서 플레이어 1 은 다음 턴에서 플레이어 2 가 최고의 결과를 얻지 못하게 하는 수 ( 플레이어 1 에게 최고의 수 ) 를 두게 된다 .

이런 방식으로 시간과 용량이 허용하는 한도 내에서 계속 깊이 들어가 상대에 대한 최소값을 찾음으로써 플레이어 자신에 대한 최대값을 얻는 게임트리 검색방법을 미니맥스 알고리즘이라 한다 .

[ 그림 2] 는 미니맥스 알고리즘을 사용한 예이다 . 위로 향하는 삼각형 노드는 자신의 수이고 , 아래로 향하는 삼각형 노드는 상대의 수이다 . 그리고 각각의 숫자는 자신을 기준으로 했을 때의 평가값 수치이다 .

그림처럼 두 단계 깊이까지만 탐색을 수행한다면 , 먼저 제일 밑의 노드들에서 각각 평가값들을 계산한다 .

그 위 노드에서 상대방은 하위 노드들중에서 평가값이 가장 작은수를 선택하게 된다 ( 자신을 기준으로 계산한 평가값이기 때문에 상대방에게는 가장 작은 평가값이 가장 좋은 수가 되기 때문이다 ).

그리고 다시 제일 위의 노드에서는 밑의 세 개의 노드중에서 평가값이 가장 큰 수를 선택하게 되는데 , 그래야만 상대가 선택하는 수가 가장 좋지 않은 수가 되고 그것이 또한 자신에게 가장 좋은 수가 되기 때문이다 .

88

Page 89: 인공지능 (Artificial Intelligence)

89

Alpha-Beta Pruning

http://www.gameai.net/Article/jangki_ai.pdf

Newell, Simon, Shaw (1958 년 ) 기본 아이디어 : 모든 노드의 정확한 평가치값이 아니라 다음 수를 선택할 때 여러 선택의 갈림길에서 어떠한 것이 가장 높은 평가치를 갖는가 하는 상대적인 평가만 할 수 있으면 된다 .

Page 90: 인공지능 (Artificial Intelligence)

Alpha-Beta Pruning 의 가지치기 : 탐색 중단 , 수 줄임

이 개념은 어떠한 경우 게임트리의 특정한 가지는 더 이상 탐색해 나갈 필요가 없다는 점에 기반한 것이다 .

위의 그림에서 왼쪽 노드들을 탐색하고 나면 현재까지 MIN 의 최소값이 3 이라는 것을 알 수 있다 . 그리고 가운데 노드들을 탐색했을 때 첫 노드의 평가치가 2 라면 , 이는 현재까지의 최소값인 3 보다 작기 때문에 상대방은 항상 이 노드를 선택하게 될 것이다 . 그러므로 자신은 절대 이 노드쪽으로 수를 두면 안되기 때문에 가운데 노드쪽으로는 선택하지 않게 될 것이다 . 그러므로 더 이상 가운데 노드의 자식들을 탐색을 수행할 필요가 없다 .

이를 좀더 일반화시킨다면 , ' 상대가 현재 위치 이후의 어떤 지점에서 더 유리한 결과를 얻을 수 있다면 , 현재 위치를 만드는 수는 나에게 무조건 불리하므로 더 이상 고려할 필요가 없다 ' 는 뜻이 된다 . 즉 나에게 불리한 수가 만들어지는 지점부터는 트리의 ' 가지를 쳐도(pruning)' 되는 것이다 .

어떤 노드에서 가지를 쳐도 될 것인가를 구체적으로 판단하려면 , 게임트리 검색의 매 순간마다 현재까지의 탐색에서 나에게 가장 유리한 수의 최대값과 상대에게 가장 유리한 최대값을 기억하고 있어야 한다 . 현재의 검색에서 상대의 현재 최대값이 나의 현재 최대값보다 크다면 그 부분 이하는 더 이상 고려할 필요가 없다 . 이 때 나의 현재 최대값을 알파 , 상대의 현재 최대값을 베타라고 부른다 .

90

Page 91: 인공지능 (Artificial Intelligence)

91

And/Or Graph Divide a problem into sub-problems and solve

them individually divide and conquer

And/Or Graph Node: sub-problems Links: And Link, Or Link

And : connect parent and sub-problems Or : represents alternatives

Page 92: 인공지능 (Artificial Intelligence)

92

Searching And/Or Graph(1) Objective of Search

To show whether start node is Solvable? or Unsolvable ?

Definition of Solvable Terminal node is solvable A non-terminal OR node is solvable if at least one of its

successor is solvable A non-terminal AND node is solvable iff all of its succes-

sors are solvable

Page 93: 인공지능 (Artificial Intelligence)

93

Searching And/Or Graph(2)

Definition of UnSolvable Non-Terminal node with no successor is unsolvable A non-terminal OR node is unsolvable iff all of its succes-

sors are unsolvable A non-terminal AND node is unsolvable if at least one of

its successors is unsolvable Search terminate when start node is labeled ei-

ther solvable or unsolvable

Page 94: 인공지능 (Artificial Intelligence)

94

Island Driven Search Idea: Find a set of islands between s, g s i1 i2 …. im-1 g Problem is to identify the islands Optimal solution not guaranteed Hierarchical abstraction can be used