0% found this document useful (0 votes)
19 views22 pages

AI Lec 10

Uploaded by

Saptiva Goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views22 pages

AI Lec 10

Uploaded by

Saptiva Goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Artificial Intelligence

Lecture – 10
Prepared By: Prof (Dr.) Anirban Bose
Dept.: Computer Science & Engineering
Dr. B. C. Roy Engineering College, Durgapur
2 Simulated Annealing
 In metallurgy, annealing is the process used to temper or harden metals and glass by
heating them to a high temperature and then gradually cooling them, thus allowing the
material to reach a low energy crystalline state.

 The loop of the simulated-annealing algorithm is quite similar to hill climbing. Instead of
picking the best move, however, it picks a random move.
 If the move improves the situation, it is always accepted. Otherwise, the algorithm accepts
the move with some probability less than 1.
3 An Example
Initial State – S
1 2 3
Goal State – G
4 5 Cost/Heuristic Function, E(n) – No. of Misplaced Tiles
6 7 8 Temperature, T – 100
Cooling Schedule – 0.95
Start (S) Transition Function – Function to generate a neighbouring
state from the current state.
Acceptance Probability, P -
DeltaE,E – E(n’) – E(n)

1 2 3 Algo:
while(iter <= MaxIter)
4 5 6
while(T > Tmin )
7 8 n’ = generateNeighbour(n)
deltaE(n, n’, T)
Goal (G)
if(deltaE <= 0 or r <= P)
n n’
T T*0.95
iter iter + 1
4 Simulated Annealing…

 The probability decreases exponentially with the “badness” of the move—the amount ΔE
by which the evaluation is worsened.

 The probability also decreases as the “temperature” T goes down: “bad” moves are more
likely to be allowed at the start when T is high, and they become more unlikely as T
decreases.

 If the schedule (mapping of time to temperature and how fast the temperature decreases is
called the Annealing Schedule) lowers T slowly enough, the algorithm will find a global
optimum with probability approaching 1.
5 Genetic Algorithms
 A genetic algorithm (or GA) is a variant of stochastic beam search in which successor
states are generated by combining two parent states rather than by modifying a single state.
 Like beam searches, 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. For example, an 8-queens state must specify the positions of 8
queens, each in a column of 8 squares, and so requires 8 × log 2 8 = 24 bits.
 Alternatively, the state could be represented as 8 digits, each in the range from 1 to 8.
 Each state is rated by the objective function, or (in GA terminology) the fitness function.
 A fitness function should return higher values for better states.
6 How GA Works?
7 Operators in GA

 Selection: It is one of the most popular ways of parent selection. In this every individual
can become a parent with a probability which is proportional to its fitness.

 Crossover: The crossover operator is analogous to reproduction and biological crossover.


In this more than one parent is selected and one or more off-springs are produced using the
genetic material of the parents. Crossover is usually applied in a GA with a high
probability.

 Mutation: It may be defined as a small random tweak in the chromosome, to get a new
solution. It is used to maintain and introduce diversity in the genetic population and is
usually applied with a low probability.
8 Operators in Action
Fitness Function: X2 (Minimization)

1 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0
pa1 off1

0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1
pa2 off2
Crossover point
pa1 fitness value: 1672=27889 off1 fitness value: 26896
pa2 fitness value = 784 off2 fitness value = 961

1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0
off1 off1 off1 fitness value: 25600
off2 fitness value = 729
0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1
off2 Mutation point off2
9 8 - Queens
 Problem: placing eight queens on an 8×8
chessboard such that none of them attack one
another (no two are in the same row, column,
or diagonal).
 States: All configuration of the chessboard
with queens.
 State Transition Model: Moving a queen in
distinct places within a column.
 Fitness Function: Number of pairs of non-
attacking queens in a particular state.
10 8 - Queens

 Genetic Algorithms do not require any derivative information.


 Genetic Algorithms are faster and efficient when compared to the traditional methods of
brute-force search.
 Genetic Algorithms is proven to have many parallel capabilities
 Optimizes both continuous and discrete functions and also multi-objective problems.
11 Constraint Satisfaction Problem
 A constraint satisfaction problem consists of three components, X, D, and C:
 X is a set of variables, {X1, . . . , Xn}.
 D is a set of domains, {D1, . . . , Dn}, one for each variable.
 C is a set of constraints that specify allowable combinations of values.
 Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable Xi. Each
constraint Ci consists of a pair <scope, rel>, where ‘scope’ is a tuple of variables that participate
in the constraint and ‘rel’ is a relation that defines the values that those variables can take on.
 To solve a CSP, we need to define a state space and the notion of a solution. Each state in a CSP
is defined by an assignment of values to some or all of the variables, {X i = vi, Xj = vj, . . .}.
 An assignment that does not violate any constraints is called a consistent or legal assignment.
 A complete assignment is one in which every variable is assigned, and a solution to a CSP is a
consistent, complete assignment.
 A partial assignment is one that assigns values to only some of the variables.
12 Example:
 Suppose that, we are looking at a map of Australia showing each of its states and territories. We are
given the task of coloring each region either red, green, or blue in such a way that no neighboring
regions have the same color.

WA: Western Australia


NT: Northern Territory
SA: South Australia
Q: Queensland
NSW: New South Wales
V: Victoria
T: Tasmania

 To formulate this as a CSP, we define the variables to be the regions X = {WA,NT, Q,NSW , V,SA, T }.
The domain of each variable is the set Di = {red,green,blue}. The constraints require neighboring
regions to have distinct colors. Thus there are nine constraints: C = {SA WA,SA NT,SA Q,SA
NSW ,SA V, WA NT,NT Q, Q NSW ,NSW V }
13 Example…
 Variables, .
 Domains, .
 Constraints,
OR

 The family of CSP constraints can be better visualized by Constraint Graph.

• The nodes of the graph correspond to variables of the problem, and a link
connects any two variables that participate in a constraint.
• CSP solvers can be faster than state-space searchers because the CSP solver
can quickly eliminate large swatches of the search space.
• For example, once we have chosen {SA = blue}, a search procedure would
have to consider 35 = 243 assignments for the five neighboring variables
instead of only 25 = 32 assignments to look at, a reduction of 87%.
14 Types of CSP Variables
■ Discrete variables
■ finite domains:
■ n variables, domain size d  O (d n) complete assignments

■ e.g., map coloring and 8-queens problems are both of this kind.


infinite domains:
■ integers, strings, etc.
■ e.g., job scheduling, variables are start/end days for each job

■ need a constraint language, e.g., StartJob + 5 ≤ StartJob


1 3
■ Continuous variables
■ e.g., start/end times for Hubble Space Telescope observations
■ linear constraints solvable in polynomial time by linear programming
15 Types of Constraints
 Unary constraints involve a single variable.
 e.g., SA ≠ green
 Binary constraints involve pairs of variables.
 e.g., SA ≠ WA
 Higher-order constraints involve 3 or more variables.
 e.g., cryptarithmetic column constraints
 A constraint involving an arbitrary number of variables is called a global constraint. One of
the most common global constraints is Alldiff , which says that all of the variables involved
in the constraint must have different values.
 e.g., cryptarithmetic puzzles, 8 – queen.
16 Solving CSP: Backtracking
 Only need to consider assignments to a single variable at each node.
 Backtracking search is used for a depth-first search that chooses values for one variable at
a time and backtracks when a variable has no legal values left to assign.
 Backtracking search is the basic uninformed algorithm for CSPs
17 Map Coloring Problem

WA NT Q NSW V SA T
Initial Domain RGB RGB RGB RGB RGB RGB RGB
After WA = Red R GB RGB RGB RGB GB RGB
After Q = Green R B G R B RGB B RGB
After V = Blue R B G R B ??? RGB
18 Map Coloring Problem

WA NT Q NSW V SA T
Initial Domain RGB RGB RGB RGB RGB RGB RGB

After SA = Blue RG RG RG RG RG B RGB

After WA = Red R G RG RG RG B RGB

After NT = Green R G R G R B G
19 Map Coloring Problem: Backtrack
20 LOCAL SEARCH FOR CSPS
 Local search algorithms (Hill Climbing, Simulated Annealing etc.) turn out to be effective in solving many
CSPs.
 They use a complete-state formulation.
 The initial state assigns a value to every variable, and the search changes the value of one variable at a time.
 Typically, the initial guess violates several constraints. The point of local search is to eliminate the violated
constraints.
 In choosing a new value for a variable, the most obvious heuristic is to select the value that results in the
minimum number of conflicts with other variables
21 Example
22 Excercise

X = {V1, V2, V3, V4, V5, V6}


D = {R, G, B}
C = If there is an edge
between i and j, then Vi
must be different of Vj

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy