Professional Documents
Culture Documents
04.02.2012
AI 1
Practical stuff
Course server:
http://
Mail:
Lars.mehnen@technikum-wien.at
Textbook:
S. Russell and P. Norvig Artificial Intelligence: A Modern Approach Prentice Hall, 2003, Second Edition
04.02.2012
AI 1
Course overview
04.02.2012
AI 1
Practical stuff
Excercices:
Agents
Wumpus
Problem solving Evolutionary algorithms Knowledge and reasoning Expert system Fuzzy logic Planning Agents
04.02.2012
AI 1
Origin after WWII Highly interdisciplinary Currently consist of huge variety of subfields
04.02.2012
AI 1
04.02.2012
AI 1
Test still relevant now, yet might be the wrong question. Requires the collaboration of major components of AI: knowledge, reasoning, language understanding, learning,
04.02.2012
AI 1
Problem with Turing test: not reproducible, constructive or amenable to mathematical analysis.
04.02.2012 AI 1 8
Cognitive Science vs. Cognitive neuroscience. Both approaches are now distinct from AI Share that the available theories do not explain anything resembling human intelligence. Three fields share a principal direction.
04.02.2012
AI 1
Problems:
Not all intelligence is mediated by logic behavior What is the purpose of thinking? What thought should one have?
04.02.2012 AI 1 10
04.02.2012
AI 1
11
Yet rationality is only applicable in ideal environments. Moreover rationality is not a very good model of reality.
04.02.2012
AI 1
12
Rational agents
An agent is an entity that perceives and acts This course is about designing rational agents
An agent is a function from percept histories to actions: For any given class of environments and task we seek the agent (or class of agents) with the best performance. Problem: computational limitations make perfect rationality unachievable.
04.02.2012
AI 1
13
Foundations of AI
Different fields have contributed to AI in the form of ideas,viewpoints and techniques.
Philosophy: Logic, reasoning, mind as a physical system, foundations of learning, language and rationality. Mathematics: Formal representation and proof algorithms, computation, (un)decidability, (in)tractability, probability. Psychology: adaptation, phenomena of perception and motor control. Economics: formal theory of rational decisions, game theory. Linguistics: knowledge represetatio, grammar. Neuroscience: physical substrate for mental activities. Control theory: homeostatic systems, stability, optimal agent design.
04.02.2012
AI 1
14
A brief history
What happened after WWII?
1943: Warren Mc Culloch and Walter Pitts: a model of artificial boolean neurons to perform computations.
First steps toward connectionist computation and learning (Hebbian learning). Marvin Minsky and Dann Edmonds (1951) constructed the first neural network computer
Arthur Samuel (1952-)investigated game playing (checkers ) with great success. John McCarthy(1958-) :
Inventor of Lisp (second-oldest high-level language) Logic oriented, Advice Taker (separation between knowledge and reasoning)
04.02.2012
AI 1
16
04.02.2012
AI 1
17
Expert systems
MYCIN to diagnose blood infections (Feigenbaum et al.)
Introduction of uncertainty in reasoning.
04.02.2012
AI 1
18
04.02.2012
AI 1
19
04.02.2012
AI 1
20
04/02/2012
AI 1
Outline
Agents and environments.
The vacuum-cleaner world
04/02/2012
AI 1
An agent can perceive its own actions, but not always it effects.
04/02/2012
AI 1
The agent function will internally be represented by the agent program. The agent program runs on the physical architecture to produce f.
04/02/2012
AI 1
Environment: square A and B Percepts: [location and content] e.g. [A, Dirty] Actions: left, right, suck, and no-op
04/02/2012
AI 1
Percept sequence [A,Clean] [A, Dirty] [B, Clean] [B, Dirty] [A, Clean],[A, Clean] [A, Clean],[A, Dirty]
04/02/2012
AI 1
function REFLEX-VACUUM-AGENT ([location, status]) return an action if status == Dirty then return Suck else if location == A then return Right else if location == B then return Left
04/02/2012
AI 1
Performance measure according to what is wanted in the environment instead of how the agents should behave.
04/02/2012
AI 1
Rationality
What is rational at a given time depends on four things:
Performance measure, Prior environment knowledge, Actions, Percept sequence to date (sensors).
DEF: A rational agent chooses whichever action maximizes the expected value of the performance measure given the percept sequence to date and prior environment knowledge.
04/02/2012
AI 1
Rationality
Rationality omniscience
An omniscient agent knows the actual outcome of its actions.
Rationality perfection
Rationality maximizes expected performance, while perfection maximizes actual performance.
04/02/2012
AI 1
10
Rationality
The proposed definition requires:
Information gathering/exploration
To maximize future rewards
Agent autonomy
Compensate for incorrect prior knowledge
04/02/2012
AI 1
11
Environments
To design a rational agent we must specify its task environment. PEAS description of the environment:
Performance Environment Actuators Sensors
04/02/2012
AI 1
12
Environments
E.g. Fully automated taxi:
PEAS description of the environment:
Performance Safety, destination, profits, legality, comfort Environment Streets/freeways, other traffic, pedestrians, weather,, Actuators Steering, accelerating, brake, horn, speaker/display, Sensors Video, sonar, speedometer, engine sensors, keyboard, GPS,
04/02/2012
AI 1
13
Environment types
Backgammon
Internet shopping
Taxi
04/02/2012
AI 1
14
Environment types
Fully vs. partially observable: an environment is full observable when the sensors can detect all aspects that are relevant to the choice of action.
Backgammon
Internet shopping
Taxi
04/02/2012
AI 1
15
Environment types
Fully vs. partially observable: an environment is full observable when the sensors can detect all aspects that are relevant to the choice of action.
Backgammon FULL
Taxi PARTIAL
04/02/2012
AI 1
16
Environment types
Deterministic vs. stochastic: if the next environment state is completely determined by the current state the executed action then the environment is deterministic.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL Backgammon FULL Internet shopping PARTIAL Taxi PARTIAL
04/02/2012
AI 1
17
Environment types
Deterministic vs. stochastic: if the next environment state is completely determined by the current state the executed action then the environment is deterministic.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES Backgammon FULL NO Internet shopping PARTIAL YES Taxi PARTIAL NO
04/02/2012
AI 1
18
Environment types
Episodic vs. sequential: In an episodic environment the agents experience can be divided into atomic steps where the agents perceives and then performs A single action. The choice of action depends only on the episode itself
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES Backgammon FULL NO Internet shopping PARTIAL YES Taxi PARTIAL NO
04/02/2012
AI 1
19
Environment types
Episodic vs. sequential: In an episodic environment the agents experience can be divided into atomic steps where the agents perceives and then performs A single action. The choice of action depends only on the episode itself
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO Backgammon FULL NO NO Internet shopping PARTIAL YES NO Taxi PARTIAL NO NO
04/02/2012
AI 1
20
Environment types
Static vs. dynamic: If the environment can change while the agent is choosing an action, the environment is dynamic. Semi-dynamic if the agents performance changes even when the environment remains the same.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO Backgammon FULL NO NO Internet shopping PARTIAL YES NO Taxi PARTIAL NO NO
04/02/2012
AI 1
21
Environment types
Static vs. dynamic: If the environment can change while the agent is choosing an action, the environment is dynamic. Semi-dynamic if the agents performance changes even when the environment remains the same.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO YES Backgammon FULL NO NO YES Internet shopping PARTIAL YES NO SEMI Taxi PARTIAL NO NO NO
04/02/2012
AI 1
22
Environment types
Discrete vs. continuous: This distinction can be applied to the state of the environment, the way time is handled and to the percepts/actions of the agent.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO YES
Taxi PARTIAL NO NO NO
04/02/2012
AI 1
23
Environment types
Discrete vs. continuous: This distinction can be applied to the state of the environment, the way time is handled and to the percepts/actions of the agent.
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO YES YES
Taxi PARTIAL NO NO NO NO
04/02/2012
AI 1
24
Environment types
Single vs. multi-agent: Does the environment contain other agents who are also maximizing some performance measure that depends on the current agents actions?
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO YES YES Backgammon FULL NO NO YES YES Internet shopping PARTIAL YES NO SEMI YES Taxi PARTIAL NO NO NO NO
04/02/2012
AI 1
25
Environment types
Single vs. multi-agent: Does the environment contain other agents who are also maximizing some performance measure that depends on the current agents actions?
Solitaire Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? FULL YES NO YES YES YES Backgammon FULL NO NO YES YES NO Internet shopping PARTIAL YES NO SEMI YES NO Taxi PARTIAL NO NO NO NO NO
04/02/2012
AI 1
26
Environment types
04/02/2012
AI 1
27
Agent types
How does the inside of the agent work?
Agent = architecture + program
04/02/2012
AI 1
28
Agent types
Function TABLE-DRIVEN_AGENT(percept) returns an action static: percepts, a sequence initially empty table, a table of actions, indexed by percept sequence append percept to the end of percepts action LOOKUP(percepts, table) return action
04/02/2012
AI 1
29
Agent types
Four basic kind of agent programs will be discussed:
Simple reflex agents Model-based reflex agents Goal-based agents Utility-based agents
04/02/2012
AI 1
30
Large reduction in possible percept/action situations(next page). Implemented through conditionaction rules
If dirty then suck
04/02/2012
AI 1
31
function REFLEX-VACUUM-AGENT ([location, status]) return an action if status == Dirty then return Suck else if location == A then return Right else if location == B then return Left
04/02/2012
AI 1
32
function SIMPLE-REFLEX-AGENT(percept) returns an action static: rules, a set of condition-action rules state INTERPRET-INPUT(percept) rule RULE-MATCH(state, rule) action RULE-ACTION[rule] return action
Will only work if the environment is fully observable otherwise infinite loops may occur.
04/02/2012
AI 1
33
04/02/2012
AI 1
34
function REFLEX-AGENT-WITH-STATE(percept) returns an action static: rules, a set of condition-action rules state, a description of the current world state action, the most recent action. state UPDATE-STATE(state, action, percept) rule RULE-MATCH(state, rule) action RULE-ACTION[rule] return action
04/02/2012
AI 1
35
Typically investigated in search and planning research. Major difference: future is taken into account Is more flexible since knowledge is represented explicitly and can be manipulated.
04/02/2012
AI 1
36
Utility function maps a (sequence of) state(s) onto a real number. Improves on goals:
Selecting between conflicting goals Select appropriately between several goals based on likelihood of success.
04/02/2012
AI 1
37
04/02/2012
AI 1
38
Problem generator: suggests actions that will lead to new and informative experiences.
Exploration vs. exploitation
04/02/2012
AI 1
39
Outline
Problem-solving agents
A kind of goal-based agent
Problem types
Single state (fully observable) Search with partial information
Problem formulation
Example problems
04/02/2012
AI 1
Example: Romania
04/02/2012
AI 1
Example: Romania
On holiday in Romania; currently in Arad
Flight leaves tomorrow from Bucharest
Formulate goal
Be in Bucharest
Formulate problem
States: various cities Actions: drive between cities
Find solution
Sequence of cities; e.g. Arad, Sibiu, Fagaras, Bucharest,
04/02/2012
AI 1
Problem-solving agent
Four general steps in problem solving:
Goal formulation
What are the successful world states
Problem formulation
What actions and states to consider given the goal
Search
Determine the possible sequence of actions that lead to the states of known values and then choosing the best sequence.
Execute
Give the solution perform the actions.
04/02/2012
AI 1
Problem-solving agent
function SIMPLE-PROBLEM-SOLVING-AGENT(percept) return an action static: seq, an action sequence state, some description of the current world state goal, a goal problem, a problem formulation state UPDATE-STATE(state, percept) if seq is empty then goal FORMULATE-GOAL(state) problem FORMULATE-PROBLEM(state,goal) seq SEARCH(problem) action FIRST(seq) seq REST(seq) return action
04/02/2012
AI 1
Problem types
04/02/2012
AI 1
04/02/2012
AI 1
04/02/2012
AI 1
Sensorless: start in {1,2,3,4,5,6,7,8} e.g Right goes to {2,4,6,8}. Solution?? Contingency: start in {1,3}. (assume Murphys law, Suck can dirty a clean carpet and local sensing: [location,dirt] only. Solution??
04/02/2012
AI 1
10
Problem formulation
A problem is defined by:
An initial state, e.g. Arad Successor function S(X)= set of action-state pairs
e.g. S(Arad)={<Arad Zerind, Zerind>,}
A solution is a sequence of actions from initial to goal state. Optimal solution has the lowest path cost.
04/02/2012
AI 1
11
(Abstract) state = set of real states. (Abstract) action = complex combination of real actions.
e.g. Arad Zerind represents a complex set of possible routes, detours, rest stops, etc. The abstraction is valid if the path between two states is reflected in the real world.
(Abstract) solution = set of real paths that are solutions in the real world. Each abstract action should be easier than the real problem.
04/02/2012
AI 1
12
04/02/2012
AI 1
13
States?? two locations with or without dirt: 2 x 22=8 states. Initial state?? Any state can be initial Actions?? {Left, Right, Suck} Goal test?? Check whether squares are clean. Path cost?? Number of actions to reach goal.
04/02/2012
AI 1
14
Example: 8-puzzle
04/02/2012
AI 1
15
Example: 8-puzzle
States?? Integer location of each tile Initial state?? Any state can be initial Actions?? {Left, Right, Up, Down} Goal test?? Check whether goal configuration is reached Path cost?? Number of actions to reach goal
04/02/2012
AI 1
16
04/02/2012
AI 1
17
Incremental formulation vs. complete-state formulation States?? Initial state?? Actions?? Goal test?? Path cost??
04/02/2012
AI 1
18
Incremental formulation States?? Any arrangement of 0 to 8 queens on the board Initial state?? No queens Actions?? Add queen in empty square Goal test?? 8 queens on board and none attacked Path cost?? None 3 x 1014 possible sequences to investigate
04/02/2012
AI 1
19
Incremental formulation (alternative) States?? n (0 n 8) queens on the board, one per column in the n leftmost columns with no queen attacking another. Actions?? Add queen in leftmost empty column such that is not attacking other queens 2057 possible sequences to investigate; Yet makes no difference when n=100
04/02/2012
AI 1
20
04/02/2012
AI 1
21
States?? Real-valued coordinates of robot joint angles; parts of the object to be assembled. Initial state?? Any arm position and object configuration. Actions?? Continuous motion of robot joints Goal test?? Complete assembly (without robot) Path cost?? Time to execute
04/02/2012
AI 1
22
04/02/2012
AI 1
23
function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion then return failure choose leaf node for expansion according to strategy if node contains goal state then return solution else expand the node and add resulting nodes to the search tree enddo
04/02/2012
AI 1
24
function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion then return failure choose leaf node for expansion according to strategy if node contains goal state then return solution else expand the node and add resulting nodes to the search tree enddo
04/02/2012
AI 1
25
function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion then return failure choose leaf node for expansion according to strategy if node contains goal state then return solution else expand the node and add resulting nodes to the search tree enddo
04/02/2012
AI 1
26
A state is a (representation of) a physical configuration A node is a data structure belong to a search tree
A node has a parent, children, and ncludes path cost, depth, Here node= <state, parent-node, action, path-cost, depth> FRINGE= contains generated nodes which are not yet expanded.
White nodes with black outline
04/02/2012
AI 1
27
function TREE-SEARCH(problem,fringe) return a solution or failure fringe INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe) loop do if EMPTY?(fringe) then return failure node REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe INSERT-ALL(EXPAND(node, problem), fringe)
04/02/2012
AI 1
28
04/02/2012
AI 1
29
Search strategies
A strategy is defined by picking the order of node expansion. Problem-solving performance is measured in four ways:
Completeness; Does it always find a solution if one exists? Optimality; Does it always find the least-cost solution? Time Complexity; Number of nodes generated/expanded? Space Complexity; Number of nodes stored in memory during search?
Time and space complexity are measured in terms of problem difficulty defined by:
b - maximum branching factor of the search tree d - depth of the least-cost solution m - maximum depth of the state space (may be )
04/02/2012
AI 1
30
04/02/2012
AI 1
31
BF-search, an example
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue
04/02/2012
AI 1
32
BF-search, an example
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue
A B C
04/02/2012
AI 1
33
BF-search, an example
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue
A B D E C
04/02/2012
AI 1
34
BF-search, an example
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue
A B D E F C G
04/02/2012
AI 1
35
BF-search; evaluation
Completeness:
Does it always find a solution if one exists?
YES
If shallowest goal node is at some finite depth d Condition: If b is finite
(maximum num. Of succ. nodes is finite)
04/02/2012
AI 1
36
BF-search; evaluation
Completeness:
YES (if b is finite)
Time complexity:
Assume a state space where every state has b successors.
root has b successors, each node at the next level has again b successors (total b2), Assume solution is at depth d Worst case; expand all but the last node at depth d Total numb. of nodes generated:
b + b 2 + b 3 + ...+ b d + (b d +1 b) = O(b d +1 )
04/02/2012
AI 1
37
BF-search; evaluation
Completeness:
YES (if b is finite)
Time complexity:
Total numb. of nodes generated:
b + b 2 + b 3 + ...+ b d + (b d +1 b) = O(b d +1 )
Space complexity:
Idem if each node is retained in memory
04/02/2012
AI 1
38
BF-search; evaluation
Completeness:
YES (if b is finite)
Time complexity:
Total numb. of nodes generated:
b + b 2 + b 3 + ...+ b d + (b d +1 b) = O(b d +1 )
Space complexity:
Idem if each node is retained in memory
Optimality:
Does it always find the least-cost solution? In general YES
unless actions have different cost.
04/02/2012
AI 1
39
BF-search; evaluation
Two lessons:
Memory requirements are a bigger problem than its execution time. Exponential complexity search problems cannot be solved by uninformed search methods for any but the smallest instances.
DEPTH2 2 4 6 8 10 12 14
TIME 0.11 seconds 11 seconds 19 minutes 31 hours 129 days 35 years 3523 years
MEMORY 1 megabyte 106 megabytes 10 gigabytes 1 terabyte 101 terabytes 10 petabytes 1 exabyte
04/02/2012
AI 1
40
Uniform-cost search
Extension of BF-search:
Expand node with lowest path cost
Implementation: fringe = queue ordered by path cost. UC-search is the same as BF-search when all step-costs are equal.
04/02/2012
AI 1
41
Uniform-cost search
Completeness:
YES, if step-cost > (smal positive constant)
Time complexity:
Assume C* the cost of the optimal solution. Assume that every action costs at least Worst-case: C */
O(b
Space complexity:
Idem to time complexity
Optimality:
nodes expanded in order of increasing path cost. YES, if complete.
04/02/2012
AI 1
42
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
04/02/2012
AI 1
43
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B C
04/02/2012
AI 1
44
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D E C
04/02/2012
AI 1
45
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I E C
04/02/2012
AI 1
46
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I E C
04/02/2012
AI 1
47
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I E C
04/02/2012
AI 1
48
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I J E K C
04/02/2012
AI 1
49
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I J E K C
04/02/2012
AI 1
50
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H I J E K C
04/02/2012
AI 1
51
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H
04/02/2012
C E F K
52
I J
AI 1
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H
04/02/2012
C E F K L
AI 1
G M
53
DF-search, an example
Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack)
A B D H
04/02/2012
C E F K L M
54
I J
AI 1
DF-search; evaluation
Completeness;
Does it always find a solution if one exists?
NO
unless search space is finite and no loops are possible.
04/02/2012
AI 1
55
DF-search; evaluation
Completeness;
NO unless search space is finite.
Time complexity;
O(b m )
Terrible if m is much larger than d (depth of optimal solution) But if many solutions, then faster than BF-search
04/02/2012
AI 1
56
DF-search; evaluation
Completeness;
NO unless search space is finite.
O(b m ) O(bm + 1)
04/02/2012
AI 1
57
DF-search; evaluation
Completeness;
NO unless search space is finite.
O(b m ) O(bm + 1)
04/02/2012
AI 1
58
Depth-limited search
Is DF-search with depth limit l.
i.e. nodes at depth l have no successors. Problem knowledge can be used
Solves the infinite-path problem. If l < d then incompleteness results. If l > d then not optimal. Time complexity: O(b l ) Space complexity: O(bl)
04/02/2012
AI 1
59
Depth-limited algorithm
function DEPTH-LIMITED-SEARCH(problem,limit) return a solution or failure/cutoff return RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[problem]),problem,limit) function RECURSIVE-DLS(node, problem, limit) return a solution or failure/cutoff cutoff_occurred? false if GOAL-TEST[problem](STATE[node]) then return SOLUTION(node) else if DEPTH[node] == limit then return cutoff else for each successor in EXPAND(node, problem) do result RECURSIVE-DLS(successor, problem, limit) if result == cutoff then cutoff_occurred? true else if result failure then return result if cutoff_occurred? then return cutoff else return failure
04/02/2012
AI 1
60
What?
A general strategy to find best depth limit l.
Goals is found at depth d, the depth of the shallowest goal-node.
04/02/2012
AI 1
61
04/02/2012
AI 1
62
ID-search, example
Limit=0
04/02/2012
AI 1
63
ID-search, example
Limit=1
04/02/2012
AI 1
64
ID-search, example
Limit=2
04/02/2012
AI 1
65
ID-search, example
Limit=3
04/02/2012
AI 1
66
ID search, evaluation
Completeness:
YES (no infinite paths)
04/02/2012
AI 1
67
ID search, evaluation
Completeness:
YES (no infinite paths)
Time complexity:
Algorithm seems costly due to repeated generation of certain states. Node generation: 2 d
level d: once level d-1: 2 level d-2: 3 level 2: d-1 level 1: d
O(b d )
N(BFS) = b + b 2 + ...+ b d + (b d +1 b)
Num. Comparison for b=10 and d=5 solution at far right
N(IDS) = 50 + 400 + 3000 + 20000 + 100000 = 123450 N(BFS) = 10 + 100 + 1000 + 10000 + 100000 + 999990 = 1111100
04/02/2012
AI 1
68
ID search, evaluation
Completeness:
YES (no infinite paths) Time complexity:
Space complexity:
Cfr. depth-first search
O(b d ) O(bd)
04/02/2012
AI 1
69
ID search, evaluation
Completeness:
YES (no infinite paths) Time complexity:
O(b d ) O(bd)
04/02/2012
AI 1
70
Bidirectional search
+b
Check whether the node belongs to the other fringe before expansion. Space complexity is the most significant weakness. Complete and optimal if both searches are BF.
04/02/2012
AI 1
71
04/02/2012
AI 1
72
Summary of algorithms
Criterion
Breadth-First
Uniform-cost
Depth-First
Depth-limited
Iterative deepening
Bidirectional search
Complete?
YES*
YES*
NO
YES, if l d bl
YES
YES*
Time
bd+1
bC*/e
bm
bd
bd/2
Space
bd+1
bC*/e
bm
bl
bd
bd/2
Optimal?
YES*
YES*
NO
NO
YES
YES
04/02/2012
AI 1
73
Repeated states
Failure to detect repeated states can turn a solvable problems into unsolvable ones.
04/02/2012
AI 1
74
04/02/2012
AI 1
75
DF- and ID-search with closed list no longer has linear space requirements since all nodes are stored in closed list!!
04/02/2012
AI 1
76
04/02/2012
AI 1
77
contingency problem
Percepts provide new information about current state; solution is a tree or policy; often interleave search and execution. If uncertainty is caused by actions of another agent: adversarial problem
exploration problem
When states and actions of the environment are unknown.
04/02/2012
AI 1
78
Conformant problems
start in {1,2,3,4,5,6,7,8} e.g Right goes to {2,4,6,8}. Solution??
[Right, Suck, Left,Suck]
When the world is not fully observable: reason about a set of states that migth be reached
=belief state
04/02/2012
AI 1
79
Conformant problems
Search space of belief states Solution = belief state with all members goal states. If S states then 2S belief states. Murphys law:
Suck can dirty a clear square.
04/02/2012
AI 1
80
04/02/2012
AI 1
81
Contingency problems
Contingency, start in {1,3}. Murphys law, Suck can dirty a clean carpet. Local sensing: dirt, location only.
Percept = [L,Dirty] ={1,3} [Suck] = {5,7} [Right] ={6,8} [Suck] in {6}={8} (Success) BUT [Suck] in {8} = failure
Solution??
Belief-state: no fixed action sequence guarantees solution
Relax requirement:
[Suck, Right, if [R,dirty] then Suck] Select actions based on contingencies arising during execution.
04/02/2012
AI 1
82
Outline
Informed = use problem-specific knowledge Which search strategies?
Best-first search and its variants
Heuristic functions?
How to invent them
4 februari 2012
AI 1
Previously: tree-search
function TREE-SEARCH(problem,fringe) return a solution or failure fringe INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe) loop do if EMPTY?(fringe) then return failure node REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe INSERT-ALL(EXPAND(node, problem), fringe)
4 februari 2012
AI 1
Best-first search
General approach of informed search:
Best-first search: node is selected for expansion based on an evaluation function f(n)
4 februari 2012
AI 1
A heuristic function
[dictionary]A rule of thumb, simplification, or educated guess that reduces or limits the search for solutions in domains that are difficult and poorly understood.
h(n) = estimated cost of the cheapest path from node n to goal node. If n is goal then h(n)=0 More information later.
4 februari 2012
AI 1
4 februari 2012
AI 1
Assume that we want to use greedy search to solve the problem of travelling from Arad to Bucharest. The initial state=Arad
4 februari 2012
AI 1
Sibiu(253)
The first expansion step produces:
Sibiu, Timisoara and Zerind
Timisoara (329)
Zerind(374)
4 februari 2012
AI 1
Arad (366)
Fagaras (176)
Oradea (380)
4 februari 2012
AI 1
Goal reached !!
Yet not optimal (see Arad, Sibiu, Rimnicu Vilcea, Pitesti)
4 februari 2012
AI 1
10
4 februari 2012
AI 1
11
O(b )
Cfr. Worst-case DF-search (with m is maximum depth of search space) Good heuristic can give dramatic improvement.
4 februari 2012
AI 1
12
4 februari 2012
AI 1
13
4 februari 2012
AI 1
14
A* search
Best-known form of best-first search. Idea: avoid expanding paths that are already expensive. Evaluation function f(n)=g(n) + h(n)
g(n) the cost (so far) to reach the node. h(n) estimated cost to get from the node to the goal. f(n) estimated total cost of path through n to goal.
4 februari 2012
AI 1
15
A* search
A* search uses an admissible heuristic
A heuristic is admissible if it never overestimates the cost to reach the goal Are optimistic
Formally: 1. h(n) <= h*(n) where h*(n) is the true cost from n 2. h(n) >= 0 so h(G)=0 for any goal G. e.g. hSLD(n) never overestimates the actual road distance
4 februari 2012
AI 1
16
Romania example
4 februari 2012
AI 1
17
A* search example
4 februari 2012
AI 1
18
A* search example
4 februari 2012
AI 1
19
A* search example
A* search example
4 februari 2012
AI 1
21
A* search example
4 februari 2012
AI 1
22
A* search example
4 februari 2012
AI 1
23
Suppose suboptimal goal G2 in the queue. Let n be an unexpanded node on a shortest to optimal goal G.
= g(G2 ) since h(G2 )=0 > g(G) since G2 is suboptimal >= f(n) since h is admissible Since f(G2) > f(n), A* will never select G2 for expansion f(G2 )
4 februari 2012
AI 1
24
Solution:
Add extra bookkeeping i.e. remove more expsive of two paths. Ensure that optimal path to any repeated state is always first followed.
Extra requirement on h(n): consistency (monotonicity)
4 februari 2012
AI 1
25
Consistency
A heuristic is consistent if If h is consistent, we have
f (n') = g(n') + h(n') = g(n) + c(n,a,n') + h(n') i.e. f(n) is nondecreasing along any path. g(n) + h(n) f (n)
4 februari 2012
AI 1
26
4 februari 2012
AI 1
27
A* search, evaluation
Completeness: YES
Since bands of increasing f are added Unless there are infinitly many nodes with f<f(G)
4 februari 2012
AI 1
28
A* search, evaluation
Completeness: YES Time complexity:
Number of nodes expanded is still exponential in the length of the solution.
4 februari 2012
AI 1
29
A* search, evaluation
Completeness: YES Time complexity: (exponential with path length) Space complexity:
It keeps all generated nodes in memory Hence space is the major problem not time
4 februari 2012
AI 1
30
A* search, evaluation
Completeness: YES Time complexity: (exponential with path length) Space complexity:(all nodes are stored) Optimality: YES
Cannot expand fi+1 until fi is finished. A* expands all nodes with f(n)< C* A* expands some nodes with f(n)=C* A* expands no nodes with f(n)>C*
4 februari 2012
AI 1
31
4 februari 2012
AI 1
32
4 februari 2012
AI 1
33
4 februari 2012
AI 1
34
Path until Rumnicu Vilcea is already expanded Above node; f-limit for every recursive call is shown on top. Below node: f(n) The path is followed until Pitesti which has a f-value worse than the f-limit.
4 februari 2012
AI 1
35
Unwind recursion and store best f-value for current best leaf Pitesti
result, f [best] RBFS(problem, best, min(f_limit, alternative))
4 februari 2012
AI 1
36
Unwind recursion and store best f-value for current best leaf Fagaras
result, f [best] RBFS(problem, best, min(f_limit, alternative))
best is now Rimnicu Viclea (again). Call RBFS for new best
Subtree is again expanded. Best alternative subtree is now through Timisoara.
4 februari 2012
AI 1
37
RBFS evaluation
RBFS is a bit more efficient than IDA*
Still excessive node generation (mind changes)
4 februari 2012
AI 1
38
(simplified) memory-bounded A*
Use all available memory.
I.e. expand best leafs until available memory is full When full, SMA* drops worst leaf node (highest f-value) Like RFBS backup forgotten node to its parent
4 februari 2012
AI 1
39
4 februari 2012
AI 1
40
Heuristic functions
4 februari 2012
AI 1
41
Heuristic functions
E.g for the 8-puzzle knows two commonly used heuristics h1 = the number of misplaced tiles
h1(s)=8
h2 = the sum of the distances of the tiles from their goal positions (manhattan distance).
h2(s)=3+1+2+2+2+3+3+2=18
4 februari 2012
AI 1
42
Heuristic quality
Effective branching factor b*
Is the branching factor that a uniform tree of depth d would have in order to contain N+1 nodes.
4 februari 2012
AI 1
43
If h2(n) >= h1(n) for all n (both admissible) then h2 dominates h1 and is better for search
4 februari 2012
AI 1
44
The optimal solution cost of a relaxed problem is no greater than the optimal solution cost of the real problem. ABSolver found a usefull heuristic for the rubic cube.
4 februari 2012
AI 1
45
4 februari 2012
AI 1
46
4 februari 2012
AI 1
47
4 februari 2012
AI 1
48
4 februari 2012
AI 1
49
4 februari 2012
AI 1
50
Hill-climbing search
is a loop that continuously moves in the direction of increasing value
It terminates when a peak is reached.
Hill climbing does not look ahead of the immediate neighbors of the current state. Hill-climbing chooses randomly among the set of best successors, if there is more than one. Hill-climbing a.k.a. greedy local search
4 februari 2012
AI 1
51
Hill-climbing search
function HILL-CLIMBING( problem) return a state that is a local maximum input: problem, a problem local variables: current, a node. neighbor, a node. current MAKE-NODE(INITIAL-STATE[problem]) loop do neighbor a highest valued successor of current if VALUE [neighbor] VALUE[current] then return STATE[current] current neighbor
4 februari 2012
AI 1
52
Hill-climbing example
8-queens problem (complete-state formulation). Successor function: move a single queen to another square in the same column. Heuristic function h(n): the number of pairs of queens that are attacking each other (directly or indirectly).
4 februari 2012
AI 1
53
Hill-climbing example
a) b)
a) shows a state of h=17 and the h-value for each possible successor. b) A local minimum in the 8-queens state space (h=1).
4 februari 2012
AI 1
54
Drawbacks
Ridge = sequence of local maxima difficult for greedy algorithms to navigate Plateaux = an area of the state space where the evaluation function is flat. Gets stuck 86% of the time.
4 februari 2012
AI 1
55
Hill-climbing variations
Stochastic hill-climbing
Random selection among the uphill moves. The selection probability can vary with the steepness of the uphill move.
First-choice hill-climbing
cfr. stochastic hill climbing by generating successors randomly until a better one is found.
Random-restart hill-climbing
Tries to avoid getting stuck in local maxima.
4 februari 2012
AI 1
56
Simulated annealing
Escape local maxima by allowing bad moves.
Idea: but gradually decrease their size and frequency.
If T decreases slowly enough, best state is reached. Applied for VLSI layout, airline scheduling, etc.
4 februari 2012
AI 1
57
Simulated annealing
function SIMULATED-ANNEALING( problem, schedule) return a solution state input: problem, a problem schedule, a mapping from time to temperature local variables: current, a node. next, a node. T, a temperature controlling the probability of downward steps current MAKE-NODE(INITIAL-STATE[problem]) for t 1 to do T schedule[t] if T = 0 then return current next a randomly selected successor of current E VALUE[next] - VALUE[current] if E > 0 then current next else current next only with probability eE /T
4 februari 2012
AI 1
58
4 februari 2012
AI 1
59
Genetic algorithms
Variant of local beam search with sexual recombination.
4 februari 2012
AI 1
60
Genetic algorithms
Variant of local beam search with sexual recombination.
4 februari 2012
AI 1
61
Genetic algorithm
function GENETIC_ALGORITHM( population, FITNESS-FN) return an individual input: population, a set of individuals FITNESS-FN, a function which determines the quality of the individual repeat new_population empty set loop for i from 1 to SIZE(population) do x RANDOM_SELECTION(population, FITNESS_FN) y RANDOM_SELECTION(population, FITNESS_FN) child REPRODUCE(x,y) if (small random probability) then child MUTATE(child ) add child to new_population population new_population until some individual is fit enough or enough time has elapsed return the best individual
4 februari 2012
AI 1
62
Exploration problems
Until now all algorithms were offline.
Offline= solution is determined before executing it. Online = interleaving computation and action
4 februari 2012
AI 1
63
An agent can recognize previous states. Actions are deterministic. Access to admissible heuristic h(s) e.g. manhattan distance
4 februari 2012
AI 1
64
4 februari 2012
AI 1
65
Assume an adversary who can construct the state space while the agent explores it
Visited states S and A. What next?
Fails in one of the state spaces
4 februari 2012
AI 1
66
4 februari 2012
AI 1
67
Online DF-search
function ONLINE_DFS-AGENT(s) return an action input: s, a percept identifying current state static: result, a table indexed by action and state, initially empty unexplored, a table that lists for each visited state, the action not yet tried unbacktracked, a table that lists for each visited state, the backtrack not yet tried s,a, the previous state and action, initially null if GOAL-TEST(s) then return stop if s is a new state then unexplored[s] ACTIONS(s) if s is not null then do result[a,s] s add s to the front of unbackedtracked[s] if unexplored[s] is empty then if unbacktracked[s] is empty then return stop else a an action b such that result[b, s]=POP(unbacktracked[s]) else a POP(unexplored[s]) s s return a
4 februari 2012
AI 1
68
4 februari 2012
AI 1
69
S=(1,1)
s is null?
True (initially)
UX[(1,1)] empty?
False
POP(UX[(1,1)])->a
A=UP
s = (1,1) Return a
4 februari 2012
AI 1
70
S=(2,1)
s is null?
UX[(2,1)] empty?
False
4 februari 2012
AI 1
71
S=(1,1)
s is null?
false (s=(2,1)) result[DOWN,(2,1)] <- (1,1) UB[(1,1)]={(2,1)}
UX[(1,1)] empty?
False
4 februari 2012
AI 1
72
S=(1,2)
s is null?
false (s=(1,1)) result[RIGHT,(1,1)] <- (1,2) UB[(1,2)]={(1,1)}
UX[(1,2)] empty?
False
4 februari 2012
AI 1
73
S=(1,1)
s is null?
false (s=(1,2)) result[LEFT,(1,2)] <- (1,1) UB[(1,1)]={(1,2),(2,1)}
UX[(1,1)] empty?
True UB[(1,1)] empty? False
A= b for b in result[b,(1,1)]=(1,2)
B=RIGHT
A=RIGHT, s=(1,1)
4 februari 2012
AI 1
74
Online DF-search
Worst case each node is visited twice. An agent can go on a long walk even when it is close to the solution. An online iterative deepening approach solves this problem. Online DF-search works only when actions are reversible.
4 februari 2012
AI 1
75
Solution: Random walk introduces exploration (can produce exponentially many steps)
4 februari 2012
AI 1
76
4 februari 2012
AI 1
77
Learning real-time A*
function LRTA*-COST(s,a,s,H) return an cost estimate if s is undefined the return h(s) else return c(s,a,s) + H[s] function LRTA*-AGENT(s) return an action input: s, a percept identifying current state static: result, a table indexed by action and state, initially empty H, a table of cost estimates indexed by state, initially empty s,a, the previous state and action, initially null if GOAL-TEST(s) then return stop if s is a new state (not in H) then H[s] h(s) unless s is null result[a,s] s H[s] MIN LRTA*-COST(s,b,result[b,s],H)
b ACTIONS(s)
4 februari 2012
AI 1
78
Outline
CSP? Backtracking for CSP Local search for CSPs Problem structure and decomposition
4 februari 2012
AI 1
A state is defined as an assignment of values to some or all variables. Consistent assignment: assignment does not violate the constraints.
4 februari 2012
AI 1
4 februari 2012
AI 1
Variables: WA, NT, Q, NSW, V, SA, T Domains: Di={red,green,blue} Constraints:adjacent regions must have different colors.
E.g. WA NT (if the language allows this) E.g. (WA,NT) {(red,green),(red,blue),(green,red),}
4 februari 2012
AI 1
4 februari 2012
AI 1
Constraint graph
CSP benefits
Standard representation pattern Generic goal and successor functions Generic heuristics (no domain specific expertise).
4 februari 2012
AI 1
Varieties of CSPs
Discrete variables
Finite domains; size d O(dn) complete assignments.
E.g. Boolean CSPs, include. Boolean satisfiability (NP-complete).
Continuous variables
e.g. start/end times for Hubble Telescope observations. Linear constraints solvable but time costy.
4 februari 2012
AI 1
Varieties of constraints
Unary constraints involve a single variable. e.g. SA green Binary constraints involve pairs of variables.
e.g. SA WA
Preference (soft constraints) e.g. red is better than green often representable by a cost for each variable assignment constrained optimization problems.
4 februari 2012
AI 1
4 februari 2012
AI 1
10
Path is irrelevant, so complete state representation can also be used. Branching factor b at the top level is nd. b=(n-l)d at depth l, hence n!dn leaves (only dn complete assignments).
4 februari 2012
AI 1
11
Commutativity
CSPs are commutative.
The order of any given set of actions has no effect on the outcome. Example: choose colors for Australian territories one at a time
[WA=red then NT=green] same as [NT=green then WA=red] All CSP search algorithms consider a single variable assignment at a time there are dn leaves.
4 februari 2012
AI 1
12
Backtracking search
Cfr. Depth-first search Chooses values for one variable at a time and backtracks when a variable has no legal values left to assign. Uninformed algorithm
No good general performance
4 februari 2012
AI 1
13
Backtracking search
function BACKTRACKING-SEARCH(csp) return a solution or failure return RECURSIVE-BACKTRACKING({} , csp) function RECURSIVE-BACKTRACKING(assignment, csp) return a solution or failure if assignment is complete then return assignment var SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp) for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do if value is consistent with assignment according to CONSTRAINTS[csp] then add {var=value} to assignment result RRECURSIVE-BACTRACKING(assignment, csp) if result failure then return result remove {var=value} from assignment return failure
4 februari 2012
AI 1
14
Backtracking example
4 februari 2012
AI 1
15
Backtracking example
4 februari 2012
AI 1
16
Backtracking example
4 februari 2012
AI 1
17
Backtracking example
4 februari 2012
AI 1
18
4 februari 2012
AI 1
19
var SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp)
A.k.a. most constrained variable heuristic Rule: choose variable with the fewest legal moves Which variable shall we try first?
4 februari 2012
AI 1
20
Degree heuristic
Use degree heuristic Rule: select variable that is involved in the largest number of constraints on other unassigned variables. Degree heuristic is very useful as a tie breaker. In what order should its values be tried?
4 februari 2012
AI 1
21
Least constraining value heuristic Rule: given a variable choose the least constraing value i.e. the one that leaves the maximum flexibility for subsequent variable assignments.
4 februari 2012
AI 1
22
Forward checking
Forward checking idea: keep track of remaining legal values for unassigned variables. Terminate search when any variable has no legal values.
4 februari 2012
AI 1
23
Forward checking
4 februari 2012
AI 1
24
Forward checking
4 februari 2012
AI 1
25
Forward checking
FC has detected that partial assignment is inconsistent with the constraints and backtracking can occur.
4 februari 2012
AI 1
26
1 1 2 3 4
X3 {1,2,3,4}
X4 {1,2,3,4}
[4-Queens slides copied from B.J. Dorr CMSC 421 course on AI]
4 februari 2012 AI 1 27
1 1 2 3 4
X3 {1,2,3,4}
X4 {1,2,3,4}
4 februari 2012
AI 1
28
1 1 2 3 4
X3 { ,2, ,4}
X4 { ,2,3, }
4 februari 2012
AI 1
29
1 1 2 3 4
X3 { ,2, ,4}
X4 { ,2,3, }
4 februari 2012
AI 1
30
1 1 2 3 4
X3 { , , , }
X4 { ,2,3, }
4 februari 2012
AI 1
31
1 1 2 3 4
X3 {1,2,3,4}
X4 {1,2,3,4}
4 februari 2012
AI 1
32
1 1 2 3 4
X3 {1, ,3, }
X4 {1, ,3,4}
4 februari 2012
AI 1
33
1 1 2 3 4
X3 {1, ,3, }
X4 {1, ,3,4}
4 februari 2012
AI 1
34
1 1 2 3 4
X3 {1, , , }
X4 {1, ,3, }
4 februari 2012
AI 1
35
1 1 2 3 4
X3 {1, , , }
X4 {1, ,3, }
4 februari 2012
AI 1
36
1 1 2 3 4
X3 {1, , , }
X4 { , ,3, }
4 februari 2012
AI 1
37
1 1 2 3 4
X3 {1, , , }
X4 { , ,3, }
4 februari 2012
AI 1
38
Constraint propagation
Solving CSPs with combination of heuristics plus forward checking is more efficient than either approach alone. FC checking propagates information from assigned to unassigned variables but does not provide detection for all failures.
NT and SA cannot be blue!
4 februari 2012
AI 1
39
Arc consistency
X Y is consistent iff for every value x of X there is some allowed y SA NSW is consistent iff SA=blue and NSW=red
4 februari 2012
AI 1
40
Arc consistency
X Y is consistent iff for every value x of X there is some allowed y NSW SA is consistent iff NSW=red and SA=blue NSW=blue and SA=??? Arc can be made consistent by removing blue from NSW
4 februari 2012
AI 1
41
Arc consistency
Arc can be made consistent by removing blue from NSW RECHECK neighbours !!
Remove red from V
4 februari 2012
AI 1
42
Arc consistency
Arc can be made consistent by removing blue from NSW RECHECK neighbours !!
Remove red from V
Arc consistency detects failure earlier than FC Can be run as a preprocessor or after each assignment.
Repeated until no inconsistency remains
4 februari 2012
AI 1
43
K-consistency
Arc consistency does not detect all inconsistencies:
Partial assignment {WA=red, NSW=red} is inconsistent.
Stronger forms of propagation can be defined using the notion of kconsistency. A CSP is k-consistent if for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable.
E.g. 1-consistency or node-consistency E.g. 2-consistency or arc-consistency E.g. 3-consistency or path-consistency
4 februari 2012
AI 1
45
K-consistency
A graph is strongly k-consistent if
It is k-consistent and Is also (k-1) consistent, (k-2) consistent, all the way down to 1consistent.
This is ideal since a solution can be found in time O(nd) instead of O(n2d3) YET we didnt win already: any algorithm for establishing n-consistency must take time exponential in n, in the worst case.
4 februari 2012
AI 1
46
Further improvements
Checking special constraints
Checking Alldif() constraint
E.g. {WA=red, NSW=red}
Intelligent backtracking
Standard form is chronological backtracking i.e. try different value for preceding variable. More intelligent, backtrack to conflict set.
Set of variables that caused the failure or set of previously assigned variables that are connected to X by constraints. Backjumping moves back to most recent element of the conflict set. Forward checking can be used to determine conflict set.
4 februari 2012
AI 1
47
Variable selection: randomly select any conflicted variable Value selection: min-conflicts heuristic
Select new value that results in a minimum number of conflicts with the other variables
4 februari 2012
AI 1
48
4 februari 2012
AI 1
49
Min-conflicts example 1
h=5
h=3
h=1
4 februari 2012
AI 1
50
Min-conflicts example 2
A two-step solution for an 8-queens problem using min-conflicts heuristic. At each stage a queen is chosen for reassignment in its column. The algorithm moves the queen to the min-conflict square breaking ties randomly.
4 februari 2012
AI 1
51
4 februari 2012
AI 1
52
Problem structure
How can the problem structure help to find a solution quickly? sub-problem identification is important:
Coloring Tasmania and mainland are independent sub-problems Identifiable as connected components of constrained graph.
Improves performance
4 februari 2012
AI 1
53
Problem structure
Suppose each problem has c variables out of a total of n. Worst case solution cost is O(n/c dc), i.e. linear in n
Instead of O(d n), exponential in n
Tree-structured CSPs
Theorem: if the constraint graph has no loops then CSP can be solved in O(nd 2) time Compare difference with general CSP, where worst case is O(d n)
4 februari 2012
AI 1
55
Tree-structured CSPs
In most cases sub-problems of a CSP are connected as a tree Any tree-structured CSP can be solved in time linear in the number of variables.
Choose a variable as root, order variables from root to leaves such that every nodes parent precedes it in the ordering. (label var from X1 to Xn) For j from n down to 2, apply REMOVE-INCONSISTENT-VALUES(Parent(Xj),Xj) For j from 1 to n assign Xj consistently with Parent(Xj )
4 februari 2012
AI 1
56
4 februari 2012
AI 1
57
Idea: assign values to some variables so that the remaining variables form a tree. Assume that we assign {SA=x} cycle cutset
And remove any values from the other variables that are inconsistent. The selected value for SA could be the wrong one so we have to try all of them
4 februari 2012 AI 1 58
This approach is worthwhile if cycle cutset is small. Finding the smallest cycle cutset is NP-hard
Approximation algorithms exist
4 februari 2012
AI 1
60
Domains?
1-9
Constraints?
There may not be 2 numbers in the same row and column and in a 3x3 group box.
4 februari 2012
AI 1
61
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 lead to failure. Constraint propagation 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.
4 februari 2012
AI 1
62
Outline
What are games? Optimal decisions in games
Which strategy leads to success?
4 februari 2012
AI 1
4 februari 2012
AI 1
Games adversary
Solution is strategy (strategy specifies move for every possible opponent reply). Time limits force an approximate solution Evaluation function: evaluate goodness of game position Examples: chess, checkers, Othello, backgammon
4 februari 2012
AI 1
Types of Games
4 februari 2012
AI 1
Game setup
Two players: MAX and MIN MAX moves first and they take turns until the game is over. Winner gets award, looser gets penalty. Games as search:
Initial state: e.g. board configuration of chess (TICTACTOE) Successor function: list of (move,state) pairs specifying legal moves. Terminal test: Is the game finished? Utility function: Gives numerical value of terminal states. E.g. win (+1), loose (-1) and draw (0) in tic-tac-toe (next)
4 februari 2012
AI 1
4 februari 2012
AI 1
Optimal strategies
Find the contingent strategy for MAX assuming an infallible MIN opponent. Assumption: Both players play optimally !! Given a game tree, the optimal strategy can be determined by using the minimax value of each node: MINIMAX-VALUE(n)= UTILITY(n) If n is a terminal maxs successors(n) MINIMAX-VALUE(s) If n is a max node mins successors(n) MINIMAX-VALUE(s) If n is a min node
4 februari 2012
AI 1
4 februari 2012
AI 1
4 februari 2012
AI 1
10
4 februari 2012
AI 1
11
Definition of optimal play for MAX assumes MIN plays optimally: maximizes worst-case outcome for MAX. But if MIN does not play optimally, MAX will do even better. [proven.]
4 februari 2012
AI 1
13
Minimax Algorithm
function MINIMAX-DECISION(state) returns an action inputs: state, current state in game vMAX-VALUE(state) return the action in SUCCESSORS(state) with value v function MAX-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v for a,s in SUCCESSORS(state) do v MAX(v,MIN-VALUE(s)) return v function MIN-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v for a,s in SUCCESSORS(state) do v MIN(v,MAX-VALUE(s)) return v
4 februari 2012 AI 1 14
Properties of Minimax
Criterion Minimax
Time
O(bm)
Space
O(bm)
4 februari 2012
AI 1
15
Multiplayer games
Games allow more than two players Single minimax values become vectors
4 februari 2012
AI 1
16
Revisit example
4 februari 2012
AI 1
17
Alpha-Beta Example
Do DF-search until first leaf
Range of possible values
[-,+]
[-, +]
4 februari 2012
AI 1
18
[-,+]
[-,3]
4 februari 2012
AI 1
19
[-,+]
[-,3]
4 februari 2012
AI 1
20
[3,+]
[3,3]
4 februari 2012
AI 1
21
[3,+]
This node is worse for MAX
[3,3]
[-,2]
4 februari 2012
AI 1
22
[3,14]
[3,3]
[-,2]
[-,14]
4 februari 2012
AI 1
23
[3,5]
[3,3]
[,2]
[-,5]
4 februari 2012
AI 1
24
[3,3]
[3,3]
[,2]
[2,2]
4 februari 2012
AI 1
25
[3,3]
[3,3]
[-,2]
[2,2]
4 februari 2012
AI 1
26
Alpha-Beta Algorithm
function ALPHA-BETA-SEARCH(state) returns an action inputs: state, current state in game vMAX-VALUE(state, - , +) return the action in SUCCESSORS(state) with value v function MAX-VALUE(state, , ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v- for a,s in SUCCESSORS(state) do v MAX(v,MIN-VALUE(s, , )) if v then return v MAX( ,v) return v
4 februari 2012 AI 1 27
Alpha-Beta Algorithm
function MIN-VALUE(state, , ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v+ for a,s in SUCCESSORS(state) do v MIN(v,MAX-VALUE(s, , )) if v then return v MIN( ,v) return v
4 februari 2012
AI 1
28
n will never be reached in actual play. Hence when enough is known about n, it can be pruned.
4 februari 2012
AI 1
29
4 februari 2012
AI 1
30
4 februari 2012
AI 1
31
4 februari 2012
AI 1
32
Heuristic EVAL
Idea: produce an estimate of the expected utility of the game from a given position. Performance depends on quality of EVAL. Requirements:
EVAL should order terminal-nodes in the same way as UTILITY. Computation may not take too long. For non-terminal states the EVAL should be strongly correlated with the actual chance of winning.
Only useful for quiescent (no wild swings in value in near future) states
4 februari 2012
AI 1
33
Heuristic difficulties
Heuristic counts pieces won
4 februari 2012
AI 1
36
Horizon effect
Fixed depth search thinks it can avoid the queening move
4 februari 2012
AI 1
37
4 februari 2012
AI 1
38
Possible moves (5-10,5-11), (5-11,19-24),(5-10,10-16) and (5-11,11-16) [1,1], [6,6] chance 1/36, all other chance 1/18
4 februari 2012
AI 1
39
4 februari 2012
AI 1
40
These equations can be backed-up recursively all the way to the root of the game tree.
4 februari 2012
AI 1
41
Left, A1 wins Right A2 wins Outcome of evaluation function may not change when values are scaled differently. Behavior is preserved only by a positive linear transformation of EVAL.
4 februari 2012
AI 1
42
Discussion
Examine section on state-of-the-art games yourself Minimax assumes right tree is better than left, yet
Return probability distribution over possible values Yet expensive calculation
4 februari 2012
AI 1
43
Discussion
Utility of node expansion
Only expand those nodes which lead to significanlty better moves
4 februari 2012
AI 1
44
Summary
Games are fun (and dangerous) They illustrate several important points about AI
Perfection is unattainable -> approximation Good idea what to think about Uncertainty constrains the assignment of values to states
4 februari 2012
AI 1
45
Thinking Rationally
Computational models of human thought processes Computational models of human behavior Computational systems that think rationally Computational systems that behave rationally
4 februari 2012
AI 1
Logical Agents
Reflex agents find their way from Arad to Bucharest by dumb luck Chess program calculates legal moves of its king, but doesnt know that no piece can be on 2 different squares at the same time Logic (Knowledge-Based) agents combine general knowledge with current percepts to infer hidden aspects of current state prior to selecting actions
Crucial in partially observable environments
4 februari 2012
AI 1
Outline
Knowledge-based agents Wumpus world Logic in general Propositional and first-order logic
Inference, validity, equivalence and satisfiability Reasoning patterns
Resolution Forward/backward chaining
4 februari 2012
AI 1
Knowledge Base
Knowledge Base : set of sentences represented in a knowledge representation language and represents assertions about the world.
tell
ask
Inference rule: when one ASKs questions of the KB, the answer should follow from what has been TELLed to the KB previously.
4 februari 2012
AI 1
4 februari 2012
AI 1
Abilities KB agent
Agent must be able to:
Represent states and actions, Incorporate new percepts Update internal representation of the world Deduce hidden properties of the world Deduce appropriate actions
4 februari 2012
AI 1
Description level
The KB agent is similar to agents with internal state Agents can be described at different levels
Knowledge level
What they know, regardless of the actual implementation. (Declarative description)
Implementation level
Data structures in KB and algorithms that manipulate them e.g propositional logic and resolution.
4 februari 2012
AI 1
Wumpus
4 februari 2012
AI 1
4 februari 2012
AI 1
10
4 februari 2012
AI 1
11
4 februari 2012
AI 1
12
4 februari 2012
AI 1
13
4 februari 2012
AI 1
14
4 februari 2012
AI 1
15
4 februari 2012
AI 1
16
4 februari 2012
AI 1
17
[1,1] The KB initially contains the rules of the environment. The first percept is [none, none,none,none,none], move to safe cell e.g. 2,1 [2,1] breeze which indicates that there is a pit in [2,2] or [3,1], return to [1,1] to try next safe cell
4 februari 2012
AI 1
18
[1,2] Stench in cell which means that wumpus is in [1,3] or [2,2] YET not in [1,1] YET not in [2,2] or stench would have been detected in [2,1] THUS wumpus is in [1,3] THUS [2,2] is safe because of lack of breeze in [1,2] THUS pit in [1,3]
move to next safe cell [2,2]
4 februari 2012
AI 1
19
[2,2] move to [2,3] [2,3] detect glitter , smell, breeze THUS pick up gold THUS pit in [3,3] or [2,4]
4 februari 2012
AI 1
20
What is a logic?
A formal language
Syntax what expressions are legal (well-formed) Semantics what legal expressions mean
in logic the truth of each sentence with respect to each possible world.
4 februari 2012
AI 1
21
Entailment
One thing follows from another KB |= KB entails sentence if and only if is true in worlds where KB is true. .g. x+y=4 entails 4=x+y Entailment is a relationship between sentences that is based on semantics.
4 februari 2012
AI 1
22
Models
Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated. m is a model of a sentence if is true in m M() is the set of all models of
4 februari 2012
AI 1
23
4 februari 2012
AI 1
24
4 februari 2012
AI 1
25
4 februari 2012
AI 1
26
4 februari 2012
AI 1
27
4 februari 2012
AI 1
28
4 februari 2012
AI 1
29
Logical inference
The notion of entailment can be used for logic inference.
Model checking (see wumpus example): enumerate all possible models and check whether is true.
4 februari 2012
AI 1
30
Schematic perspective
If KB is true in the real world, then any sentence derived From KB by a sound inference procedure is also true in the real world.
4 februari 2012
AI 1
31
February 4, 2012
Terminology
A sentence is valid if its truth value is t in all interpretations
Valid sentences: true, false, P P
Inference
KB i Soundness: Inference procedure i is sound if whenever KB i , it is also true that KB Completeness: Inference procedure i is complete if whenever KB , it is also true that KB i
February 4, 2012 4
Rules of Inference
Valid Rules of Inference:
Modus Ponens And-Elimination And-Introduction Or-Introduction Double Negation Unit Resolution Resolution
February 4, 2012
February 4, 2012
February 4, 2012
Horn Clauses
Real World KBs are often a conjunction of Horn clauses Horn clause =
proposition symbol; or (conjunction of symbols) symbol
February 4, 2012
Forward Chaining
Fire any rule whose premises are satisfied in the KB. Add its conclusion to the KB until query is found.
February 4, 2012
10
Backward Chaining
Motivation: Need goal-directed reasoning in order to keep from getting overwhelmed with irrelevant consequences Main idea:
Work backwards from query q To prove q:
Check if q is known already Prove by backward chaining all premises of some rule concluding q
February 4, 2012
11
February 4, 2012
12
Propositional Logic
4 februari 2012
AI 1
Propositional Logic
4 februari 2012
AI 1
Propositional Logic
4 februari 2012
AI 1
4 februari 2012
AI 1
4 februari 2012
AI 1
4 februari 2012
AI 1
Inference by enumeration
Depth-first enumeration of all models is sound and complete
4 februari 2012
AI 1
Logical equivalence
Two sentences are logically equivalent iff true in same set of models or iff |= and |= .
4 februari 2012
AI 1
A sentence is unsatisfiable if it is true in no models Satisfiability is connected to inference via the following: KB |= if and only if (KB ) is unsatisfiable
Remember proof by contradiction.
4 februari 2012
AI 1
10
Inference rules in PL
Modens Ponens
( ) ( )
4 februari 2012
AI 1
11
Example
Assume R1 through R5: How can we prove P1,2?
4 februari 2012
AI 1
13
Proof methods
Proof methods divide into (roughly) two kinds: Application of inference rules
Legitimate (sound) generation of new sentences from old Proof = a sequence of inference rule application can use inference rules as operators in a standard search algorithm Typically require transformation of sentences into a normal form
Model checking
truth table enumeration (always exponential in n) improved backtracking, e.g., Davis--Putnam-Logemann-Loveland (DPLL) heuristic search in model space (sound but incomplete) e.g., min-conflicts-like hill-climbing algorithms
4 februari 2012
AI 1
14
Resolution
Start with Unit Resolution Inference Rule: Full Resolution Rule is a generalization of this rule: For clauses of length two:
4 februari 2012
AI 1
15
Now after biconditional elimination of R3 followed by a modens ponens with R5: R15 : (P1,1 P2,2 P3,1) Resolution :
4 februari 2012
AI 1
16
Resolution
Uses CNF (Conjunctive normal form)
Conjunction of disjunctions of literals (clauses)
Resolution is complete in the sense that it can always be used to either confirm or refute a sentence (it can not be used to enumerate true sentences.)
4 februari 2012
AI 1
17
Conversion to CNF
B1,1 (P1,2 P2,1) Eliminate , replacing with ( )( ).
(B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) (B1,1 P1,2 P2,1) ((P1,2 P2,1) B1,1)
4 februari 2012
AI 1
18
Resolution algorithm
Proof by contradiction, i.e., show KB unsatisfiable
4 februari 2012
AI 1
19
Resolution algorithm
First KB is converted into CNF Then apply resolution rule to resulting clauses. The process continues until:
There are no new clauses that can be added
Hence does not ential
4 februari 2012
AI 1
20
Resolution example
KB = (B1,1 (P1,2 P2,1)) B1,1 = P1,2
4 februari 2012
AI 1
21
4 februari 2012
AI 1
22
Forward chaining
Idea: fire any rule whose premises are satisfied in the KB,
add its conclusion to the KB, until query is found
4 februari 2012
AI 1
23
4 februari 2012
AI 1
24
4 februari 2012
AI 1
25
4 februari 2012
AI 1
26
4 februari 2012
AI 1
27
4 februari 2012
AI 1
28
4 februari 2012
AI 1
29
4 februari 2012
AI 1
30
4 februari 2012
AI 1
31
4 februari 2012
AI 1
32
Proof of completeness
FC derives every atomic sentence that is entailed by KB
1. 2. 3. 4. 5. FC reaches a fixed point where no new atomic sentences are derived. Consider the final state as a model m, assigning true/false to symbols. Every clause in the original KB is true in m
a1 a k b
4 februari 2012
AI 1
33
Backward chaining
Idea: work backwards from the query q:
to prove q by BC,
check if q is known already, or prove by BC all premises of some rule concluding q
Avoid loops: check if new subgoal is already on the goal stack Avoid repeated work: check if new subgoal
1. 2.
4 februari 2012
AI 1
34
4 februari 2012
AI 1
35
4 februari 2012
AI 1
36
4 februari 2012
AI 1
37
4 februari 2012
AI 1
38
4 februari 2012
AI 1
39
4 februari 2012
AI 1
40
4 februari 2012
AI 1
41
4 februari 2012
AI 1
42
4 februari 2012
AI 1
43
4 februari 2012
AI 1
44
May do lots of work that is irrelevant to the goal BC is goal-driven, appropriate for problem-solving,
e.g., Where are my keys? How do I get into a PhD program?
4 februari 2012
AI 1
45
4 februari 2012
AI 1
46
4 februari 2012
AI 1
47
4 februari 2012
AI 1
48
4 februari 2012
AI 1
49
4 februari 2012
AI 1
50
Increase in complexity by keeping the number of symbols fixed and increasing the amount of clauses.
m = number of clauses n = number of symbols Hard problems seem to cluster near m/n = 4.3 (critical point)
4 februari 2012
AI 1
51
4 februari 2012
AI 1
52
4 februari 2012
AI 1
53
64 distinct proposition symbols, 155 sentences A fringe square is provably safe if the sentence is entailed by the knowledge base.
4 februari 2012 AI 1
(P
i, j
W i, j )
54
4 februari 2012
AI 1
55
Better would be to have just two sentences for breezes and stenches for all squares.
Impossible for propositional logic.
4 februari 2012
AI 1
56
Summary
Logical agents apply inference to a knowledge base to derive new information and make decisions. Basic concepts of logic:
syntax: formal structure of sentences semantics: truth of sentences wrt models entailment: necessary truth of one sentence given another inference: deriving sentences from other sentences soundness: derivations produce only entailed sentences completeness: derivations can produce all entailed sentences
Wumpus world requires the ability to represent partial and negated information, reason by cases, etc. Resolution is complete for propositional logic Forward, backward chaining are linear-time, complete for Horn clauses Propositional logic lacks expressive power
4 februari 2012 AI 1 57
Outline
Why FOL? Syntax and semantics of FOL Using FOL Wumpus world in FOL Knowledge engineering in FOL
4 februari 2012
AI 1
meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2 (unlike natural language, where meaning depends on context)
Meaning in propositional logic is context-independent Propositional logic has very limited expressive power
(unlike natural language) E.g., cannot say "pits cause breezes in adjacent squares
except by writing one sentence for each square
4 februari 2012
AI 1
First-order logic
Whereas propositional logic assumes the world contains facts, first-order logic (like natural language) assumes the world contains
Objects: people, houses, numbers, colors, baseball games, wars, Relations: red, round, prime, brother of, bigger than, part of, comes between, Functions: father of, best friend, one more than, plus,
4 februari 2012
AI 1
Logics in General
Ontological Commitment: What exists in the world TRUTH
PL : facts hold or do not hold. FL : objects with relatios between them that hold or do not hold
4 februari 2012
AI 1
4 februari 2012
AI 1
Atomic sentences
Atomic sentence = predicate (term1,...,termn) or term1 = term2 Term = function (term1,...,termn) or constant or variable
4 februari 2012
AI 1
Complex sentences
Complex sentences are made from atomic sentences using connectives
S, S1 S2, S1 S2, S1 S2, S1 S2,
4 februari 2012
AI 1
An atomic sentence predicate(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relation referred to by predicate.
4 februari 2012
AI 1
4 februari 2012
AI 1
10
4 februari 2012
AI 1
11
Quantifiers
Allows us to express properties of collections of objects instead of enumerating objects by name Universal: for all Existential: there exists
4 februari 2012
AI 1
12
Universal quantification
<variables> <sentence> Everyone at VUB is smart: x At(x,VUB) Smart(x) x P is true in a model m iff P is true with x being each possible object in the model Roughly speaking, equivalent to the conjunction of instantiations of P
At(KingJohn,VUB) Smart(KingJohn) At(Richard,VUB) Smart(Richard) At(VUB,VUB) Smart(VUB) ...
4 februari 2012 AI 1 13
4 februari 2012
AI 1
14
Existential quantification
<variables> <sentence> Someone at VUB is smart: x At(x, VUB) Smart(x) x P is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P
At(KingJohn,VUB) Smart(KingJohn) At(Richard,VUB) Smart(Richard) At(VUB, VUB) Smart(VUB) ...
AI 1
4 februari 2012
15
4 februari 2012
AI 1
16
Properties of quantifiers
x y is the same as y x x y is the same as y x x y is not the same as y x x y Loves(x,y) y x Loves(x,y)
There is a person who loves everyone in the world Everyone in the world is loved by at least one person
Quantifier duality: each can be expressed using the other x Likes(x,IceCream) x Likes(x,IceCream) x Likes(x,Broccoli) x Likes(x,Broccoli)
4 februari 2012 AI 1 17
Equality
term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object E.g., definition of Sibling in terms of Parent:
x,y Sibling(x,y) [(x = y) m,f (m = f) Parent(m,x) Parent(f,x) Parent(m,y) Parent(f,y)]
4 februari 2012
AI 1
18
I.e., does the KB entail some best action at t=5? Answer: Yes, {a/Shoot} substitution (binding list) Given a sentence S and a substitution , S denotes the result of plugging into S; e.g.,
S = Smarter(x,y) = {x/Hillary,y/Bill} S = Smarter(Hillary,Bill)
4 februari 2012
AI 1
19
Using FOL
The kinship domain:
Brothers are siblings
x,y Brother(x,y) Sibling(x,y)
Sibling is symmetric
x,y Sibling(x,y) Sibling(y,x)
4 februari 2012
AI 1
20
Using FOL
The set domain: s Set(s) (s = {} ) (x,s2 Set(s2) s = {x|s2}) x,s {x|s} = {} x,s x s s = {x|s} x,s x s [ y,s2} (s = {y|s2} (x = y x s2))] s1,s2 s1 s2 (x x s1 x s2) s1,s2 (s1 = s2) (s1 s2 s2 s1) x,s1,s2 x (s1 s2) (x s1 x s2) x,s1,s2 x (s1 s2) (x s1 x s2)
4 februari 2012
AI 1
21
Actions:
Turn(Right), Turn(Left), Forward, Shoot, Grab, Release, Climb
To determine best action, construct query: a BestAction(a,5) ASK solves this and returns {a/Grab}
And TELL about the action.
4 februari 2012
AI 1
22
Reflex
t Glitter(t) BestAction(Grab,t)
4 februari 2012
AI 1
23
4 februari 2012
AI 1
24
Decide on a vocabulary of predicates, functions, and constants Encode general knowledge about the domain Encode a description of the specific problem instance Pose queries to the inference procedure and get answers Debug the knowledge base
4 februari 2012
AI 1
25
4 februari 2012
AI 1
26
Decide on a vocabulary
4 februari 2012
AI 1
27
4 februari 2012
AI 1
28
4 februari 2012
AI 1
29
7.
4 februari 2012
AI 1
30
Summary
First-order logic:
objects and relations are semantic primitives syntax: constants, functions, predicates, equality, quantifiers.
4 februari 2012
AI 1
31
Outline
Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward chaining Backward chaining Resolution
4 februari 2012
AI 11
FOL to PL
First order inference can be done by converting the knowledge base to PL and using propositional inference.
How to convert universal quantifiers?
Replace variable by ground term.
4 februari 2012
AI 11
for any variable v and ground term g (Subst(x,y) = substitution of y by x) E.g., x King(x) Greedy(x) Evil(x) yields:
King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(Father(John)) Greedy(Father(John)) Evil(Father(John)) . . .
4 februari 2012
AI 11
E.g., x Crown(x) OnHead(x,John) yields: Crown(C1) OnHead(C1,John) provided C1 is a new constant symbol, called a Skolem constant
4 februari 2012
AI 11
EI versus UI
UI can be applied several times to add new sentences; the new KB is logically equivalent to the old. EI can be applied once to replace the existential sentence; the new KB is not equivalent to the old but is satisfiable if the old KB was satisfiable.
4 februari 2012
AI 11
4 februari 2012
AI 11
Reduction contd.
CLAIM: A ground sentence is entailed by a new KB iff entailed by the original KB. CLAIM: Every FOL KB can be propositionalized so as to preserve entailment IDEA: propositionalize KB and query, apply resolution, return result PROBLEM: with function symbols, there are infinitely many ground terms,
e.g., Father(Father(Father(John)))
4 februari 2012
AI 11
Reduction contd.
THEOREM: Herbrand (1930). If a sentence is entailed by an FOL KB, it is entailed by a finite subset of the propositionalized KB IDEA: For n = 0 to do
create a propositional KB by instantiating with depth-n terms see if is entailed by this KB
PROBLEM: works if is entailed, loops if is not entailed THEOREM: Turing (1936), Church (1936) Entailment for FOL is semi decidable
algorithms exist that say yes to every entailed sentence, but no algorithm exists that also says no to every non-entailed sentence.
4 februari 2012
AI 11
It seems obvious that Evil(John), but propositionalization produces lots of facts such as Greedy(Richard) that are irrelevant.
With p k-ary predicates and n constants, there are pnk instantiations!
4 februari 2012
AI 11
10
4 februari 2012
AI 11
11
Unification
We can get the inference immediately if we can find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
4 februari 2012
AI 11
12
Unification
We can get the inference immediately if we can find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)
4 februari 2012
AI 11
13
Unification
We can get the inference immediately if we can find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
{x/Jane} {x/OJ,y/John}
4 februari 2012
AI 11
14
Unification
We can get the inference immediately if we can find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
4 februari 2012
AI 11
15
Unification
We can get the inference immediately if we can find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
4 februari 2012
AI 11
16
Unification
To unify Knows(John,x) and Knows(y,z),
= {y/John, x/z } or = {y/John, x/John, z/John}
The first unifier is more general than the second. There is a single most general unifier (MGU) that is unique up to renaming of variables.
MGU = { y/John, x/z }
4 februari 2012
AI 11
17
4 februari 2012
AI 11
18
4 februari 2012
AI 11
19
GMP used with KB of definite clauses (exactly one positive literal). All variables assumed universally quantified.
4 februari 2012
AI 11
20
Soundness of GMP
Need to show that
p1', , pn', (p1 pn q) |= q
4 februari 2012
AI 11
21
4 februari 2012
AI 11
22
4 februari 2012
AI 11
23
4 februari 2012
AI 11
24
4 februari 2012
AI 11
25
4 februari 2012
AI 11
26
4 februari 2012
AI 11
27
4 februari 2012
AI 11
28
4 februari 2012
AI 11
29
4 februari 2012
AI 11
30
4 februari 2012
AI 11
31
4 februari 2012
AI 11
32
4 februari 2012
AI 11
33
4 februari 2012
AI 11
34
An enemy of America counts as "hostile: West, who is American The country Nono, an enemy of America
4 februari 2012
AI 11
35
An enemy of America counts as "hostile: West, who is American The country Nono, an enemy of America
Enemy(Nono,America)
4 februari 2012
AI 11
36
4 februari 2012
AI 11
37
4 februari 2012
AI 11
38
4 februari 2012
AI 11
39
4 februari 2012
AI 11
40
4 februari 2012
AI 11
41
Matching itself can be expensive: Database indexing allows O(1) retrieval of known facts
e.g., query Missile(x) retrieves Missile(M1)
Matching conjunctive premises against known facts is NP-hard. (Pattern matching) Forward chaining is widely used in deductive databases
4 februari 2012
AI 11
42
4 februari 2012
AI 11
43
4 februari 2012
AI 11
44
4 februari 2012
AI 11
45
4 februari 2012
AI 11
46
4 februari 2012
AI 11
47
4 februari 2012
AI 11
48
4 februari 2012
AI 11
49
4 februari 2012
AI 11
50
4 februari 2012
AI 11
51
4 februari 2012
AI 11
52
4 februari 2012
AI 11
53
Logic programming
Logic programming
Identify problem Assemble information <coffee break> Encode info in KB Encode problem instances as facts Ask queries Find false facts.
Procedural programming
Identify problem Assemble information Figure out solution Program solution Encode problem instance as data Apply program to data Debug procedural errors
Efficient unification and retrieval of matching clauses. Depth-first, left-to-right backward chaining Built-in predicates for arithmetic etc., e.g., X is Y*Z+3 Built-in predicates that have side effects (e.g., input and output predicates, assert/retract predicates) Closed-world assumption ("negation as failure")
e.g., given alive(X) :- not dead(X). alive(joe) succeeds if dead(joe) fails
4 februari 2012
AI 11
55
Prolog
Appending two lists to produce a third: append([],Y,Y). append([X|L],Y,[X|Z]) :- append(L,Y,Z). query: answers: append(A,B,[1,2]) ? A=[] B=[1,2] A=[1] B=[2] A=[1,2] B=[]
4 februari 2012
AI 11
56
with = {x/Ken}
4 februari 2012
AI 11
57
Conversion to CNF
Everyone who loves all animals is loved by someone: x [y Animal(y) Loves(x,y)] [y Loves(y,x)] Eliminate biconditionals and implications x [y Animal(y) Loves(x,y)] [y Loves(y,x)] Move inwards: x p x p, x p x p x [y (Animal(y) Loves(x,y))] [y Loves(y,x)] x [y Animal(y) Loves(x,y)] [y Loves(y,x)] x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
4 februari 2012
AI 11
58
4 februari 2012
AI 11
59
4 februari 2012
AI 11
60
Outline
Ontological engineering Categories and objects Actions, situations and events Mental events and mental objects The internet shopping world Reasoning systems for categories Reasoning with default information Truth maintenance systems
February 4, 2012 Mehnen 2
Ontological engineering
How to create more general and flexible representations.
Concepts like actions, time, physical object and beliefs Operates on a bigger scale than K.E.
February 4, 2012
Mehnen
February 4, 2012
Mehnen
Category organization
Relation = inheritance:
All instance of food are edible, fruit is a subclass of food and apples is a subclass of fruit then an apple is edible.
Defines a taxonomy
February 4, 2012
Mehnen
A set of categories s constitutes an exhaustive decomposition of a category c if all members of the set c are covered by categories in s:
E.D.(s,c) ( i i c c2 c2 s i c2) Example: ExhaustiveDecomposition({Americans, Canadian, Mexicans},NorthAmericans).
February 4, 2012 Mehnen 9
Is ({Americans,Canadian,
Mexicans},NorthAmericans) a partition?
Categories can be defined by providing necessary and sufficient conditions for membership
x Bachelor(x) Male(x) Adult(x) Unmarried(x)
February 4, 2012 Mehnen 10
Natural kinds
Many categories have no clear-cut definitions (chair, bush, book). Tomatoes: sometimes green, red, yellow, black. Mostly round. One solution: category Typical(Tomatoes). x, x Typical(Tomatoes) Red(x) Spherical(x).
We can write down useful facts about categories without providing exact definitions.
What about bachelor? Quine challenged the utility of the notion of strict definition. We might question a statement such as the Pope is a bachelor.
February 4, 2012 Mehnen 11
Physical composition
One object may be part of another:
PartOf(Bucharest,Romania) PartOf(Romania,EasternEurope) PartOf(EasternEurope,Europe)
The PartOf predicate is transitive (and irreflexive), so we can infer that PartOf(Bucharest,Europe) More generally:
x PartOf(x,x) x,y,z PartOf(x,y) PartOf(y,z) PartOf(x,z)
February 4, 2012
Mehnen
12
Measurements
Objects have height, mass, cost, .... Values that we assign to these are measures Combine Unit functions with a number: Length(L1) = Inches(1.5) = Centimeters(3.81). Conversion between units: i Centimeters(2.54 x i)=Inches(i). Some measures have no scale: Beauty, Difficulty, etc.
Most important aspect of measures: is that they are orderable. Don't care about the actual numbers. (An apple can have deliciousness .9 or .1.)
February 4, 2012 Mehnen 13
February 4, 2012
Mehnen
14
Fluent are functions and predicates that vary from one situation to the next.
E.g. Holding(G1, S0)
E.g. Gold(G1)
15
February 4, 2012
Mehnen
17
Describing change
Simples Situation calculus requires two axioms to describe change:
Possibility axiom: when is it possible to do the action
At(Agent,x,s) Adjacent(x,y) Poss(Go(x,y),s)
Note that next state is completely specified by current state. Each action effect is mentioned only once.
February 4, 2012 Mehnen 19
Other problems
How to deal with secondary (implicit) effects?
If the agent is carrying the gold and the agent moves then the gold moves too. Ramification problem
Extensions:
Event calculus (when actions have a duration) Process categories
February 4, 2012
Mehnen
20
February 4, 2012
Mehnen
22
23
Description logics
Formal language for constructing and combining category definitions Efficient algorithms to decide subset and superset relationships between categories.
February 4, 2012 Mehnen 24
Semantic Networks
Logic vs. semantic networks Many variations
All represent individual objects, categories of objects and relationships among objects.
February 4, 2012
Mehnen
25
February 4, 2012
Mehnen
26
Semantic networks
Drawbacks
Links can only assert binary relations Can be resolved by reification of the proposition as an event
February 4, 2012
Mehnen
27
Description logics
Are designed to describe defintions and properties about categories
A formalization of semantic networks
February 4, 2012
Mehnen
29
Planning
The Planning problem Planning with State-space search Partial-order planning Planning graphs Planning with propositional logic Analysis of planning approaches
4 februari 2012 AI 1 2
What is Planning
Generate sequences of actions to perform tasks and achieve objectives.
States, actions and goals
Search for solution over abstract space of plans. Classical planning environment: fully observable, deterministic, finite, static and discrete. Assists humans in practical applications
design and manufacturing military operations games space exploration
4 februari 2012
AI 1
Planning language
What is a good language?
Expressive enough to describe a wide variety of problems. Restrictive enough to allow efficient algorithms to operate on it. Planning algorithm should be able to take advantage of the logical structure of the problem.
Representation of goals
Partially specified state and represented as a conjunction of positive ground literals A goal is satisfied if the state contains all literals in goal.
4 februari 2012 AI 1 6
Language semantics?
How do actions affect states?
An action is applicable in any state that satisfies the precondition. For FO action schema applicability involves a substitution for the variables in the PRECOND.
At(P1,JFK) At(P2,SFO) Plane(P1) Plane(P2) Airport(JFK) Airport(SFO) Satisfies : At(p,from) Plane(p) Airport(from) Airport(to) With ={p/P1,from/JFK,to/SFO} Thus the action is applicable.
4 februari 2012
AI 1
Language semantics?
The result of executing action a in state s is the state s
s is same as s except
Any positive literal P in the effect of a is added to s Any negative literal P is removed from s
EFFECT: AT(p,from) At(p,to): At(P1,SFO) At(P2,SFO) Plane(P1) Plane(P2) Airport(JFK) Airport(SFO)
4 februari 2012
AI 1
10
4 februari 2012
AI 1
13
Regression planners
backward state-space search To achieve a goal, what must have been true in the previous state.
4 februari 2012 AI 1 14
4 februari 2012
AI 1
15
Progression algorithm
Formulation as state-space search problem:
Initial state = initial state of the planning problem
Literals not appearing are false
Goal test = does the state satisfy the goal Step cost = each action costs 1
Inefficient:
(1) irrelevant action problem (2) good heuristic required for efficient search
4 februari 2012 AI 1 16
Regression algorithm
How to determine predecessors?
What are the states from which applying a given action leads to the goal?
Goal state = At(C1, B) At(C2, B) At(C20, B) Relevant action for first conjunct: Unload(C1,p,B) Works only if pre-conditions are satisfied. Previous state= In(C1, p) At(p, B) At(C2, B) At(C20, B) Subgoal At(C1,B) should not be present in this state.
Actions must not undo desired literals (consistent) Main advantage: only relevant actions are considered.
Often much lower branching factor than forward search.
4 februari 2012
AI 1
17
Regression algorithm
General process for predecessor construction
Give a goal description G Let A be an action that is relevant and consistent The predecessors is as follows:
Any positive effects of A that appear in G are deleted. Each precondition literal of A is added , unless it already appears.
Any standard search algorithm can be added to perform the search. Termination when predecessor satisfied by initial state.
In FO case, satisfaction might require a substitution.
4 februari 2012 AI 1 18
Partial-order planning
Progression and regression planning are totally ordered plan search forms.
They cannot take advantage of problem decomposition. Decisions must be made on how to sequence actions on all the subproblems
4 februari 2012
AI 1
20
Shoe example
Goal(RightShoeOn LeftShoeOn) Init() Action(RightShoe, PRECOND: RightSockOn EFFECT: RightShoeOn) Action(RightSock,PRECOND: EFFECT: RightSockOn) Action(LeftShoe, PRECOND: LeftSockOn EFFECT: LeftShoeOn) Action(LeftSock, PRECOND: EFFECT: LeftSockOn)
Partial-order planning(POP)
Any planning algorithm that can place two actions into a plan without which comes first is a PO plan.
4 februari 2012
AI 1
22
A B
AI 1
4 februari 2012
23
4 februari 2012
AI 1
24
4 februari 2012
AI 1
25
Solving POP
Assume propositional planning problems:
The initial plan contains Start and Finish, the ordering constraint Start < Finish, no causal links, all the preconditions in Finish are open. Successor function :
picks one open precondition p on an action B and generates a successor plan for every possible consistent way of choosing action A that achieves p.
Test goal
4 februari 2012 AI 1 26
Enforcing consistency
When generating successor plan:
The causal link A->p->B and the ordering constraint A < B is added to the plan.
If A is new also add start < A and A < B to the plan
Resolve conflicts between new causal link and all existing actions Resolve conflicts between action A (if new) and all existing causal links.
4 februari 2012
AI 1
27
Process summary
Operators on partial plans
Add link from existing plan to open precondition. Add a step to fulfill an open condition. Order one step w.r.t another to remove possible conflicts
Gradually move from incomplete/vague plans to complete/correct plans Backtrack if an open condition is unachievable or if a conflict is irresolvable.
4 februari 2012 AI 1 28
4 februari 2012
AI 1
30
Initial plan: Start with EFFECTS and Finish with PRECOND. Pick an open precondition: At(Spare, Axle) Only PutOn(Spare, Axle) is applicable PutOn(Spare, Axle) At(Spare,Axle ) Finish Add causal link: Add constraint : PutOn(Spare, Axle) < Finish
4 februari 2012
AI 1
31
Pick an open precondition: At(Spare, Ground) Only Remove(Spare, Trunk) is applicable Re move(Spare,Trunk) At(Spare,Ground ) PutOn(Spare, Axle) Add causal link: Add constraint : Remove(Spare, Trunk) < PutOn(Spare,Axle)
4 februari 2012
AI 1
32
Pick an open precondition: At(Flat, Axle) LeaveOverNight is applicable conflict: LeaveOverNight also has the effect At(Spare,Ground)
4 februari 2012
AI 1
33
To resolve, add constraint : LeaveOverNight < Remove(Spare, Trunk) Add causal link:
4 februari 2012
Pick an open precondition: At(Spare, Trunk) Only Start is applicable Add causal link: Start At(Spare,Trunk ) Re move(Spare,Trunk) Conflict: of causal link with effect At(Spare,Trunk) in LeaveOverNight
No re-ordering solution possible.
backtrack
4 februari 2012
AI 1
35
Remove LeaveOverNight, Remove(Spare, Trunk) and causal links Repeat step with Remove(Spare,Trunk) Add also RemoveFlatAxle and finish
4 februari 2012
AI 1
36
Some details
What happens when a first-order representation that includes variables is used?
Complicates the process of detecting and resolving conflicts. Can be resolved by introducing inequality constraint.
CSPs most-constrained-variable constraint can be used for planning algorithms to select a PRECOND.
4 februari 2012
AI 1
37
Planning graphs
Used to achieve better heuristic estimates.
A solution can also directly extracted using GRAPHPLAN.
4 februari 2012
AI 1
38
Planning graphs
Could?
Records only a restricted subset of possible negative interactions among actions.
4 februari 2012
AI 1
39
Cake example
Start at level S0 and determine action level A0 and next level S1.
A0 >> all actions whose preconditions are satisfied in the previous level. Connect precond and effect of actions S0 --> S1 Inaction is represented by persistence actions.
4 februari 2012
AI 1
40
Cake example
Level S1 contains all literals that could result from picking any subset of actions in A0
Conflicts between literals that can not occur together (as a consequence of the selection action) are represented by mutex links. S1 defines multiple states and the mutex links are the constraints that define this set of states.
Cake example
Level of appearance can be used as cost estimate of achieving any goal literals = level cost. Small problem: several actions can occur
Restrict to one action using serial PG (add mutex links between every pair of actions, except persistence actions).
PG is a relaxed problem.
4 februari 2012
AI 1
43
4 februari 2012
AI 1
44
4 februari 2012
AI 1
45
GRAPHPLAN example
Initially the plan consist of 5 literals from the initial state and the CWA literals (S0). Add actions whose preconditions are satisfied by EXPAND-GRAPH (A0) Also add persistence actions and mutex relations. Add the effects at level S1 Repeat until goal is in level Si
4 februari 2012 AI 1 46
GRAPHPLAN example
Interference
E.g. Remove(Flat, Axle) and LeaveOverNight At(Flat, Axle) as PRECOND and not At(Flat,Axle) as EFFECT
Competing needs
E.g. PutOn(Spare,Axle) and Remove(Flat, Axle) due to At(Flat.Axle) and not At(Flat, Axle)
Inconsistent support
E.g. in S2, At(Spare,Axle) and At(Flat,Axle)
4 februari 2012 AI 1 47
GRAPHPLAN example
In S2, the goal literals exist and are not mutex with any other
Solution might exist and EXTRACT-SOLUTION will try to find it
EXTRACT-SOLUTION can use Boolean CSP to solve the problem or a search process:
Initial state = last level of PG and goal goals of planning problem Actions = select any set of non-conflicting actions that cover the goals in the state Goal = reach level S0 such that all goals are satisfied Cost = 1 for each action.
4 februari 2012
AI 1
48
GRAPHPLAN example
Because of these properties and because there is a finite number of actions and literals, every PG will eventually level off !
4 februari 2012 AI 1 49
4 februari 2012
AI 1
50
SATPLAN algorithm
function SATPLAN(problem, Tmax) return solution or failure inputs: problem, a planning problem Tmax, an upper limit to the plan length for T= 0 to Tmax do cnf, mapping TRANSLATE-TO_SAT(problem, T) assignment SAT-SOLVER(cnf) if assignment is not null then return EXTRACT-SOLUTION(assignment, mapping) return failure
4 februari 2012
AI 1
51
4 februari 2012
AI 1
52
cnf, mapping TRANSLATE-TO_SAT(problem, T) How to determine the time step where the goal will be reached?
Start at T=0
Assert At(P1,SFO)0 At(P2,JFK)0
Failure .. Try T=1 Repeat this until some minimal path length is reached.
Termination is ensured by Tmax
Assert At(P1,SFO)1 At(P2,JFK)1
4 februari 2012
AI 1
53
Once all these axioms are in place, the satisfiability algorithm can start to find a plan.
4 februari 2012 AI 1 54
assignment SAT-SOLVER(cnf)
Multiple models can be found They are NOT satisfactory: (for T=1)
Fly(P1,SFO,JFK)0 Fly(P1,JFK,SFO)0 Fly(P2,JFK.SFO)0
The second action is infeasible Yet the plan IS a model of the sentence
Exactly one model now satisfies all the axioms where the goal is achieved at T=1.
4 februari 2012
AI 1
55
The second action is infeasible Yet the plan allows spurious relations
Lost of flexibility since plan becomes totally ordered : no actions are allowed to occur at the same time.
Restrict exclusion to preconditions
4 februari 2012
AI 1
56
Biggest problem is the combinatorial explosion in states. Efficient methods are under research
E.g. divide-and-conquer
4 februari 2012
AI 1
57
Outline
Time, schedules and resources Hierarchical task network planning Non-deterministic domains
Conditional planning Execution monitoring and replanning Continuous planning
Multi-agent planning
4 februari 2012 AI 1 2
Real-world:
+ actions occur at certain moments in time. + actions have a beginning and an end. + actions take a certain amount of time.
Job-shop scheduling:
Complete a set of jobs, each of which consists of a sequence of actions, Where each action has a given duration and might require resources. Determine a schedule that minimizes the total time required to complete all jobs (respecting resource constraints).
4 februari 2012 AI 1 3
4 februari 2012
AI 1
critical path
4 februari 2012
AI 1
4 februari 2012
AI 1
ES and LS
Earliest possible (ES) and latest possible (LS) start times. LS-ES = slack of an action for all actions determines the schedule for the entire problem.
ES(Start) = 0 ES(B)=maxA<B ES(A) + Duration(A) LS(Finish)=ES(Finish) LS(A) = minA<B LS(B) -Duration(A)
4 februari 2012
AI 1
4 februari 2012
AI 1
4 februari 2012
AI 1
10
Hierarchical task network (HTN) planning uses a refinement of actions through decomposition.
e.g. building a house = getting a permit + hiring a contractor + doing the construction + paying the contractor. Refined until only primitive actions remain.
4 februari 2012
AI 1
12
Representation decomposition
General descriptions are stored in plan library.
Each method = Decompos(a,d); a= action and d= PO plan.
See buildhouse example Start action supplies all preconditions of actions not supplied by other actions.
=external preconditions
Finish action has all effects of actions not present in other actions
=external effects
Primary effects (used to achieve goal) vs. secondary effects
4 februari 2012 AI 1 13
Buildhouse example
External precond
External effects
4 februari 2012
AI 1
14
Buildhouse example
Action(Buyland, PRECOND: Money, EFFECT: Land Money) Action(GetLoan, PRECOND: Goodcredit, EFFECT: Money Mortgage) Action(BuildHouse, PRECOND: Land, EFFECT: House) Action(GetPermit, PRECOND: LAnd, EFFECT: Permit) Action(HireBuilder, EFFECT: Contract) Action(Construction, PRECOND: Permit Contract, EFFECT: HouseBuilt Permit), Action(PayBuilder, PRECOND: Money HouseBuilt, EFFECT: Money House Contract), Decompose(BuildHouse, Plan ::STEPS{ S1: GetPermit, S2:HireBuilder, S3:Construction, S4 PayBuilder} ORDERINGS: {Start < S1 < S3< S4<Finish, Start<S2<S3}, LINKS
Start Land S1,Start Money S4,S1 Permit S3,S2 Contract S3, S3 HouseBuilt S4,S4 house Finish,S4 Money Finish
4 februari 2012 AI 1 15
Properties of decomposition
Should be correct implementation of action a
Correct if plan d is complete and consistent PO plan for the problem of achieving the effects of a given the preconditions of a.
4 februari 2012
AI 1
18
4 februari 2012
AI 1
19
POP+HTN example
a
4 februari 2012
AI 1
20
POP+HTN example
a
4 februari 2012
AI 1
21
How to hook up d in a?
Remove action a from P and replace with d
For each step s in d select an action that will play the role of s (either new s or existing s from P) Possibility of subtask sharing
4 februari 2012
AI 1
22
Resolve problems by
Rule out recursion. Bound the length of relevant solutions, Hybridize HTN with POP
4 februari 2012
AI 1
23
4 februari 2012
AI 1
24
Non-deterministic domains
So far: fully observable, static and deterministic domains.
Agent can plan first and then execute plan with eyes closed
Uncertain environment: incomplete (partially observable and/or nondeterministic) and incorrect (differences between world and model) information
Use percepts Adapt plan when necessary
4 februari 2012
AI 1
25
Handling indeterminacy
Sensorless planning (conformant planning)
Find plan that achieves goal in all possible circumstances (regardless of initial state and action effects).
Continuous planning
Planning active for a life time: adapt to changed circumstances and reformulate goals if necessary.
4 februari 2012
AI 1
26
Sensorless planning
4 februari 2012
AI 1
27
Abstract example
Initial state = <chair,table, cans of paint, unknown colors>, goal state=<color(table) = color(chair)> Sensorless planning (conformant planning)
Open any can of paint and apply it to both chair and table.
Continuous planning
Can revise goal when we want to first eat before painting the table and the chair.
4 februari 2012
AI 1
28
Conditional planning
Deal with uncertainty by checking the environment to see what is really happening. Used in fully observable and nondeterministic environments:
The outcome of an action is unknown. Conditional steps will check the state of the environment. How to construct a conditional plan?
4 februari 2012
AI 1
29
4 februari 2012
AI 1
30
Conditional planning
Actions: left, right, suck Propositions to define states: AtL, AtR, CleanL, CleanR How to include indeterminism?
Actions can have more than one effect
E.g. moving left sometimes fails Action(Left, PRECOND: AtR, EFFECT: AtL) Becomes : Action(Left, PRECOND: AtR, EFFECT: AtLAtR)
4 februari 2012
AI 1
31
Conditional planning
Conditional plans require conditional steps:
If <test> then plan_A else plan_B
if AtLCleanL then Right else Suck
4 februari 2012
AI 1
32
Game tree
State node chance node
4 februari 2012
AI 1
33
In previous example:
[Left, if AtL CleanL CleanR then [] else Suck]
4 februari 2012
AI 1
34
And-Or-search algorithm
function AND-OR-GRAPH-SEARCH(problem) returns a conditional plan or failure return OR-SEARCH(INITIAL-STATE[problem], problem, []) function OR-SEARCH(state, problem, path) returns a conditional plan or failure if GOAL-TEST[problem](state) then return the empty plan if state is on path then return failure for action,state_set in SUCCESSORS[problem](state) do plan AND-SEARCH(state_set, problem, [state | plan] ) if plan failure then return [action | plan] return failure function AND-SEARCH(state_set, problem, path) returns a conditional plan or failure for each si in state_set do plani OR-SEARCH(si, problem,path ) if plan = failure then return failure return [ if s1 then plan1 else if s2 then plan2 else if sn-1 then plann-1 else plann]
4 februari 2012 AI 1 35
And-Or-search algorithm
How does it deal with cycles?
When a state that already is on the path appears, return failure
No non-cyclic solution
4 februari 2012
AI 1
36
And-Or-search algorithm
Sometimes only a cyclic solution exists e.g. tripple murphy: sometimes the move is not performed
[Left, if CleanL then [] else Suck] is not a solution
4 februari 2012
AI 1
37
4 februari 2012
AI 1
38
4 februari 2012
AI 1
39
Belief states
Representation?
Sets of full state descriptions
{(AtRCleanRCleanL) (AtRCleanRCleanL)}
Logical sentences that capture the set of possible worlds in the belief state (OWA)
AtR CleanR
4 februari 2012
AI 1
40
Belief states
Choice 2 and 3 are equivalent (lets continue with 3) Symbols can appear in three ways in three ways: positive, negative or unknown: 3n possible belief states for n proposition symbols.
YET, set of belief sets is a power set of the phyiscal states which is much larger than 3n Hence 3 is restricted as representation
Any scheme capable of representing every possible belief state will require O(2n) bit to represent each one in the worst case. The current scheme only requires O(n)
4 februari 2012
AI 1
41
Active sensing
Percepts are obtained through the execution of specific sensory actions. checkDirt and checkLocation
Given the representation and the sensing, action descriptions can now be formulated.
4 februari 2012
AI 1
42
Kinds of monitoring:
Action monitoring: verify whether the next action will work. Plan monitoring: verify the entire remaining plan.
4 februari 2012
AI 1
43
Can be applied in both fully and partially observable environments, and to a variety of planning representations.
4 februari 2012
AI 1
44
Replanning-agent
function REPLANNING-AGENT(percept) returns an action static: KB, a knowledge base (+ action descriptions) plan, a plan initially [] whole_plan, a plan initially [] goal, a goal TELL(KB, MAKE-PERCEPT-SENTENCE(percept,t)) current STATE-DESCRIPTION(KB,t) if plan = [] then return the empty plan whole_plan plan PLANNER(current, goal, KB) if PRECONDITIONS(FIRST(plan)) not currently true in KB then candidates SORT(whole_plan,ordered by distance to current) find state s in candidates such that failure repair PLANNER(current, s, KB) continuation the tail of whole_plan starting at s whole_plan plan APPEND(repair, continuation) return POP(plan)
4 februari 2012
AI 1
45
Repair example
4 februari 2012
AI 1
46
4 februari 2012
AI 1
47
4 februari 2012
AI 1
48
Plan monitoring
Check the preconditions for success of the entire plan.
Except those which are achieved by another step in the plan. Execution of doomed plan is cut of earlier.
4 februari 2012
AI 1
49
Continuous planning.
Agent persists indefinitely in an environment
Phases of goal formulation, planning and acting
4 februari 2012
AI 1
50
Initial state (a) Action(Move(x,y), PRECOND: Clear(x) Clear(y) On(x,z) EFFECT: On(x,y) Clear(z) On(x,z) Clear(y) The agent first need to formulate a goal: On(C,D) On(D,B) Plan is created incrementally, return NoOp and check percepts
4 februari 2012
AI 1
51
Assume that percepts dont change and this plan is constructed Ordering constraint between Move(D,B) and Move(C,D) Start is label of current state during planning. Before the agent can execute the plan, nature intervenes:
D is moved onto B
4 februari 2012
AI 1
52
Start contains now On(D,B) Agent perceives: Clear(B) and On(D,G) are no longer true
Update model of current state (start)
Causal links from Start to Move(D,B) (Clear(B) and On(D,G)) no longer valid.
Remove causal relations and two PRECOND of Move(D,B) are open Replace action and causal links to Finish by connecting Start to Finish.
4 februari 2012
AI 1
53
Extending: whenever a causal link can be supplied by a previous step All redundant steps (Move(D,B) and its causal links) are removed from the plan Execute new plan, perform action Move(C,D)
This removes the step from the plan
4 februari 2012
AI 1
54
No plan but still an open PRECOND Determine new plan for open condition Again Move(C,D)
4 februari 2012
AI 1
55
Similar to POP On each iteration find plan-flaw and fix it Possible flaws: Missing goal, Open precondition, Causal conflict, Unsupported link, Redundant action, Unexecuted action, unnecessary historical goal
4 februari 2012
AI 1
56
Multi-agent planning
So far we only discussed single-agent environments. Other agents can simply be added to the model of the world:
Poor performance since agents are not indifferent ot other agents intentions
4 februari 2012
AI 1
57
4 februari 2012
AI 1
58
Or
A: [Go(A,[Left, net), NoOp(A)] B: [Go(B,[Right, Baseline]), Hit(B, Ball)]
4 februari 2012
AI 1
59
Multi-body planning
Planning problem faced by a single centralized agent that can dictate action to each of several physical entities. Hence not truly multi-agent Important: synchronization of actions
Assume for simplicity that every action takes one time step and at each point in the joint plan the actions are performed simultaneously
[<Go(A,[Left,Net]), Go(B,[Right,Baseline]>; <NoOp(A), Hit(B, Ball)>]
Planning can be performed using POP applied to the set of all possible joint actions.
Size of this set???
4 februari 2012
AI 1
60
Multi-body planning
Alternative to set of all joint actions: add extra concurrency lines to action description
Concurrent action
Action(Hit(A, Ball) CONCURRENT: Hit(B,Ball) PRECOND: Approaching(Ball,[x,y]) At(A,[x,y]) EFFECT: Returned(Ball))
Planner similar to POP with some small changes in possible ordering relations
4 februari 2012
AI 1
61
Coordination mechanisms
To ensure agreement on joint plan: use convention.
Convention = a constraint on the selection of joint plans (beyond the constraint that the joint plan must work if the agents adopt it).
e.g. stick to your court or one player stays at the net.
Conventions which are widely adopted= social laws e.g. language. Can be domain-specific or independent. Could arise through evolutionary process (flocking behavior).
4 februari 2012
AI 1
62
Flocking example
Three rules:
Separation:
Steer away from neighbors when you get too close
Cohesion
Steer toward the average position of neighbors
Alignment
Steer toward average orientation (heading) of neighbors
4 februari 2012
AI 1
63
Coordination mechanisms
In the absence of conventions: Communication
e.g. Mine! Or Yours! in tennis example
4 februari 2012
AI 1
64
Competitive environments
Agents can have conflicting utilities
e.g. zero-sum games like chess
4 februari 2012
AI 1
65
17.05.11
AI NN
Neural Networks
McCulloch & Pitts (1943) are generally recognised as the designers of the first neural network Many of their ideas still used today (e.g. many simple units combine to give increased computational power and the idea of a threshold)
AI NN 2
17.05.11
Neural Networks
Hebb (1949) developed the first learning rule (on the premise that if two neurons were active at the same time the strength between them should be increased)
AI NN 3
17.05.11
Neural Networks
During the 50s and 60s many researchers worked on the perceptron amidst great excitement. 1969 saw the death of neural network research for about 15 years Minsky & Papert Only in the mid 80s (Parker and LeCun) was interest revived (in fact Werbos discovered algorithm in 1974)
AI NN 4
17.05.11
Neural Networks
17.05.11
AI NN
Neural Networks
We are born with about 100 billion neurons A neuron may connect to as many as 100,000 other neurons
17.05.11
AI NN
Neural Networks
Signals move via electrochemical signals The synapses release a chemical transmitter the sum of which can cause a threshold to be reached causing the neuron to fire Synapses can be inhibitory or excitatory
17.05.11
AI NN
17.05.11
AI NN
X2
Y -1
X3
The activation of a neuron is binary. That is, the neuron either fires (activation of one) or does not fire (activation of zero).
17.05.11
AI NN
X2
Y -1
X3
For the network shown here the activation function for unit Y is f(y_in) = 1, if y_in >= else 0 where y_in is the total input signal received is the threshold for Y
17.05.11
AI NN
10
X2
Y -1
X3
17.05.11
AI NN
11
X2
Y -1
X3
17.05.11
AI NN
12
X2
Y -1
X3
All excitatory connections into a particular neuron have the same weight, although different weighted connections can be input to different neurons
17.05.11
AI NN
13
X2
Y -1
X3
Each neuron has a fixed threshold. If the net input into the neuron is greater than or equal to the threshold, the neuron fires
17.05.11
AI NN
14
X2
Y -1
X3
The threshold is set such that any non-zero inhibitory input will prevent the neuron from firing
17.05.11
AI NN
15
X2
Y -1
X3
It takes one time step for a signal to pass over one connection.
17.05.11
AI NN
16
AND Function
AND X1 1 1 0 0
X2 1 0 1 0
Y 1 0 0 0
Threshold(Y) = 2
17.05.11
AI NN
17
OR X1 1 1 0 0
X2 1 0 1 0
Y 1 1 1 0
Threshold(Y) = 2
17.05.11
AI NN
18
AND NOT X1 1 1 0 0
X2 1 0 1 0
Y 0 1 0 0
Threshold(Y) = 2
17.05.11
AI NN
19
XOR X1 1 1 0 0
X2 1 0 1 0
Y 0 1 1 0
17.05.11
AI NN
20
-1
Cold
X2
Z2
1 1
Y2
Cold
17.05.11
AI NN
23
-1
Cold
X2
Z2
1 1
Y2
Cold
It takes time for the stimulus (applied at X1 and X2) to make its way to Y1 and Y2 where we perceive either heat or cold
At t(0), we apply a stimulus to X1 and X2 At t(1) we can update Z1, Z2 and Y1 At t(2) we can perceive a stimulus at Y2 At t(2+n) the network is fully functional AI NN 24
17.05.11
Y2(t) 1 0 0 0
25
17.05.11
AI NN
26
Modelling a Neuron
in i= j W j , i a j
aj wj,I inI aI g
:Activation value of unit j :Weight on the link from unit j to unit i :Weighted sum of inputs to unit i :Activation value of unit i :Activation function AI NN 28
17.05.11
Activation Functions
17.05.11
AI NN
29
Simple Networks
AND
Input 1 Input 2 Output
OR
NOT
0 0 0
0 1 1 1 0 1 0 0 1
0 0 0
0 1 1 1 0 1 1 1 1
0 1
1 0
17.05.11
AI NN
30
Simple Networks
-1 W = 1.5 x W=1 y
t = 0.0
17.05.11
AI NN
31
Perceptron
Synonym for SingleLayer, Feed-Forward Network First Studied in the 50s Other networks were known about but the perceptron was the only one capable of learning and thus all research was concentrated in this area 17.05.11 AI NN 32
Perceptron
A single weight only affects one output so we can restrict our investigations to a model as shown on the right Notation can be simpler, i.e.
O= Step 0 j WjIj
17.05.11
AI NN
33
0 1 0
1 0 0
1 1 1
0 1 1
1 0 1
1 1 0
17.05.11
AI NN
34
0,0
1,0
AND
0,0
1,0
XOR
Functions which can be separated in this way are called Linearly Separable Only linearly Separable functions can be represented by a perceptron AI NN 35
17.05.11
Linear Separability is also possible in more than 3 dimensions but it is harder to visualise 17.05.11 AI NN 36
Training a perceptron
Aim
AND 0 0 0
0 1 0
1 0 0
1 1 1
17.05.11
AI NN
37
Training a perceptrons
-1 W = 0.3 x t = 0.0
W = 0.5
W = -0.4 y
I1 -1 -1 -1 -1
I2 0 0 1 1
I3 0 1 0 1
Summation (-1*0.3) + (0*0.5) + (0*-0.4) = -0.3 (-1*0.3) + (0*0.5) + (1*-0.4) = -0.7 (-1*0.3) + (1*0.5) + (0*-0.4) = 0.2 (-1*0.3) + (1*0.5) + (1*-0.4) = -0.2
AI NN 38
Output 0 0 1 0
17.05.11
Learning
While epoch produces an error
Present network with next inputs from epoch Err = T O If Err <> 0 then Wj = Wj + LR * Ij * Err End If
End While
17.05.11 AI NN 39
Learning
While epoch produces an error
Present network with next inputs from epoch Err = T O If Err <> 0 then Wj = Wj + LR * Ij * Err End If
End While
Epoch : Presentation of the entire training set to the neural network. In the case of the AND function an epoch consists of four sets of inputs being presented to the network (i.e. [0,0], [0,1], [1,0], [1,1]) 17.05.11 AI NN 40
Learning
While epoch produces an error
Present network with next inputs from epoch Err = T O If Err <> 0 then Wj = Wj + LR * Ij * Err End If
End While
Training Value, T : When we are training a network we not only present it with the input but also with a value that we require the network to produce. For example, if we present the network with [1,1] for the AND function the training value will be 1 17.05.11 AI NN 41
Learning
While epoch produces an error
Present network with next inputs from epoch Err = T O If Err <> 0 then Wj = Wj + LR * Ij * Err End If
End While
Error, Err : The error value is the amount by which the value output by the network differs from the training value. For example, if we required the network to output 0 and it output a 1, then Err = -1 17.05.11 AI NN 42
Learning
While epoch produces an error
Present network with next inputs from epoch Err = T O If Err <> 0 then Wj = Wj + LR * Ij * Err End OutputIffrom Neuron, O : The output
End While
Ij : Inputs being presented to the neuron Wj : Weight from input neuron (Ij) to the output neuron LR : The learning rate. This dictates how quickly the network converges. It is set by a matter of experimentation. It is typically 0.1 17.05.11 AI NN 43
Learning
After First Epoch Note I1 point = W0/W1 I2 point = W0/W2
0,1
I1 1,1
0,0
1,0
I2
I1 1,1 0,1
At Convergence
0,0 1,0 I2
17.05.11
AI NN
44
Experiment:
Pigeon in Skinner box Present paintings of two different artists (e.g. Chagall / Van Gogh) Reward for pecking when presented a particular artist (e.g. Van Gogh)
17.05.11
AI NN
45
17.05.11
AI NN
46
17.05.11
AI NN
47
17.05.11
AI NN
48
Pigeons were able to discriminate between Van Gogh and Chagall with 95% accuracy (when presented with pictures they had been trained on) Discrimination still 85% successful for previously unseen paintings of the artists Pigeons do not simply memorise the pictures They can extract and recognise patterns (the style) They generalise from the already seen to make predictions This is what neural networks (biological and artificial) are good at (unlike conventional computer) AI NN 49
17.05.11
Feeding
Squashing: 17.05.11
1 = 0 . 3775 1+ e 0 . 5
AI NN 50
Data is presented to the network in the form of activations in the input layer Examples
Pixel intensity (for pictures) Molecule concentrations (for artificial nose) Share prices (for stock market prediction)
17.05.11
AI NN
51
Weight settings determine the behaviour of a network How can we find the right weights?
17.05.11
AI NN
52
Backpropagation
Requires training set (input / output pairs) Starts with small random weights Error is used to adjust weights (supervised learning) Gradient descent on error landscape
17.05.11
AI NN
53
17.05.11
AI NN
54
Advantages
Downsides
Alternatives to Backpropagation
Hebbian learning
Not successful in feed-forward nets Only limited success More general, but can be even slower than backprop
Reinforcement learning
Artificial evolution
17.05.11
AI NN
55
Task: Learn to discriminate between two different voices saying Hello Data
Sources
Steve Simpson David Raubenheimer Frequency distribution (60 bins) Analogy: cochlea
Format
17.05.11
AI NN
56
Network architecture
17.05.11
AI NN
57
Steve
David
17.05.11
AI NN
58
Steve
David
Calculate error
0.43 0 0.26 1 = 0.43 = 0.74
Steve
David
= 0.27 = 0.55
Steve
David
17.05.11
AI NN
62
Steve
David
17.05.11
AI NN
64
Network has learnt to generalise from original data Networks with different weight settings can have same functionality Trained networks concentrate on lower frequencies
Pattern recognition
Sonar mine/rock recognition (Gorman & Sejnowksi, 1988) Navigation of a car (Pomerleau, 1989) Stock-market prediction Pronunciation (NETtalk)
(Sejnowksi & Rosenberg, 1987)
17.05.11
AI NN
66
17.05.11
AI NN
67
Preference for symmetry not selection for good genes, but instead arises through the need to recognise objects irrespective of their orientation Exaggerated, symmetric ornaments facilitate mate recognition
Johnstone (1994)
Recurrent Networks
Information only flows one way One input pattern produces one output No sense of time (or memory of previous state)
Recurrency
Nodes connect back to other nodes or themselves Information flow is multidirectional Sense of time and memory of previous state(s)
Biological nervous systems show high levels of recurrency (but feed-forward structures exists too) 17.05.11 AI NN 69
Elman Nets
Unlike feed forward nets, Elman nets have a memory or sense of time 17.05.11 AI NN 70
Task
Data
Representation
Training method
Backpropagation
17.05.11
AI NN
71
17.05.11
AI NN
72
Hopfield Networks
Fully recurrent Weights are symmetric Nodes can only be on or off Random updating
17.05.11
AI NN
73
Task: store images with resolution of 20x20 pixels Hopfield net with 400 nodes
Memorise:
1. 2.
Present image Apply Hebb rule (cells that fire together, wire together)
Increase weight between two nodes if both have same activity, otherwise decrease
3.
Go to 1
Recall:
1. 2. 3.
17.05.11
AI NN
74
17.05.11
AI NN
75
Catastrophic forgetting
17.05.11
AI NN
76
17.05.11
AI NN
77
CPGs: group of neurones creating rhythmic muscle activity for locomotion, heart-beat etc. Identified in several invertebrates and vertebrates Hard to study
Computer modelling
17.05.11
AI NN
78
17.05.11
AI NN
79
17.05.11
AI NN
80
Unidirectional flow of information Good at extracting patterns, generalisation and prediction Distributed representation of data Parallel processing of data Training: Backpropagation Not exact models, but good at demonstrating principles
Recurrent networks
17.05.11
Multidirectional flow of information Memory / sense of time Complex temporal dynamics (e.g. CPGs) Various training methods (Hebbian, evolution) Often better biological models than FFNs
AI NN
81
17.05.11
AI NN
82
Current Applications
Investment Analysis
Predicting movement of stocks Replacing earlier linear models Bank Checks, VISA, etc. Chemistry related Sensor networks may gather more data than can be processed by operators Inputs: Cues from camera data, vibration levels, sound, radar, lydar, etc. Output: Number of people at a terminal, engine warning light, control for light switch
Signature Analysis
Process Control
Monitoring
17.05.11
AI NN
83
Current Work
Work of S. Cho, Chow and C. Leung Training Neural Network to approximate crowd size based on image cues Network approximates a non linear mapping between input and output space Their input cues: Black Pixels, White Pixels, Edge Pixels Our proposed inputs: Edge Histogram, Blob Size histogram (based on background model)
AI NN 84
17.05.11
References
[1] L. Smith, ed. (1996, 2001), "An Introduction to Neural Networks", URL: http://www.cs.stir.ac.uk/~lss/NNIntro/InvSlides.html [2] Sarle, W.S., ed. (1997), Neural Network FAQ, URL: ftp://ftp.sas.com/pub/neural/FAQ.html [3] StatSoft, "Neural Networks", URL: http://www.statsoftinc.com/textbook/stneunet.html [4] S. Cho, T. Chow, and C. Leung, "A Neural-Based Crowd Estimation by Hybrid Global Learning Algorithm", IEEE Transactions on Systems, Man and Cybernetics, Part B, No. 4. 1999. 17.05.11 AI NN 85
Contents
Recap of Evolutionary Metaphor Basic scheme of an EA Basic Components:
Representation / Evaluation / Population / Parent Selection / Recombination / Mutation / Survivor Selection / Termination
Examples : eight queens / knapsack Typical behaviours of EAs EC in context of global optimisation
Recap of EC metaphor
A population of individuals exists in an environment with limited resources Competition for those resources causes selection of those fitter individuals that are better adapted to the environment These individuals act as seeds for the generation of new individuals through recombination and mutation The new individuals have their fitness evaluated and compete (possibly also with parents) for survival. Over time Natural selection causes a rise in the fitness of the population
Recap 2:
EAs fall into the category of generate and test algorithms They are stochastic, population-based algorithms Variation operators (recombination and mutation) create the necessary diversity and thereby facilitate novelty Selection reduces diversity and acts as a force pushing quality
Representations
Candidate solutions (individuals) exist in phenotype space They are encoded in chromosomes, which exist in genotype space
Encoding : phenotype=> genotype (not necessarily one to one) Decoding : genotype=> phenotype (must be one to one)
Chromosomes contain genes, which are in (usually fixed) positions called loci (sing. locus) and have a value (allele) In order to find the global optimum, every feasible solution must be represented in genotype space
Some problems may be best posed as minimisation problems, but conversion is trivial
Population
Holds (representations of) possible solutions Usually has a fixed size and is a multiset of genotypes Some sophisticated EAs also assert a spatial structure on the population e.g., a grid. Selection operators usually take whole population into account i.e., reproductive probabilities are relative to current generation Diversity of a population refers to the number of different fitnesses / phenotypes / genotypes present (note not the same thing)
high quality solutions more likely to become parents than low quality but not guaranteed even worst in current population usually has non-zero probability of becoming a parent
This stochastic nature can aid escape from local optima
Variation Operators
Role is to generate new candidate solutions Usually divided into two types according to their arity (number of inputs):
Arity 1 : mutation operators Arity >1 : Recombination operators Arity = 2 typically called crossover
There has been much debate about relative importance of recombination and mutation
Nowadays most EAs use both Choice of particular variation operators is representation dependant
Mutation
Acts on one genotype and delivers another Element of randomness is essential and differentiates it from other unary heuristic operators Importance ascribed depends on representation and dialect:
Binary GAs background operator responsible for preserving and introducing diversity EP for FSMs/ continuous variables only search operator GP hardly used
Recombination
Merges information from parents into offspring Choice of what information to merge is stochastic Most offspring may be worse, or the same as the parents Hope is that some are better by combining elements of genotypes that lead to good traits Principle has been used for millennia by breeders of plants and livestock
Survivor Selection
a.k.a. replacement Most EAs use fixed population size so need a way of going from (parents + offspring) to next generation Often deterministic
Fitness based : e.g., rank parents+offspring and take best Age based: make as many offspring as parents and delete all parents
Sometimes do combination (elitism)
Initialisation / Termination
Initialisation usually done at random,
Need to ensure even spread and mixture of possible allele values Can include existing solutions, or use problem-specific heuristics, to seed the population
Place 8 queens on an 8x8 chessboard in such a way that they cannot check each other
Obvious mapping
1 3 5 2 6 4 7 8
1 3 5 2 6 4 7 8
1 3 7 2 6 4 5 8
1 3 526 4 7 8 8 7 654 3 2 1
1 3 542 8 7 6 8 7 624 1 3 5
Note that is is only one possible set of choices of operators and parameters
Typical behaviour of an EA
Phases in optimising on a 1-dimensional fitness landscape
Early phase: quasi-random population distribution
Answer: - it depends how much you want the last bit of progress - it may be better to do more shorter runs
F: fitness after smart initialisation T: time needed to reach level F after random initialisation
T
perform better than a generic search algorithm on most instances, have limited utility, not do well on all instances
Goal is to provide robust tools that provide:
Random search
better on problems of the given type worse on problems different from given type amount of added knowledge is variable
Recent theory suggests the search for an all-purpose algorithm may be fruitless
EA 2
EA 3
EA 1
e.g. box decomposition (branch and bound etc) Guarantee to find x* , but may run in superpolynomial time
Heuristic Approaches (generate and test)
rules for deciding which x S to generate next no guarantees that best solutions found are globally optimal
But problems often exhibit many local optima Often very quick to identify good solutions
EAs are distinguished by:
Use of population, Use of multiple, stochastic search operators Especially variation operators with arity >1 Stochastic selection
GA Quick Overview
Developed: USA in the 1970s Early names: J. Holland, K. DeJong, D. Goldberg Typically applied to:
discrete optimization
Attributed features:
not too fast good heuristic for combinatorial problems
Special Features:
Traditionally emphasizes combining information from good parents (crossover) many variants, e.g., reproduction models, operators
Genetic algorithms
Hollands original GA is now known as the simple genetic algorithm (SGA) Other GAs use different:
Representations Mutations Crossovers Selection mechanisms
Representation
Phenotype space Genotype space = {0,1}L 10010001 10010010 010001001 011101001 Decoding (inverse representation)
Encoding (representation)
1. Select parents for the mating pool (size of mating pool = population size) 2. Shuffle the mating pool 3. For each consecutive pair apply crossover with probability pc , otherwise copy parents 4. For each offspring apply mutation (bit-flip with probability pm independently for each bit) 5. Replace the whole population with the resulting offspring
1/6 = 17%
A
3/6 = 50%
2/6 = 33%
An example after Goldberg 89 (1) Simple problem: max x2 over {0,1,,31} GA approach:
Representation: binary code, e.g. 01101 13 Population size: 4 1-point xover, bitwise mutation Roulette wheel selection Random initialisation
x2 example: selection
X2 example: crossover
X2 example: mutation
The simple GA
Has been subject of many (early) studies
still often used as benchmark for novel GAs
more likely to keep together genes that are near each other Can never keep together genes from opposite ends of string This is known as Positional Bias Can be exploited if we know about the structure of our problem, but this is not usually the case
n-point crossover
Choose n random crossover points Split along those points Glue parts, alternating between parents Generalisation of 1 point (still some positional bias)
Uniform crossover
Assign 'heads' to one parent, 'tails' to the other Flip a coin for each gene of the first child Make an inverse copy of the gene for the second child Inheritance is independent of position
Crossover OR mutation?
Decade long debate: which one is better / necessary / main-background Answer (at least, rather wide agreement):
it depends on the problem, but in general, it is good to have both both have another role mutation-only-EA is possible, xover-only-EA would not work
Other representations
Gray coding of integers (still binary chromosomes)
Gray coding is a mapping that means that small changes in the genotype cause small changes in the phenotype (unlike binary coding). Smoother genotype-phenotype mapping makes life easier for the GA
Nowadays it is generally accepted that it is better to encode numerical variables directly as Integers Floating point variables
Integer representations
Some problems naturally have integer variables, e.g. image processing parameters Others take categorical values from a fixed set e.g. {blue, green, yellow, pink} N-point / uniform crossover operators work Extend bit-flipping mutation to make
creep i.e. more likely to move to similar value Random choice (esp. categorical variables) For ordinal problems, it is hard to know correct range for creep, so often use two mutation operators in tandem
y x L1 ( a1 ,..., aL ) = x + L ( aL j 2 j ) [ x, y ] 2 1 j =0
Only 2L values out of infinite are represented L determines possible maximum precision of solution High precision long chromosomes (slow evolution)
Uniform mutation:
Intermediate
exploits idea of creating children between parents (hence a.k.a. arithmetic recombination) zi = xi + (1 - ) yi where : 0 1. The parameter can be:
constant: uniform arithmetical crossover variable (e.g. depend on the age of the population) picked at random every time
x1 , ..., xk , yk + (1 ) xk , ..., xn
x , ..., x , y + (1 ) x , ..., y + (1 ) x 1 k k +1 k +1 n n
reverse for other child. e.g. with = 0.5
a x + (1 a ) y
reverse for other child. e.g. with = 0.5
Permutation Representations
Ordering/sequencing problems form a special type Task is (or can be solved by) arranging some objects in a certain order
Example: sort algorithm: important thing is which elements occur before others (order) Example: Travelling Salesman Problem (TSP) : important thing is which elements occur next to each other (adjacency)
Therefore must change at least two values Mutation parameter now reflects the probability that some operator is applied once to the whole string, rather than individually in each position
Many specialised operators have been devised which focus on combining order or adjacency information from the two parents
Order 1 crossover
Idea is to preserve relative order that elements occur Informal procedure:
1. Choose an arbitrary part from the first parent 2. Copy this part to the first child 3. Copy the numbers that are not in the first part, to the first child:
starting right from cut point of the copied part, using the order of the second parent and wrapping around at the end
PMX example
Step 1
Step 2
Step 3
Cycle crossover
Basic idea: Each allele comes from one parent together with its position.
Informal procedure:
1. Make a cycle of alleles from P1 in the following way.
(a) Start with the first allele of P1. (b) Look at the allele at the same position in P2. (c) Go to the position with the same allele in P1. (d) Add this allele to the cycle. (e) Repeat step b through d until you arrive at the first allele of P1.
2. Put the alleles of the cycle in the first child on the positions they have in the first parent. 3. Take next cycle from second parent
Edge Recombination
Works by constructing a table listing which edges are present in the two parents, if an edge is common to both, mark with a + e.g. [1 2 3 4 5 6 7 8 9] and [9 3 7 8 2 6 5 1 4]
Edge Recombination 2
Informal procedure once edge table is constructed
1. Pick an initial element at random and put it in the offspring 2. Set the variable current element = entry 3. Remove all references to current element from the table 4. Examine list for current element:
If there is a common edge, pick that to be next element Otherwise pick the entry in the list which itself has the shortest list Ties are split at random
Multiparent recombination
Recall that we are not constricted by the practicalities of nature Noting that mutation uses 1 parent, and traditional crossover 2, the extension to a>2 is natural to examine Been around since 1960s, still rare but studies indicate useful Three main types:
Based on allele frequencies, e.g., p-sexual voting generalising uniform crossover Based on segmentation and recombination of the parents, e.g., diagonal crossover generalising n-point crossover Based on numerical operations on real-valued alleles, e.g., center of mass crossover, generalising arithmetic recombination operators
Population Models
SGA uses a Generational model:
each individual survives for exactly one generation the entire set of parents is replaced by the offspring
Generation Gap
the proportion of the population replaced 1.0 for GGA, 1/pop_size for SSGA
Fitness-Proportionate Selection
Problems include
One highly fit member can rapidly take over if rest of population is much less fit: Premature Convergence At end of runs when fitnesses are similar, lose selection pressure Highly susceptible to function transposition
Linear Ranking
measures advantage of best individual in GGA this is the number of children allotted to it
Simple 3 member example
Exponential Ranking
Linear Ranking is limited to selection pressure Exponential Ranking can allocate more than 2 copies to fittest individual Normalise constant factor c according to population size
Tournament Selection
All methods above rely on global population statistics
Could be a bottleneck esp. on parallel machines Relies on presence of external fitness function which might not exist: e.g. evolving game players
Informal Procedure:
Pick k members at random then select the best of these Repeat to select more individuals
Tournament Selection 2
Probability of selecting i will depend on:
Rank of i Size of sample k
higher k increases selection pressure
Whether fittest contestant always wins (deterministic) or this happens with probability p
For k = 2, time for fittest individual to take over population is the same as linear ranking with s = 2 p
Survivor Selection
Most of methods above used for parent selection Survivor selection can be divided into two approaches:
Age-Based Selection
e.g. SGA In SSGA can implement as delete-random (not recommended) or as first-in-first-out (a.k.a. deleteoldest)
Fitness-Based Selection
Using one of the methods above or
fitness of a permutation is the duration of the corresponding schedule (to be minimized) use any suitable mutation and crossover use roulette wheel parent selection on inverse fitness Generational GA model for survivor selection use random initialisation
04.02.2012
AI HH
A quantitative description of membrane current and its application to conduction and excitation in nerve. The Journal of Physiology 117:500-544 (1952)
04.02.2012
AI HH
04.02.2012
AI HH
Nervous System
Signals are propagated from nerve cell to nerve cell (neuron) via electro-chemical mechanisms ~100 billion neurons in a person Hodgkin and Huxley experimented on squid giant axons and discovered how the signal is produced and propagate within the neuron H.-H. model was published in Jour. of Physiology (1952) H.-H. were awarded 1963 Nobel Prize FitzHugh-Nagumo model is a simplification
04.02.2012 AI HH 4
Neurons
Basic morphology
Presynaptic terminal (axon or dendrite) Postsynaptic process (dendrite or cell body)
Cerebral cortex
108 - 109 synapses/mm3 0.5 - 1.0 m diameter of synaptic contact
04.02.2012
AI HH
Neuron
04.02.2012
04.02.2012
AI HH
04.02.2012
AI HH
04.02.2012
AI HH
Depolarisation
Repolarisation
Restingpotential
Posthyperpolarisation
Restingpotential
04.02.2012
AI HH
10
04.02.2012
AI HH
Synaptic transmission
Depolarization due to action potential Influx of calcium Exocystosis of synaptic vesicles Diffusion of neurotransmitter Binding to postsynaptic receptors
04.02.2012
AI HH
12
04.02.2012
AI HH
13
Currents
V denotes the membrane voltage IK is the potassium current INa is the sodium current IL is a leakage current
04.02.2012
AI HH
14
Circuit
04.02.2012
AI HH
15
04.02.2012
AI HH
16
Action Potential
mV _ 30
_0
10 msec -70
04.02.2012 AI HH
Axon membrane potential difference V = Vi Ve When the axon is excited, V spikes because sodium Na+ and potassium K+ ions flow through the membrane.
17
Charge across a capacitor is q = CE, C is capacitance, E is the voltage across the capacitor, differentiating:
Ohms law:
dq dE =C dt dt
V = IR I = V / R = gV
Hodkin Huxley equations K and Na nonlinear functions of membrane voltage and time.
I c= g c (V , t ) (V (t ) E (t ))
04.02.2012
V-Vc is the voltage difference across the membrane and the equilibrium value for the ion is Vc, which may change in time.
AI HH
18
Traveling wave
04.02.2012
20
Circuit Equations
Since the sum of the currents is 0, it follows that
dV C = Na (V V Na ) g K (V V K ) gr (V Vr ) + Iap g dt
where Iap is applied current. If ion conductances are constants then group constants to obtain 1st order, linear eq
dV C = g (V V *) + Iap dt
Solving gives
04.02.2012
V (t ) V * + Iap / g
AI HH
21
Variable Conductance
g
Experiments showed that gNa and gK varied with time and V. After stimulus, Na responds much more rapidly than K . 04.02.2012 AI HH 22
Hodgkin-Huxley System
Four state variables are used: v(t)=V(t)-Veq is membrane potential, m(t) is Na activation, n(t) is K activation and h(t) is Na inactivation.
In terms of these variables gK=gKn4 and gNa=gNam3h. The resting potential Veq-70mV. Voltage clamp experiments determined gK and n as functions of t and hence the parameter dependences on v in the differential eq. for n(t). Likewise for m(t) and h(t).
04.02.2012 AI HH 23
Hodgkin-Huxley System
dv 3 4 C = g Na m h(v VNa ) g K n (v VK ) gr (v Vr ) + I ap dt
dm = m( v )(1 m) m( v )m dt dn = n ( v )(1 n ) n ( v )n dt
04.02.2012
dh = h ( v )(1 h ) h ( v )h dt
AI HH
24
110 mV
n(t) 40msec
h(t) 10msec
04.02.2012
25
Fast-Slow Dynamics
m(t)
h(t)
n(v) and h(v). An increase in v results in an increase in m(v) and a large dm/dt. Hence Na activates more rapidly than K in response to a change in v.
10msec
FitzHugh-Nagumo System
dv = f (v ) w + I dt
and
dw = v 0.5w dt
dw ( v 0.5w) = dv f (v ) w + I
which is small unless the solution is near f(v)-w+I=0. Thus the slow manifold is the cubic w=f(v)+I which is the nullcline of the fast variable v. And w is the slow variable with nullcline w=2v.
04.02.2012 AI HH 27
04.02.2012
AI HH
28
FitzHugh-Nagumo Orbits
04.02.2012
AI HH
29
04.02.2012
AI HH
30
04.02.2012
AI HH
31
04.02.2012
AI HH
32
04.02.2012
Interconnect
AI HH
34
04.02.2012
AI HH
35
Basic neurobiology: Combine inhibitory and excitatory signals at different times to fire a neuron.
04.02.2012
AI HH
36
Computer science: Programing a simple early computer demonstrates basic computer science concepts.
04.02.2012
AI HH
37
Neural networks: Use a learning algorithm to understand how the brain stabilizes the eyes during head movement.
04.02.2012
AI HH
38
Active neural membranes: Explore the HodgkinHuxley equations, the classical explanation of neural membrane biophysics.
04.02.2012
AI HH
39
04.02.2012
AI HH
40
References
1. C.G. Boeree, The Neuron, www.ship.edu/~cgboeree/. 2. R. FitzHugh, Mathematical models of excitation and propagation in nerve, In: Biological Engineering, Ed: H.P. Schwan, McGraw-Hill, New York, 1969. 3. L. Edelstein-Kesket, Mathematical Models in Biology, Random House, New York, 1988. 4. A.L. Hodgkin, A.F. Huxley and B. Katz, J. Physiology 116, 424448,1952. 5. A.L. Hodgkin and A.F. Huxley, J. Physiol. 116, 449-566, 1952. 6. F.C. Hoppensteadt and C.S. Peskin, Modeling and Simulation in Medicine and the Life Sciences, 2nd ed, Springer-Verlag, New York, 2002. 7. J. Keener and J. Sneyd, Mathematical Physiology, SpringerVerlag, New York, 1998. 8. J. Rinzel, Bull. Math. Biology 52, 5-23, 1990. 9. E.K. Yeargers, R.W. Shonkwiler and J.V. Herod, An Introduction to the Mathematics of Biology: with Computer 41 04.02.2012 AI HH Algebra Models, Birkhauser, Boston, 1996.