Professional Documents
Culture Documents
CSL7540
Deepak
(Based on the courses from UCB, UW and IIT Delhi)
Logistics
• Timings: Mon(4 PM)/Wed (2 PM)/Fri (2 PM)
• Requirements
• Probability and statistics
• Algorithms
• Coding skills
Evaluation policy (tentative)
• Assignments 2/3 – 20%
• Project – 20%
• Quizzes
• Reading assignments 20%
• Self study questions
• Final Exam – 40%
Course objectives
• A brief intro to the philosophy of AI
• A brief intro to the breadth of ideas in AI
• Be able to write from scratch, debug and run (some) AI algorithms.
Peter Morgan/Reuters
2005: Self driving cars
2006: Dawn of a new era
Deep Learning
What will we learn
• Search
• Planning
• Constraint Satisfaction
• Logics
• Knowledge representation
• Learning
• Reasoning
• RL
What is
Artificial
Intelligence?
Deep Blue
Was Deep
Blue
intelligent?
Deep Blue
• Brute-force computing power
• Massive parallel computation
• Human-designed search procedure
• Terminal position
• Win/lose/draw
• Certain search depth (e.g. 10 moves ahead)
• Searching up to 200 million positions/sec
Is it human like intelligence?
Deep Blue
• Eliza - https://www.masswerk.at/elizabot/
Thinking rationally
• Irrefutable reasoning processes
• Ensures that all actions performed by a computer are formally provable from
inputs and prior knowledge
• John is a man
• All men are mortal
• therefore, John is mortal
• Field of logic
• Limitations
• Logical inference does not cover everything
• Reflexes
• Combinatorial explosion (in time and space)
Acting humanly: The Turing Test approach
• An agent would not pass the Turing Test without the following
requirements:
• natural language processing
• knowledge representation
• automated reasoning
• machine learning
• computer vision (total Turing test)
• robotics (total Turing test)
• Problems
• What if people call a human a machine?
• Make human-like errors
• No possible mathematical analysis
Acting rationally
• Rational behaviour: doing the right thing
• Need not always be deliberative
• Reflexive
• A rational agent acts so as to achieve the best (expected) outcome
• Perfect rationality cannot be achieved due to computational limitations
• Goals are expressed in terms of the performance or utility of
outcomes
• Being rational means maximizing its expected performance
Artificial Intelligence = Maximizing expected performance
Artificial Intelligence
CSL7540
Deepak
(Based on the courses from MIT, UW and IIT Delhi)
Agents
• An agent is an entity that perceives its environment through sensors
and take actions through actuators.
• The agent behaviour is described by the agent function, or policy, that
maps percept histories to actions:
𝑓 ∶ 𝒫∗ → 𝒜
• Output
• Path: start state → a state satisfying goal test
• May require shortest path
Search
• Search is a class of techniques for systematically finding or
constructing solutions to problems.
• Many AI problems can be formulated as search problems!
• Examples
• Path planning
• Games
• Natural Language Processing
• Recommendation system
…
Example: 8-puzzle
• Breadth-first search a
• Depth-first search
b c
• Uniform cost search
• Iterative deepening search
d e f g h
Breadth First Search
• Maintain queue of nodes to visit
• Evaluation
• Complete? a
• Time Complexity?
• Space Complexity? b c
• Optimal?
d e f g h
Depth-first search
• Maintain stack of nodes to visit
• Evaluation
• Complete? a
• Time Complexity?
• Space Complexity? b c
• Optimal?
d e f g h
https://www.youtube.com/watch?v=dtoFAvtVE4U
Iterative deepening search
• Complete?
• Time complexity?
• Space complexity?
• Optimal?
Iterative deepening search
• Complete? - yes
• Time complexity?
d b1 + (d-1) b2 + … + bd = O(bd)
• Evaluation
• Complete? – yes a
1 5
• Time Complexity? – O(b^(C*/e))
• Space Complexity? – O(b^(C*/e)) b c
• Optimal? – yes 2 6
1 4
3
d e f g h
https://www.youtube.com/watch?v=z6lUnb9ktkE
Graph (instead of tree) Search: Handling
repeated nodes
• Repeated expansions is a bigger issue for DFS than for BFS or IDDFS
• Trying to remember all previously expanded nodes and comparing the new
nodes with them is infeasible
• Space becomes exponential
• duplicate checking can also be expensive
• Time complexity?
• O(bm), but can be improved with good h(n)
• Space complexity?
• O(bm)
• Optimal
• No
A* search
• Shakey the Robot
• A* was first proposed in 1968 to
improve robot planning
f(G) = g(G)
f(G2) > f(G) since h(G) = 0 substitution
Proof of Optimality of (Tree) A*
• Suppose some sub-optimal goal state G2 has been generated and is
on the frontier
• Let n be an unexpanded state on the agenda such that n is on a
shortest (optimal) path to the optimal goal state G
• Assume h() is admissible
Proof of Optimality of (Tree) A*
• Suppose some sub-optimal goal state G2 has been generated and is
on the frontier
• Let n be an unexpanded state on the agenda such that n is on a
shortest (optimal) path to the optimal goal state G
• Assume h() is admissible
• Time complexity?
• Exponential
• Space complexity?
• Keeps all nodes in memory
• Optimal
• Yes
http://www.youtube.com/watch?v=huJEgJ82360
• Is ‘h’ admissible?
• Is ‘h’ consistent?
• What is the sequence of nodes explored by A* search?
• What is the path returned by A*?
Memory Problem?
• Iterative deepening A*
• Similar to ID search
Admissible heuristics
Admissible heuristics
• h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance
• h1 = 8
• h2 = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18
Admissible heuristics
Admissible heuristics
Admissible heuristics
Admissible heuristics
Admissible heuristics
Admissible heuristics
Admissible heuristics
Pattern databases
• The idea is is to store (precompute) the exact solution costs for every
possible sub-problem instance
• every possible configuration of the four tiles and the blank
• Usage
• Use position of chosen tiles as index into DB
• Use lookup value as heuristic, hDB
• Admissible?
Artificial Intelligence
CSL7540
Deepak
(Based on the courses from UCB, UW and IIT Delhi)
Path vs. State
• Till now: Systematic exploration of search space to reach goal
• Optimization of path to the goal
• Local search?
• Hill-climbing, Gradient methods, Simulated annealing, Genetic algorithms
Local search and optimization
• Idea
• Keep track of single current state
• Move only to neighboring states
• Ignore paths
• Advantages
• Low memory requirements
• Can often find reasonable solutions in large or infinite (continuous) state
spaces
Local search and optimization
Local search and optimization
• Pure optimization problems
• All states have an objective function
• Aim is to find the best state according to an objective function
• State with max (or min) objective value
• Many optimization problems do not fit the “standard” search model
presented earlier
• Path-cost/Goal-state formulation
• Local search can do quite well on these problems
Hill-climbing (Greedy Local Search)
• Min version will reverse inequalities and look for lowest valued
successor
Hill-climbing (Greedy Local Search)
• A loop that continuously moves towards increasing value
• Value can be an objective/heuristic function value
• Terminates when a peak is reached (greedy local search)
• Hill climbing does not look ahead of the immediate neighbors
• Can randomly choose among the set of best successors
• If multiple have the best value
• However…
• Takes only 4 steps on average when it succeeds
• And 3 on average when it gets stuck
• (for a state space with 8^8 =~17 million states)
• Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 × 7/2 = 28)
• 24/(24+23+20+11) = 31%
• 23/(24+23+20+11) = 29% etc.
Genetic algorithms (crossover)
• Issues:
• Large number of “tunable” parameters
• Lack of good empirical studies comparing to simpler methods
• No convincing evidence that GAs are better than hill-climbing
Local search in continuous spaces
• Discretization
• use hill-climbing
• Gradient descent
• Make a move in the direction of the gradient
Local search in continuous spaces
• Objective function: f(x1, x2….. xn)
• Compute gradient ∂f/ ∂xi
• Take a small step downhill in the direction of the gradient:
• Xi ← Xi – λ.∂f/ ∂xi
• Repeat until convergence
Artificial Intelligence
CSL7540
Deepak
(Based on the courses from MIT, UW and IIT Delhi)
Games
• Why do AI researchers study game playing?
• Adversarial search
• The Universe
• Number of atoms ≈ 1078
• Age ≈ 1018 seconds
• 108 moves/sec x 1078 x 1018 = 10104
Alpha – Beta search
• Chess: captures first, then threats, then forward moves, and then backward
moves)
• Hash table of previously seen positions
Cutting off search
• MinimaxCutoff is identical to MinimaxValue except
• Terminal? is replaced by Cutoff?
• Utility is replaced by Eval
• Evaluation functions?
• For chess/checkers, typically linear weighted sum of features
• Eval(s) = w1 f1(s) + w2 f2(s) + … + wn fn(s)
The Horizon effect
• Secondary Search
• Search further down selected path to ensure this is the best move
• Progressive Deepening
• Search one ply, then two ply, etc., until run out of time
• Similar to IDS
Quiescence Search
• Cutting off can be dangerous in presence of wild swings
• Singular Extensions: find obviously good moves and try them at cutoff
Deterministic Games in Practice
• Checkers: Chinook ended 40-year-reign of human world champion Marion Tinsley
in 1994. Used a precomputed endgame database defining perfect play for all
positions involving 8 or fewer pieces on the board, a total of 444 billion positions.
Checkers is now solved!
• Chess: Deep Blue defeated human world champion Garry Kasparov in a six-game
match in 1997. Deep Blue searches 200 million positions per second, uses very
sophisticated evaluation, and undisclosed methods for extending some lines of
search up to 40 ply. Current programs are even better, if less historic!
• Go: human champions refused to compete against computers, who are too bad.
In Go, b > 300, so most programs use pattern knowledge bases to suggest
plausible moves, along with aggressive pruning. In 2016, DeepMind’s AlphaGo
defeated Lee Sedol 4-1 to end the human reign.
Success in Go
• Combination of
• Deep Neural Networks
• Monte Carlo Tree Search
• Idea: For all deals consistent with what you can see
• Compute the minimax value of available actions for each of possible deals
• Compute the expected value over all deals
Summary
• Summary
• CSPs:
• State is factored
• Defined by variables Xi with values from domain Di
• Goal test is a set of constraints specifying allowable combinations of values
for subsets of variables
• A problem is solved when each variable has a value that satisfies all the
constraints on the variable
• CSP search algorithms take advantage of the structure of states and use
general-purpose rather than problem-specific heuristic
Example: Map-Colouring
• Variables: WA, NT, Q, NSW, V, SA, T
• DFS?
Backtracking search
• Backtracking search is the basic uninformed algorithm for CSPs
• Idea 1:
• Variable assignments are commutative, i.e.,
• [WA = red then NT = green] same as [NT = green then WA = red]
• Only need to consider assignments to a single variable at each node
• Idea 2:
• Check constraints as you go
• Incremental goal test
• Theorem: if the constraint graph has no loops, the CSP can be solved
in O(n.d2) time
• Disadvantages:
• Does not work with loops
Improving structure
• Conditioning: Instantiate a variable, prune its neighbors’ domains
• Cutset conditioning: Instantiate (in all ways) a set of variables such that the
remaining constraint graph is a tree
• Cutset size c: runtime O(dc · (n − c)d2), very fast for small c
Iterative algorithms for CSPs
• We have seen Backtracking (modified DFS) for CSPs
• How about local search?
• Hill-climbing, simulated annealing typically work with “complete” states, i.e.,
all variables assigned
• To apply to CSPs:
• Allow states with unsatisfied constraints operators reassign variable values
• Variable selection: Randomly select any conflicted variable
• Value selection by min-conflicts heuristic:
• Choose value that violates the fewest constraints
Performance of min-conflicts
• Given random initial state, can solve n-queens in almost constant
time for arbitrary n with high probability (e.g., n = 10,000,000)
• The same appears to be true for any randomly-generated CSP except
in a narrow range of the ratio
# "# $"%&'()*%&
•𝑅= # "# +)(*),-.&
Summary
• CSPs are a special kind of problem:
• States defined by values of a fixed set of variables
• Goal test defined by constraints on variable values
• Backtracking = depth-first search with one variable assigned per node
• Variable ordering and value selection heuristics help significantly
• Forward checking prevents assignments that guarantee later failure
• Constraint propagation (e.g., arc consistency) does additional work to constrain values
and detect inconsistencies
• The CSP representation allows analysis of problem structure
• Tree-structured CSPs can be solved in linear time
• Iterative min-conflicts is usually effective in practice
Min-conflicts algorithm
• Variables: Q1, Q2, Q3, and Q4 (4 queens)
• Domain: {A, B, C, D} (positions)
• Given configuration: Q1=C, Q2=C, Q3=D, Q4=B
• Assume that in every step, your algorithm always
chooses the leftmost conflicted queen to reduce
conflict and moves the queen along the column
• If there are ties, choose the topmost square
• What would be the configuration of queens after
I. One step?
II. Two steps?
III. Three steps?
IV. How many more steps are required to reach the solution?