introduction to computer science lecture 10: artificial...

35
Introduction to Computer Science Lecture 10: Artificial Intelligence Tian-Li Yu Taiwan Evolutionary Intelligence Laboratory (TEIL) Department of Electrical Engineering National Taiwan University [email protected] Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu Tian-Li Yu Artificial Intelligence 1 / 35

Upload: others

Post on 28-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Introduction to Computer ScienceLecture 10: Artificial Intelligence

Tian-Li Yu

Taiwan Evolutionary Intelligence Laboratory (TEIL)Department of Electrical Engineering

National Taiwan University

[email protected]

Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu

Tian-Li Yu Artificial Intelligence 1 / 35

Page 2: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

What is AI?

Cognitive Science LogicistIs that human?

Think like humans Think rationally

Act like humans Act rationally

Turing (1950) Test

Eliza:chayden.net/eliza/Eliza.html

www.jabberwacky.com

Natural language processingKnowledge representation

Automated reasoningMachine learning

Rational Agent

Tian-Li Yu Artificial Intelligence 2 / 35

Page 3: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Strong AI vs. Weak AI

Weak AI- Machines can be programmed to exhibit intelligent behavior.

Strong AI- Machines can be programmed to possess intelligence and consciousness.

John Searle’s Chinese room argument.

Tian-Li Yu Artificial Intelligence 3 / 35

Page 4: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Levels of Intelligent Behaviors

Reflex: actions are predetermined responses to the input data

More intelligent behavior requires knowledge of the environment and involves suchactivities as:

- Goal seeking- Learning

Tian-Li Yu Artificial Intelligence 4 / 35

Page 5: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Research Approaches in AI

Performance oriented- Engineering track- To maximize the performance of the agents.

Simulation oriented- Theoretical track- To understand how the agents produce responses.

Tian-Li Yu Artificial Intelligence 5 / 35

Page 6: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Understanding Images

Template matching

Image processing- edge enhancement- region finding- smoothing

Image analysis- Hough transformation (line,

circles)

Tian-Li Yu Artificial Intelligence 6 / 35

Page 7: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Natural Language Processing

Syntactic analysis- Mary gave John a birthday card. Subject: Mary- John got a birthday card. Subject: John

Semantic analysis, contextual analysis- John drove me home.- John drove me crazy.

- The pigpen was built by the barn.- The pigpen was built by the farmer.

- Do you know what time it is?

Tian-Li Yu Artificial Intelligence 7 / 35

Page 8: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Natural Language Processing (contd.)

Information retrieval / extraction- I’ve got a solution to your problem.- Shoot.- Right.

- How was your date last night?- He/She has a good personality.

- You can count on me.- Ya, right. That’s comforting.

Tian-Li Yu Artificial Intelligence 8 / 35

Page 9: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Reasoning

Production systems- Collection of states including initial state & goal state(s)- Collection of productions: rules or moves- Each production may have preconditions- Control system: decides which production to apply next

Recall prologSimilar to finite state automata

S1 S2

0

0

11

Tian-Li Yu Artificial Intelligence 9 / 35

Page 10: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Search a Production System

1 2 3

4 6

7 5 8

1 2 3

4 5 6

7 8

1 2 3

4 5 6

7 8

1 2 3

4 5 6

7 8

1 2 3

4 5

7 8 6

1 2

4 5 3

7 8 6

1 2 3

4 5

7 8 6

Goal

Tian-Li Yu Artificial Intelligence 10 / 35

Page 11: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Computer Game Playing

Let’s meet an old friend- Tic-tac-toe

© © ×

×

×

Tian-Li Yu Artificial Intelligence 11 / 35

Page 12: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Game Tree & Minimax Search

O O X

X

O X

O O X

X

O X X

O O X

X X

O X

O O X

X X

O X

O O X

O X X

O X

O O X

X X

O X O

O O X

X X X

O X O

O O X

O X

O X X

O O X

X O

O X X

O O X

X X O

O X X

O O X

X X

OO X

O O X

X X

O X

O

O O X

X X O

O X X

O O X

X X X

O X O

O’s turn (MIN)

O’s turn (MIN)

X’s turn (MAX)

X’s turn (MAX)

0

-1 -1 0

00

0 0

+1 +1

+1+1

-1-1

Tian-Li Yu Artificial Intelligence 12 / 35

Page 13: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Heuristic

For most games, a complete search is practically impossible.- Chess ∼ 1047; Chinese chess ∼ 1048; Go ∼ 10171

A quantitative estimate of the distance to a goal is needed.

Requirements for good heuristics- Much easier to compute than a complete solution- Reasonable estimate of proximity to a goal

Tian-Li Yu Artificial Intelligence 13 / 35

Page 14: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Let’s Define a Heuristic

XX 100X 10

0OX* 0O -10OO -100

© © ×

×

×

−→0+10+10-10+0+10+0+100 = 120

The board favors X

Tian-Li Yu Artificial Intelligence 14 / 35

Page 15: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Does It Work?

O O X

X

X

O O X

X

O X

O O X

O X

X

O O X

X

X O

O O X

X O

X

-80 100 10020

This is the best choice for O based on our heuristic.

Tian-Li Yu Artificial Intelligence 15 / 35

Page 16: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

How About This?How About This?

O

O X O X O

X

O

X

O

X

O

X

-10 0 10 -10 -10 0

O X

X

O

O X

X

O

90 100

O X

X

O O

Doomed!!

Tian-Li Yu Artificial Intelligence 16 / 35

Page 17: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

What’s Wrong?

Heuristics are not perfect- Otherwise, we’d call them solutions

Heuristics are usually more accurate toward the end of the game.

Need some search procedure for more accurate estimation.

Tian-Li Yu Artificial Intelligence 17 / 35

Page 18: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Heuristic + Minimax Search

O

X

O X

X

O

O X

X

O

O X O

X

O

O X

O X

O

O X

X O

O

O X

X

O O

O X

X

O O

O O X

X

O

O X

O X

O

O X

X

O O

-10 -10 -10

-100 -100

Min: -100

90 0 -180

Min: -180

Max: -100

Tian-Li Yu Artificial Intelligence 18 / 35

Page 19: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Alpha-Beta Pruning

O

X

O X

X

O

O X

X

O

O X O

X

O

O X

O X

O

O X

X O

O

O X

X

O O

O X

X

O O

O O X

X

O

O X

O X

O

O X

X

O O

-10 -10 -10

-100 -100

Min: -100

Not evaluated yet -180

Min: -180

Max: -100

Tian-Li Yu Artificial Intelligence 19 / 35

Page 20: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Learning

Supervised vs. unsupervised

Supervised- Learning by provided examples- Imitation- Parameter tuning

Unsupervised- Learning by experiences- Reinforcement- Evolutionary (semi-supervised)

Tian-Li Yu Artificial Intelligence 20 / 35

Page 21: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Artificial Neural Networks

Human brain- 1011 neurons- 1014 synapses

Tian-Li Yu Artificial Intelligence 21 / 35

Page 22: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Perceptron

-0.5

0

0.5

1

1.5

-5 -4 -3 -2 -1 0 1 2 3 4 5

f(x)

x

-0.5

0

0.5

1

1.5

-5 -4 -3 -2 -1 0 1 2 3 4 5

f(x)

x

w1

v1

v2

v3

w2

w3

Processing unit

Compute effective input:

V1W1+V2W2+V3W3

Compare effective

input to threshold

value.

Produce

output of

0 or 1

1 iff greater than or equal to the thresholdTian-Li Yu Artificial Intelligence 22 / 35

Page 23: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Some Building Blocks

ANDx −→ 1 1.5

1−→

y −→

ORx −→ 1 0.5

1−→

y −→

SIGNx −→ 1 0 −→

Tian-Li Yu Artificial Intelligence 23 / 35

Page 24: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Some Examples

x

y

1

0

0

1

x=2

x −→ 1 2 −→ output

x

y

0

1

x=y

x −→ 1 0-1−→ outputy −→

Tian-Li Yu Artificial Intelligence 24 / 35

Page 25: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

The XOR Problem

x

y

1

1

0

0

11.5

1

-1-0.5

-1

x

y

10.5

1output

1 0

1 0

Tian-Li Yu Artificial Intelligence 25 / 35

Page 26: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Associative Memory

Content addressable

.5

.5

.5

.5

.5

.51

1 1

-1

-1-1

-1

-1

-1

1

11 -1.5

Tian-Li Yu Artificial Intelligence 26 / 35

Page 27: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

How Does It Worka.

Start: All but the rightmost unitsare excited

b.

Step 1: Only the leftmost unitsremain excited

c.

Step 2: The top and bottom unitsbecome excited

d.

Final: All the units on theperimeter are excited

Tian-Li Yu Artificial Intelligence 27 / 35

Page 28: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Example

BAM applet: http://www.cbu.edu/˜pong/ai/bam/bamapplet.html

Tian-Li Yu Artificial Intelligence 28 / 35

Page 29: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Darwin’s Theory of Evolution

Evolution- The change in populations of organisms over generations.

Darwin’s idea: Natural selection- Struggle to survive- Survival of the fittest- Genetic variation: inherited traits

Tian-Li Yu Artificial Intelligence 29 / 35

Page 30: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Black-Box Optimization

x −→ f −→ y

Finding the x that yields the highest y with an unknown fEvolving the giraffe that is the fittest in an unknown environment.Instead of finding a solution, let’s evolve a solution.

Tian-Li Yu Artificial Intelligence 30 / 35

Page 31: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

(1+1) Evolutionary Strategy

Simplest evolutionary strategy

One parent: n-dimension real vector, P = (p1, ...,pn)

Generate one child by mutation: C = (c1, ..., cn)

- ci = pi + N(0, σ2)

Replace P by C if C is better.Modify σ according to the replacement rate r.

- One fifth rule

Tian-Li Yu Artificial Intelligence 31 / 35

Page 32: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

1/5 Rule Intuition

σ← σ/C1/n, if r > Θ

σ← σ · C1/n, if r < Θ

If replacement rate high, not exploring enough→ increase step size.

If replacement rate low, too daring→ reduce step size.

Θ = 1/5 (Guessed by Rechenberg) and C = 0.817 (Progress analysis by Schwefel)

Tian-Li Yu Artificial Intelligence 32 / 35

Page 33: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Visualization of 1/5 Rule

σ too small

optimum

contours of

constant f

σ too large

Tian-Li Yu Artificial Intelligence 33 / 35

Page 34: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

Training NN with (1+1)ES

x

yo

Target:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++....++++++++++++++++++++++++++...+++++++++++++++++

++++++++++++++++++.......++++++++++++++++++++++++.....++++++++++++++++

+++++++++++++++++.........++++++++++++++++++++++.......+++++++++++++++

++++++++++++++++...........++++++++++++++++++++........+++++++++++++++

++++++++++++++++............++++++++++++++++++..........++++++++++++++

.++++++++++++++.............++++++++++++++++++...........+++++++++++++

..++++++++++++...............++++++++++++++++............+++++++++++++

...++++++++++.................++++++++++++++..............++++++++++++

....++++++++..................++++++++++++++..............++++++++++++

.....++++++....................++++++++++++................+++++++++++

.......++.......................+++++++++++................+++++++++++

................................++++++++++..................++++++++++

.................................++++++++...................++++++++++

..................................++++++.....................+++++++++

...................................++++......................+++++++++

..............................................................++++++++

x

y

o

5 neurons, 17 parameters++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++...+++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++.....++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++.......+++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++........+++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++..........++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++...........+++++++++++++

...++++++++++++++++++++++++++++++++++++++++++............+++++++++++++

..........++++++++++++++++++++++++++++++++++..............++++++++++++

.................++++++++++++++++++++++++++...............++++++++++++

.......................++++++++++++++++++++................+++++++++++

..............................++++++++++++.................+++++++++++

....................................++++....................++++++++++

............................................................++++++++++

.............................................................+++++++++

.............................................................+++++++++

..............................................................++++++++

4 neurons, 18 parameters++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++....++++++++++++++++++++++++++..++++++++++++++++++

+++++++++++++++++++......++++++++++++++++++++++++....+++++++++++++++++

++++++++++++++++++........++++++++++++++++++++++......++++++++++++++++

+++++++++++++++++..........++++++++++++++++++++........+++++++++++++++

.+++++++++++++++............++++++++++++++++++..........++++++++++++++

.++++++++++++++.............++++++++++++++++++..........++++++++++++++

..++++++++++++...............++++++++++++++++............+++++++++++++

...++++++++++.................++++++++++++++..............++++++++++++

....++++++++..................++++++++++++++..............++++++++++++

.....++++++....................++++++++++++................+++++++++++

......+++.......................++++++++++..................++++++++++

................................++++++++++..................++++++++++

.................................++++++++....................+++++++++

..................................++++++......................++++++++

...................................++++.......................++++++++

....................................++.........................+++++++

Total Differences: 172(123.084600)/1540

Tian-Li Yu Artificial Intelligence 34 / 35

Page 35: Introduction to Computer Science Lecture 10: Artificial ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS19L01.pdf · Introduction to Computer Science Lecture 10: Artificial Intelligence

License

Page File Licensing Source/ author

28”BAM applet”.,Author:[email protected], Source: http://

dilbert.com/strips/comic/1996-05-02/, Date:2013/03/06, Fairuse under copyright law 46,52,65.

6

”Edge detection applied to a photograph”.,Author:JonMcLoone, Source: http://en.wikipedia.org/wiki/

File:EdgeDetectionMathematica.png, Date:2013/03/06, This workis licensed under the Creative Commons Attribution-ShareAlike 3.0 Li-cense.

Tian-Li Yu Artificial Intelligence 35 / 35