Heuristic Function - Artificial Intelligence - Lecture Slides, Slides of Artificial Intelligence

Some concept of Artificial Intelligence are Agents and Problem Solving, Autonomy, Programs, Classical and Modern Planning, First-Order Logic, Resolution Theorem Proving, Search Strategies, Structure Learning. Main points of this lecture are: Heuristic Function, Best Move, Information, Algorithm, Game, Adaptation, Algedonics or Backpropagation, Knowledge, Rule Selection, Contingent Rule

Typology: Slides

2012/2013

Uploaded on 04/29/2013

shantii
shantii 🇮🇳

4.4

(14)

97 documents

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Heuristic Function
In a board game, before we make a move when we have various
options How do we know which is the best move?
Information
If I have an algorithm that guides to win the game (truth)
Adaptation
Through learning by trial and error (algedonics or backpropagation)
knowledge
Knowledge
By defining a heuristic function F that gives a sense of evaluation and
comparison between moves, allowing us to use a contingent rule
IF in state i THEN move to stake k /// rule selection
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Heuristic Function - Artificial Intelligence - Lecture Slides and more Slides Artificial Intelligence in PDF only on Docsity!

Heuristic Function

In a board game, before we make a move when we have various

options How do we know which is the best move?

Information

If I have an algorithm that guides to win the game (truth)

Adaptation

Through learning by trial and error (algedonics or backpropagation)

knowledge

Knowledge

By defining a heuristic function F that gives a sense of evaluation and

comparison between moves, allowing us to use a contingent rule

 IF in state i THEN move to stake k /// rule selection

1

Heuristic Function

In a board game, to arrive at that knowledge

  • I have to perceive some patterns from the

boards, this is, aspects that show a

comparative value among them

  • For example, we believe that the green

option is the best, although this is not an

absolute truth, nevertheless is knowledge

  • IF Black Panel
    • THEN Green Panel

2

How can we define the knowledge behind this opinion?

After some consideration we may come up with something like this:

BoardEvaluation = MyOpenOptions - TheirOpenOptions

Using this function we obtain for the three possible panels that:

BoardEvaluation(Yellow Board) = 8 - 5 = 3

BoardEvaluation( Green Board) = 8 - 4 = 4

BoardEvaluation( Red Board) = 8 - 6 = 2 BoardEvaluation(Black Board) = 8 - 8 = 0

A final note on the heuristic function. As we play further down the game,

the function may be have to be changed according to where in the game

we are.

 This is to say at the beginning the strategy of the game may be to achieve a

given position.

 In the middle of the game maybe the strategy lies in capturing pieces.

 Towards the end of the game it maybe that doing just one move is important.

Should this be the case, then we might have different X terms with

different factors a,p in the formula to accommodate the strategy at hand,

thus having different formulas according a the depth of the game

4

One or many Heuristic Functions

E(t) =∑aXp^ E(t+δt) =∑aXp^ E(t+2δt) =∑aXp

Jumping Ahead

However after I play my move, my opponents will

play theirs and if they are rational players, they will

use a criteria to select the move in order to get a

benefit and reducing the value of the board just

chosen by me.

Therefore I should evaluate not my next move, but a

combination of my move and theirs to determine my

best choice.

In their case I should consider not a maximization of

the formula E =∑aXp^ but rather, the minimization

since by reducing the value of the function from their

perspective they chooses a better board position.

Lets take a look

5

Evaluation

Evaluation

Evaluation Evaluation

Evaluation

MInimization

Evaluation

Evaluation Evaluation

Evaluation Evaluation

Evaluation

Evaluation

Evaluation

Evaluation

Evaluation Evaluation

Evaluation

Evaluation Evaluation

Evaluation

Minimization

Project 2 and Exam 1

• Note the requirements for project 2

  • Your E =∑aXp^ must beat the STM
  • The E =∑aXp^ must train the the STM, letting play it play first. After playing no more than 500 games. Most likely a set of formulas with various degrees will be necessary
  • For all three games: the evaluation should be done using recursive alpha beta (2 ply ) and should do well when playing against a human

• Note the date of the next project:

Monday March 7

7

MiniMax

The algorithm to evaluate the next move will work bottom up as follows:

1. Branch down two levels (known as one ply)

2. Evaluate all the boards

3. Minimize by selecting the board with minimum value

4. Move up one level

5. Maximize by selecting the board with the best value

6. This is the best move

with a given value from the function

It is called MINImize MAXimize (MINIMAX)

8

Selected move

MiniMax

Now in reality one should try branch the tree further down than one ply, the closer

we get to the end of the game the closer to the truth our knowledge will be.

As a matter of fact, many computer games that you play have generally three

levels: novice, medium, expert. Well the expertise mostly likely reflect how far they

branch down, most of the time we deal with 1,2 and 3 ply’s. The further you go

down, the longer it will take to decide.

Nowadays faster machines are able to go as far as down as twelve ply’s. Imagine

just the number of boards to evaluate.

eval = > minimize - maximize - minimize - maximize - minimize -maximize

=> select

10

Applying minimax

11

Big trees

So what do you when you have a tree with many branches you do not

need

You prune it, don ’ t you?

Back in the sixties, A. Samuel did it, he called his algorithm

the α β pruning

The idea behind is that the values in the upper two nodes already selected

might preclude some nodes to be considered

13

α β pruning

14

X

X

X

Max

<=

Min

Eval

<=

does

not go

does not go

does not go

goes up

goes up and stops does^ ^ >=3) not go

goes up

as β

goes up and stops!

goes up

as α

does not go does not go

<=

An example of Alpha-beta pruning

16

max

max

max

min

min

Source: www.cs.umbc.edu/~ypeng/F02671/lecture-notes/Ch05.pptt Docsity.com

Final tree

17

max

max

max

min

min

Source: www.cs.umbc.edu/~ypeng/F02671/lecture-notes/Ch05.pptt Docsity.com

Pseudo Code α β

public class Minimax with alpha beta pruning int[] BOARD = new int[3] // BOARD[1] is the board number // BOARD[2] is the evaluation of the board //BOARD[3] is the number of possible boards that open from this one int[] POSSIBLE = new int[3] ; int[] MinBOARD = new int[3]; int[] MaxBOARD = new int[3] ; int play, plyLimit, depthGrow ; // define desired board, play and depth

// Recursive MINIMAX public void init() { plyLimit = depth ; game = "playing"; while (Game = "playing") { BOARD = Maximize(BOARD,alpha, beta, 1); display(BOARD); game = EvaluateEnd(BOARD); if game=“playing” {BOARD = otherPlay (BOARD); game = EvaluateEnd(BOARD); } } ; };

19

Maximize method int[] Maximize(BOARD,alpha,beta,depthGrow) { alpha = -infinite; for ( j= 1; j <= BOARD[3] ; j=j+1 ) { MaxBOARD = NextBoard(j,BOARD); POSSIBLE = Minimize(MaxBOARD,alpha,beta,depthGrow); if ( beta > alpha ) alpha = beta; if alpha >= POSSIBLE[2] then BOARD = POSSIBLE }; return BOARD ; }

// Evaluate method float Evaluate(int[3] BOARD) { // determines the value of the function for the board }

// Evaluate End method String EvaluateEnd(int[3] BOARD) { // determines if the games has ended }

// Display Board void display(int[3] BOARD) { // display board over the interface }

// Next Board Method int NextBoard(int j, int[3] BOARD) { // determines the next sequential board }

// Minimize Method int[] Minimize(BOARD,alpha,beta,depthGrow) {depthGrow = depthGrow +1; pruning = "in process" ; beta = + infinite ; for ( j = 1; j <= BOARD[3] AND pruning = "in process" ; j=j+1 ) { MinBOARD = NextBoard(j, BOARD); if ( depthGrow = plyLimit ) POSSIBLE[2] = Evaluate(MinBOARD[1]) else POSSIBLE = Maximize(MinBOARD, alpha, beta, depthGrow); } if ( MinBOARD[2] <= beta ) { BOARD = POSSIBLE ; beta = MinBOARD[2] ; if (beta <= alpha) pruning = "done" ; } } Return BOARD }

Bigger trees?

If you have still a bigger tree you can always do a Crash Cut,

The idea behind this pruning is to cut a complete sub tree

before branching if you do not like a given type of move

For example, in chess, lets say you do not care to

exchange your queens, therefore that whole sub tree is

chopped off

20