0% found this document useful (0 votes)
5 views

unit 2 AI part 2

The document discusses heuristic functions and their application in solving problems like the 8-puzzle, emphasizing the importance of heuristic functions for finding optimal solutions. It also covers local search algorithms, adversarial search, and the minimax algorithm, including techniques like alpha-beta pruning to improve efficiency. Additionally, it highlights the significance of understanding opponent behavior in multi-agent environments, particularly in game playing scenarios.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

unit 2 AI part 2

The document discusses heuristic functions and their application in solving problems like the 8-puzzle, emphasizing the importance of heuristic functions for finding optimal solutions. It also covers local search algorithms, adversarial search, and the minimax algorithm, including techniques like alpha-beta pruning to improve efficiency. Additionally, it highlights the significance of understanding opponent behavior in multi-agent environments, particularly in game playing scenarios.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Artificial

Intelligence
Unit 2 (Part 2)
Heuristic Functions
• Heuristic means finding solution to a problem quickly and
efficiently.
• The 8-puzzle was one of the earliest heuristic search
problems. As mentioned earlier, the object of the puzzle is to
slide the tiles horizontally or vertically into the empty space
until the configuration matches the goal configuration.
• The average solution cost for a randomly generated 8-puzzle
instance is about 22 steps. The branching factor is about 3.
(When the empty tile is in the middle, four moves are
possible; when it is in a corner, two; and when it is along an
edge, three.) This means that an exhaustive tree search to
depth 22 would look at about 3**22 ≈ 3.1 × 10**10 states.
• If we want to find the shortest solutions, we need a heuristic
function.
Heuristic Function:
h(n) = h1(n) + h2(n)
Where,
h1(n) = the number of misplaced tiles.
h2 (n) = the sum of the distances of the tiles from their
goal positions.
h1(n) = Here, all of the eight tiles are out of
position, so the start state would have h1(n) = 8.
h2(n) = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18.
h(n) = 8 +18 = 26.
• It is easy to see from the definitions of the two
heuristics that, for any node n, h2(n) ≥ h1(n).
Generating admissible
heuristics from relaxed
problems
• If the rules of the puzzle were changed so that a tile
could move anywhere instead of just to the adjacent
empty square, then h1(n) would give the exact
number of steps in the shortest solution.
• Similarly, if a tile could move one square in any
direction, even onto an occupied square, then h2
would give the exact number of steps in the shortest
solution.
• A problem with fewer restrictions on the actions is
called a relaxed problem.
• If a problem definition is written down in a formal
language, it is possible to construct relaxed problems
automatically.
• For example, if the 8-puzzle actions are described as:
• A tile can move from square A to square B if A is
horizontally or vertically adjacent to B and B is blank,
• we can generate three relaxed problems by
removing one or both of the conditions:
• (a) A tile can move from square A to square B if A is
adjacent to B.
• (b) A tile can move from square A to square B if B is
blank.
• (c) A tile can move from square A to square B.
Generating admissible
heuristics from subproblems:
Pattern databases
• Admissible heuristics can also be derived from the
solution cost of a subproblem of a given problem.
• The subproblem involves getting tiles 1, 2, 3, 4 into their
correct positions. Clearly, the cost of the optimal solution of
this subproblem is a lower bound on the cost of the
complete problem.
• One might wonder whether the heuristics obtained from the
1-2-3-4 database and the 5-6-7-8 could be added, since the
two subproblems seem not to overlap. Would this still give
an admissible heuristic?
• The answer is no, because the solutions of the 1-2-3-4
subproblem and the 5-6-7-8 subproblem for a given state
will almost certainly share some moves—it is unlikely that 1-
2-3-4 can be moved into place without touching 5-6-7-8, and
vice versa.
• we record not the total cost of solving the 1-2- 3-4
subproblem, but just the number of moves involving 1-2-3-4.
Learning heuristics from
experience
• “Experience” here means solving lots of 8-
puzzles, for instance. Each optimal solution to an
8-puzzle problem provides examples from which
h(n) can be learned.
• From these examples, a learning algorithm can
be used to construct a function h(n) that can
predict solution costs for other states that arise
during search.
h(n) = c1x1(n) + c2x2(n)
• The constants c1 and c2 are adjusted to give the
best fit to the actual data on solution costs.
LOCAL SEARCH ALGORITHMS
AND OPTIMIZATION PROBLEMS
• When a goal is found, the path to that goal also
constitutes a solution to the problem. In many
problems, however, the path to the goal is irrelevant.
• For example, in the 8-queens problem, what matters is
the final configuration of queens, not the order in which
they are added.
• The same general property holds for many important
applications such as integrated-circuit design, factory-
floor layout, job-shop scheduling, automatic
programming, telecommunications network
optimization, vehicle routing, and portfolio
management.
LOCAL SEARCH ALGORITHMS
• In addition to finding goals, local search algorithms are
useful for solving pure optimization problems, in which
the aim is to find the best state according to an
objective function.
• Hill-climbing search
• Simulated annealing
• Local beam search
• Genetic algorithms
Hill-climbing search
• It is simply a loop that continually moves in the
direction of increasing value—that is, uphill.
• It terminates when it reaches a “peak” where no
neighbor has a higher value.
• The algorithm does not maintain a search tree, so the
data structure for the current node need only record the
state and the value of the objective function.
• Hill climbing does not look ahead beyond the immediate
neighbors of the current state.
• Hill climbing is sometimes called greedy local search
because it grabs a good neighbor state without thinking
ahead about where to go next.
Hill climbing often gets stuck for the
following reasons:
1. Local maxima: a local maximum is a peak
that is higher than each of its neighboring
states but lower than the global maximum.
2. Ridges: Ridges result in a sequence of local
maxima that is very difficult for greedy
algorithms to navigate.
3. Plateaux: a plateau is a flat area of the state-
space landscape. It can be a flat local
maximum, from which no uphill exit exists.
Simulated annealing
• Simulated annealing is a probabilistic algorithm
which tests points across a solution space to find
the lowest minima.
• The algorithm is termed “simulated annealing”
because it mirrors physical annealing, a process
in which a material is repeatedly heated and
cooled to elicit desired structural properties.
• It is used to solve VLSI layout problems.
• It has been applied widely to factory scheduling
and other large-scale optimization tasks.
Local beam search
• Keeping just one node in memory might seem to be an
extreme reaction to the problem of memory limitations.
The local beam search algorithm keeps track of k states
rather than just one.
• It begins with k randomly generated states. At each
step, all the successors of all k states are generated. If
any one is a goal, the algorithm halts. Otherwise, it
selects the k best successors from the complete list and
repeats.
• A variant called stochastic beam search, instead of
choosing the best k from the the pool of candidate
successors, stochastic beam search chooses k
successors at random.
Genetic algorithms
• A genetic algorithm, in which successor states are
generated by combining two parent states rather than
by modifying a single state.
• GAs begin with a set of k randomly generated
states, called the population. Each state, or
individual, is represented as a string over a
finite alphabet—most commonly, a string of 0s
and 1s.
• The production of the next generation of states
is rated by the objective function, or the fitness
function.
• For each pair to be mated, a crossover point is
chosen randomly from the positions in the string.
• Finally, each location is subject to random
mutation with a small independent probability.
Constraint Satisfaction
Problems
• Solve the following map coloring problem using
Constraint Satisfaction problem with Domain = {red,
blue, green}

• Solve the following crypt arithmetic puzzle using Constraint


Satisfaction problem with Domain = {0,1,2,3,4,5,6,7,8,9}
Adversarial Search
• Adversarial search is a search, where we examine
the problem which arises when we try to plan
ahead of the world and other agents are planning
against us.
• In previous topics, we have studied the search
strategies which are only associated with a single
agent that aims to find the solution which often
expressed in the form of a sequence of actions.
• But, there might be some situations where more
than one agent is searching for the solution in the
same search space, and this situation usually
occurs in game playing.
• The environment with more than one agent is
termed as multi-agent environment, in which
each agent is an opponent of other agent and
playing against each other. Each agent needs to
consider the action of other agent and effect of
that action on their performance.
• So, Searches in which two or more players with
conflicting goals are trying to explore the same
search space for the solution, are called
adversarial searches, often known as Games.
• The Minimax Algorithm
• Alpha-Beta Pruning
• A game can be defined as a type of search in AI which can be
formalized of the following elements:
• Initial state: It specifies how the game is set up at the start.
• Player(s): It specifies which player has moved in the state
space.
• Action(s): It returns the set of legal moves in state space.
• Result(s, a): It is the transition model, which specifies the
result of moves in the state space.
• Terminal-Test(s): Terminal test is true if the game is over, else
it is false at any case. The state where the game ends is called
terminal states.
• Utility(s, p): A utility function gives the final numeric value for
a game that ends in terminal states s for player p. It is also
called payoff function. For Chess, the outcomes are a win, loss,
or draw and its payoff values are +1, 0, ½. And for tic-tac-toe,
utility values are +1, -1, and 0.
Adversarial Search
Chapter 5.1-5.3

24
Games vs. search problems
"Unpredictable" opponent  specifying a move for every
possible opponent reply

• Time limits  unlikely to find goal, must approximate

25
Game search

• Game-playing programs developed by AI researchers since


the beginning of the modern AI era
• Programs playing chess, checkers, etc (1950s)
• Specifics:
• Sequences of player’s decisions we control
• Decisions of other player(s) we do not control
• Contingency problem: many possible opponent’s moves
must be “covered” by the solution
• Opponent’s behavior introduces uncertainty
• Rational opponent – maximizes its own utility (payoff)
function
26
Game Search Problem
• Problem formulation
• Initial state: initial board position + whose move it is
• Operators: legal moves a player can make
• Goal (terminal test): game over?
• Utility (payoff) function: measures the outcome of the game
and its desirability
• Search objective:
• Find the sequence of player’s decisions (moves) maximizing
its utility (payoff)
• Consider the opponent’s moves and their utility

27
Game tree (2-player, deterministic,
turns)

28
Minimax Algorithm
• How to deal with the contingency problem?
• Assuming the opponent is always rational and always
optimizes its behavior (opposite to us), we consider the best
opponent’s response
• Then the minimax algorithm determines the best move

29
Minimax
Perfect play for deterministic games

• Idea: choose move to position with highest minimax value
= best achievable payoff against best play

• E.g., 2-ply game: [will go through another eg in lecture]

30
Minimax. Example

31
32
Complexity of the minimax
algorithm

33
Solution to the complexity problem

34
Alpha Beta Pruning
• Some branches will never be played by rational players
since they include sub-optimal decisions for either
player
• First, we will see the idea of Alpha Beta Pruning
• Then, we’ll introduce the algorithm for minimax with
alpha beta pruning, and go through the example again,
showing the book-keeping it does as it goes along

35
Alpha beta pruning. Example

36
Minimax with alpha-beta pruning:
The algorithm
• Maxv: function called for max nodes
• Might update alpha, the best max can do far
• Minv: function called for min nodes
• Might update beta, the best min can do so far

• Each tests for the appropriate pruning case


• We’ll go through the algorithm on the course website

37
Algorithm example: alphas/betas
shown

38
Properties of α-β
Pruning does not affect final result

Good move ordering improves effectiveness of pruning


• With "perfect ordering," time complexity = O(bm/2)


 doubles depth of search

A simple example of the value of reasoning about which


computations are relevant (a form of metareasoning)
• 39
40
Design of evaluation functions

41
Further extensions to real games

42

You might also like