+ All Categories
Home > Documents > Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is...

Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is...

Date post: 10-Oct-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
31
Data Structures and Algorithms Session 26. April 29, 2009 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3137
Transcript
Page 1: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Data Structures and AlgorithmsSession 26. April 29, 2009

Instructor: Bert Huanghttp://www.cs.columbia.edu/~bert/courses/3137

Page 2: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Announcements

Homework 6 due before last class: May 4th

Final Review May 4th

Exam Wednesday May 13th 1:10-4:00 PM, 633

Page 3: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Review

Finish Quicksort discussion,

worst case, average case

Quickselect

worst case, average case

External Sorting

Page 4: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Today's Plan

Examples of Data Structures used in Artificial Intelligence and Machine Learning

Game trees: minimax, search

Bayesian Graphs

kd-trees

Page 5: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Artificial Intelligence

Sub-field of Computer Science concerned with algorithms that behave intelligently

or if we're truly ambitious, optimally.

An AI program is commonly called an agent

which makes decisions based on its percepts

Page 6: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

A.I. in Games

AI still needs to simplify the environment for its agents, so games are a nice starting point

Many board games are turn-based, so we can take some time to compute a good decision at each turn

Deterministic turn-based games can be represented as game trees

Page 7: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Game Trees

The root node is the starting state of the game

Children correspond to possible moves

If 2-player, every other level is the computer's turn

The other levels are the adversary's turns

In a simple game, we can consider/store the whole tree, make decisions based on the subtrees

Page 8: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Partial Tic-Tac-Toe Game Tree

X

X

X

X O

X O

X

O

X

O

X

O

X

O

X

X X

O

X

X O

X

O X

X

O

O X

X

O

O X

X X

O

O X

X

O X

O X

X

X O

O X

Page 9: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Tree Strategy

Thinking about the game as a tree helps organize computational strategy

If adversary plays optimally, we can define the optimal strategy via the minimax algorithm

Assume the adversary will play the optimal move at the next level. Use that result to decide which move is optimal at current level.

Page 10: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Result

Simple TreeOur Turn

Win Lose Win Win

Lose Win

Page 11: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Result

Numerical RewardsOur Turn

+100 -1 +1 +2

-1 +1

Page 12: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Minimax Details

Depth first search (postorder) to find leaves; propagate information up

Adversary also assume you will play optimally

Impossible to store full tree for most games, use heuristic measures

e.g., Chess piece values, # controlled squares

Cut off after a certain level

Page 13: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Pruning

We can also ignore parts of the tree if we see a subtree that can't possibly be better than one we saw earlier

This is called alpha-beta pruning

Figure from wikipedia article on alpha-beta pruning

Page 14: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Search

Some puzzles can be thought of as trees too

15-puzzle, Rubik's Cube, Sudoku

Discrete moves move from current state to children states

A.I. wants to find the solution state efficiently

Page 15: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

8-puzzle8 5 3

2 1 4

6 7

8 5 3

2 1 4

6 7

8 5 3

2 1

6 7 4

8 5 3

2 1 4

6 7

8 5 3

2 4

6 1 7

8 5 3

2 1 4

6 7

8 5 3

2 1

6 7 4

8 5

2 1 3

6 7 4

8 5 3

2 1 4

6 7

Page 16: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Simple Idea

Breadth first search; level-order

Try every move from current state

Try 2 moves from current state

Try 3 moves from current state

...

Page 17: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Another Idea

Depth first search

Try a move

Try another move...

If we get stuck, backtrack

Page 18: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Heuristic Search

The main problem is without any knowledge, we are guessing arbitrarily

Instead, design a heuristic and choose the next state to try according to heuristic

e.g., # of tiles in the correct location, distance from maze goal

Page 19: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Probabilistic Inference

Some of these decisions are too hard to compute exactly, and often there is insufficient information to make an exact decision

Instead, model uncertainty via probability

An important application for graph theory is using graphs to represent probabilistic independence

Page 20: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Independent Coins

1. Suppose I flip coin twice, what is the probability of both flips landing heads?

2. Compare to if we flip a coin, and if it lands heads, we buy 2 lottery tickets. If tails, we buy 1 lottery ticket. What is the probability we will win the lottery?

In Scenario 1, we reason with less computation by taking advantage of independence

Page 21: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

A Simple Bayesian Network

Subway runs

Rain

Cloudy

Construction

Page 22: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Basic Rules of Thumb

Trees and DAGs are easier to reason

We can use similar strategy to Topological sort:

Only do computation once all incoming neighbors have been computed

Cyclic graphs are difficult; NP-hard in some settings

Page 23: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Machine LearningAnother related field, Machine Learning, handles making intelligent decisions after looking at data

e.g., a list of surveyed voters, their demographic information, answers to questions, location, etc.

We typically think of each of these data points as a high-dimensional vector

We need smart data structures to allow efficient spatial reasoning (e.g., finding nearest neighbors)

Page 24: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

kd-trees

A kd-tree is a multidimensional binary search tree

a BST that partitions in k-dimensions

Each node specifies a dimension (x, y or z).

Left subtree is less than node in that dimension

Right subtree is greater than node in that dimension

Page 25: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

2d-tree

x-axis

y-ax

is

A

B

C

A: y

C B

Page 26: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

2d-tree

x-axis

y-ax

is

A

B

C

A: y

C BD

D

Page 27: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

2d-tree

x-axis

y-ax

is

A

B

C

A: y

C B:xD

D

Page 28: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

3d-tree

From Wikipedia: kd-tree

Page 29: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Benefits of kd-trees

Finding the nearest neighbor of a point is more efficient

We don’t have to compute the distance between all other points

Only siblings and some more distant relatives

Reduces cost from O(Nk) to O(log N) if balanced, but worst case O(N1! 1

k k)

Page 30: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Summary

Three unrelated examples of Data Structures in A.I. and Machine Learning

Tree logic useful in analyzing games in A.I.

Graph theory useful in probabilistic reasoning

kd-trees allow fast computation for handling machine learning data

Page 31: Data Structures and Algorithms - cs.columbia.edubert/courses/3137/Lecture26.pdf · An AI program is commonly called an agent which makes decisions based ... Partial Tic-Tac-Toe Game

Final Topics Overview

Big-Oh definitions (Omega, little o)

Arraylists/Linked Lists

Stacks/Queues

Binary Search Trees: AVL, Splay

Tries

Heaps

Huffman Coding Trees

Hash Tables: Separate Chaining, Probing

Graphs: Shortest Path, Max-Flow, Min Spanning Tree, Euler

Complexity Classes

Disjoint Sets

Sorting: Insertion Sort, Shell Sort, Merge Sort, Quick Sort, Radix Sort, Quick Select


Recommended