Introduction to Artificial Intelligence with Python
Instructor: Brian Yu
In this class, we explore ideas, techniques, and algorithms foundational to artificial intelligence (AI).
What is AI?
- Computer performing tasks that seem intelligent or rational.
- Examples: face recognition, game playing, natural language understanding.
Class Overview
- Search: AI finding solutions to problems, e.g., driving directions, tic-tac-toe moves.
- Knowledge: AI representing and drawing inferences from information.
- Uncertainty: Dealing with probabilities and uncertain events.
- Optimization: Finding the best or better ways to solve problems.
- Machine Learning: Learning from data and improving task performance.
- Neural Networks: AI drawing inspiration from the human brain's structure.
- Language: Understanding and processing natural human languages.
Focus Today: Search
- AI finding solutions from an initial state to a goal state.
- Examples: solving the 15 puzzle, navigating mazes, finding driving directions.
Key Terminology
- Agent: Entity that perceives and acts on its environment.
- State: Configuration of the agent in its environment.
- Initial State: The starting point for the search algorithm.
- Actions: Choices available in a given state, defined as a function
actions(S)
returning a set of actions.
- Transition Model: Describes the outcome state after performing an action, defined as a function
result(S,A)
.
- State Space: Set of all states reachable from the initial state.
- Goal Test: Determines if a state is a goal state.
- Path Cost: Numerical cost associated with a path, aiming to minimize it.
Search Problem Components
- Initial state
- Actions available in each state
- Transition model for actions
- Goal test to identify goal state
- Path cost function to evaluate paths
Representing Nodes
- Store state, parent, action, and path cost.
- Nodes help backtrack from goal to initial state to form the solution path.
Search Algorithm (Pseudocode)
- Initialize the frontier with the initial state.
- Repeat:
- If the frontier is empty, there is no solution.
- Remove a node from the frontier.
- If the node contains a goal, return the solution.
- Expand the node and add resulting nodes to the frontier.
- Keep track of explored states to avoid infinite loops.
Depth First Search (DFS)
- Uses a stack (LIFO) for the frontier.
- Explores the deepest nodes first.
- Not necessarily optimal.
- May explore more states than needed.
Breadth First Search (BFS)
- Uses a queue (FIFO) for the frontier.
- Explores the shallowest nodes first.
- More efficient in finding an optimal solution (shortest path).
Advantages and Limitations
- DFS: Can be memory efficient but not always optimal.
- BFS: Finds optimal solution but can be memory intensive.
Greedy Best-First Search
- Expands the node that appears to be closest to the goal using a heuristic function
h(n)
.
- Uses a heuristic for estimating distance to the goal, e.g., Manhattan distance.
- Not necessarily optimal.
A* Search
- Combines path cost (
g(n)
) and heuristic cost (h(n)
), considering g(n) + h(n)
.
- Optimal if the heuristic is admissible (never overestimates) and consistent.
Adversarial Search
- Minimax Algorithm: For games with two players making alternating moves.
maxValue
: Calculates the maximum value if it's the max player's turn.
minValue
: Calculates the minimum value if it's the min player's turn.
- Alpha-Beta Pruning: Optimization to eliminate unnecessary branches.
Practical Use Case: Games
- E.g., Tic-Tac-Toe, Chess.
- Turns the game into a tree of possible moves, evaluating with Minimax and pruning.
- Depth-limited Minimax for complex games with evaluation functions to estimate game state utility.
Conclusion
- Today's lecture focused on search algorithms in AI.
- Next lecture will discuss how AI represents knowledge and draws inferences.