AI - Fall2024 (Week 1)
AI - Fall2024 (Week 1)
Welcome to our course on Artificial Intelligence (AI)! This course is designed to explore the
core strategies and foundational concepts that power intelligent systems, solving complex,
real-world problems across various domains. From navigating routes to optimizing industrial
processes, and from playing strategic games to making predictive models, the use of AI is
pivotal in creating efficient and effective solutions.
These lecture notes have been prepared by Ipshita Bonhi Upoma (Lecturer, BRAC Uni-
versity) based on the book "Artificial Intelligence: A Modern Approach" by Peter Norvig
and Stuart Russell. The credit for the initial typesetting of these notes goes to Arifa Alam.
The purpose of these notes is to provide additional examples to enhance the understand-
ing of how basic AI algorithms work and the types of problems they can solve.
This is a work in progress, and as it is the first time preparing such notes, many parts
need citations and rewriting. Several graphs, algorithms and images are directly borrowed
from Russell and Norvig’s book. The next draft will address these citations.
As this is the first draft, please inform us of any typos, mathematical errors, or other tech-
nical issues so they can be corrected in future versions.
Marks Distribution
• Class Task 5%
3
Artificial Intelligence
• Lab 20%
• Mid 25%
• Final 30%
1. Classwork on the lecture will be given after the lecture and attendance will be counted
based on the classwork.
2. Feel free to bring coffee/ light snacks for yourself. Make sure to not cause any noise in
the class.
3. If you are not enjoying the lecture you are free to leave the lecture, but in no way you
should do anything that disturbs me or the other students.
4. If you want me to consider a leave of absence, email with valid reason. Classwork must
be submitted even if leave is considered.
7. Cheating in any form will not be tolerated and will result in a 100% penalty.
8. If bonus assignments are given, the marks of bonus will be added after completion of
all other assessments.
10. No grace marks will be given for any grade bump. Such requests will not be taken
nicely.
Note To Students 3
Contents 5
I 7
1 Introduction: Past, present, future 9
1.1 Some of the earliest problems that were solved using Artificial Intelligence. . 9
1.2 Problems we are trying to solve using these days: . . . . . . . . . . . . . . . 11
2 Solving Problems with AI 13
2.1 Solving problems with artificial intelligence . . . . . . . . . . . . . . . . . . . 13
2.1.1 Searching Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.2 Constraint Satisfaction Problems (CSP) . . . . . . . . . . . . . . . . 14
2.1.3 Machine Learning Techniques . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Some keywords you will hear every now and then . . . . . . . . . . . . . . . 15
2.3 Properties of Task Environment . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Types of Agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.1 Learning Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5 Problem Formulation and choice of strategies . . . . . . . . . . . . . . . . . . 19
2.6 Steps of Problem Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.7 Examples of problem formulation . . . . . . . . . . . . . . . . . . . . . . . . 21
3 Informed Search Algorithms 25
3.1 Heruistic Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.1.1 Key Characteristics of Heuristics in Search Algorithms . . . . . . . . 26
3.1.2 Why do we use heuristics? . . . . . . . . . . . . . . . . . . . . . . . 27
3.2 Heuristic functions to solve different problems . . . . . . . . . . . . . . . . . 27
3.3 Greedy Best First Search- Finally an algorithm . . . . . . . . . . . . . . . . 31
3.3.1 Algorithm: Greedy Best-First Search . . . . . . . . . . . . . . . . . . 33
3.3.2 Key Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5
CONTENTS Artificial Intelligence
7
CHAPTER 1
INTRODUCTION: PAST, PRESENT,
FUTURE
AI research quickly pushed forward, especially in Bayesian networks and Markov Decision
Processes, which allowed machines to reason under uncertainty. Games also became a testing
ground for AI. In 1951, Turing designed a theoretical chess program, followed soon by Arthur
Samuel’s checkers program, one of the earliest examples of a machine that could learn from
experience—a major step towards machine learning.
AI wasn’t just about games, though. In 1956, The Logic Theorist program, created by Allen
Newell, Herbert Simon, and Cliff Shaw, was designed to mimic human reasoning, even prov-
ing mathematical theorems from Principia Mathematica. This breakthrough demonstrated
AI’s ability to solve complex logical tasks. Meanwhile, machine translation experiments,
like the Georgetown project in 1954, successfully converted Russian sentences into English,
showcasing AI’s potential for language processing.
Even early speech recognition made strides in this decade, with Bell Labs developing Audrey,
a system that recognized spoken numbers. These advancements in the 1950s laid a strong
foundation for AI’s growth.
9
Introduction: Past, present, future Artificial Intelligence
The 1970s saw AI face skepticism. Reports like the Lighthill Report highlighted AI’s limi-
tations, but this decade also saw graph theory grow in importance, allowing for knowledge
representation in early expert systems.
The 1980s brought significant advances with expert systems that made decisions using rule-
based logic, as well as the backpropagation algorithm, which greatly improved neural net-
works.
In the 1990s, AI reached new heights. IBM’s Deep Blue made history by defeating a world
chess champion, and statistical learning models like Support Vector Machines gained popu-
larity, leading to a data-driven approach in AI.
The 2000s introduced game theory for multi-agent systems, and deep learning brought re-
newed interest in neural networks for complex pattern recognition.
In the 2010s, AI achieved remarkable feats with IBM’s Watson and Google DeepMind’s Al-
phaGo, showcasing AI’s ability to understand language and excel in strategic games, demon-
strating the depth of AI’s problem-solving abilities.
Large Language Models (LLMs) like GPT and BERT are significant developments in natural
language processing. Starting with early neural network foundations in the 2000s, advance-
ments such as Word2Vec laid the groundwork for sophisticated word embeddings. The 2017
introduction of the Transformer architecture revolutionized NLP by efficiently handling long-
range dependencies in text.
In 2018, Google’s BERT and OpenAI’s GPT used the Transformer model to understand
and generate human-like text, with BERT improving context understanding through bidi-
rectional training, and GPT enhancing generative capabilities. Recent iterations like GPT-3
and GPT-4 have scaled up in size and performance, expanding their application range from
content generation to conversational AI.
Today, in the 2020s, AI is focusing on issues like fairness and bias and exploring the po-
tential of quantum computing to revolutionize the field even further.
Healthcare—
Disease Diagnosis: AI algorithms analyze medical imaging data to detect and
diagnose diseases early, such as cancer or neurological disorders.
Transportation—
Autonomous Vehicles: AI powers self-driving cars, aiming to reduce human error
in driving and increase road safety.
Finance—
Fraud Detection: AI systems analyze transaction patterns to identify and prevent
fraudulent activities in real time.
Retail—
Customer Personalization: AI enhances customer experience by providing person-
alized recommendations based on past purchases and browsing behaviors.
Education—
Adaptive Learning Platforms: AI tailors educational content to the learning styles
and pace of individual students, improving engagement and outcomes.
Case Prediction: AI analyzes past legal cases to predict outcomes and pro-
vide guidance on legal strategies.
Solving any problem first requires abstraction/problem formulation of the problem so that
the problem can be tackled using an algorithmic solution. Based on that abstraction we
choose a suitable strategy to solve the problem.
Real-world AI challenges are rarely straightforward. They often need to be broken down
into smaller parts, with each part solved using a different strategy. For example, in creating
an autonomous vehicle, informed search may help us find a route to destination, adversarial
search helps us predict other drivers’ actions, while machine learning helps the vehicle un-
derstand road signs.
Thankfully in this course, we’ll focus on learning each strategy separately. This approach
lets us dive deep into each area without worrying about combining them.
13
Solving Problems with AI Artificial Intelligence
Local Search
Why— Local search methods are crucial for tackling optimization problems where
finding an optimal solution might be too time-consuming. These methods, which in-
clude Simulated Annealing and Hill Climbing, are invaluable for tasks such as resource
allocation and scheduling where a near-optimal solution is often sufficient.
Adversarial search
Why—Adversarial search techniques are essential for environments where agents com-
pete against each other, such as in board games or market competitions. Understanding
strategies like Minimax and Alpha-Beta Pruning allows one to predict and counter op-
ponents’ moves effectively.
Decision Tree
Why—Decision trees are introduced due to their straightforward approach to solving
classification and regression problems. They split data into increasingly precise subsets
using simple decision rules, making them suitable for tasks from financial forecasting
to clinical decision support.
Gradient Descent
Why—The gradient descent algorithm is essential for optimizing machine learning
models, particularly in training deep neural networks. Its ability to minimize error
functions makes it indispensable for developing applications like voice recognition sys-
tems and personalized recommendation engines.
2.2 Some keywords you will hear every now and then
Agent: In AI, an agent is an entity that perceives its environment through sensors
and acts upon that environment using actuators. It operates within a framework of
objectives, using its perceptions to make decisions that influence its actions.
Rational Agent: A rational agent acts to achieve the best outcome or, when there is
uncertainty, the best expected outcome. It is "rational" in the sense that it maximizes
its performance measure, based on its perceived data from the environment and the
knowledge it has.
Task Environment: In AI, the environment refers to everything external to the agent
that it interacts with or perceives to make decisions and achieve its goals. It includes
all factors, conditions, and entities that can influence or be influenced by the agent’s
actions.
Partially Observable: Here, the agent only has partial information about the
environment due to limitations in sensor capabilities or because some information
is inherently hidden. Agents must often infer or guess the missing information to
make decisions.For instance, in a poker game, players cannot see the cards of their
opponents.
Episodic: The agent’s experience is divided into distinct episodes, where the
action in each episode does not affect the next. Each episode consists of the agent
perceiving and then performing a single action. An example is image classification
tasks where each image is processed independently.
Sequential: Actions have long-term consequences, and thus the current choice
affects all future decisions. Agents need to consider the overall potential future
outcomes when deciding their actions. Navigation tasks where an agent (like a robot or
self-driving car) must continuously make decisions based on past movements exemplify
this.
Static: The environment does not change while the agent is deliberating. This
simplicity allows the agent time to make a decision without worrying about the
environment moving on. An example is a Sudoku puzzle, where the grid waits inertly
as the player strategizes.
Dynamic: The environment can change while the agent is considering its ac-
tions. Agents need to adapt quickly and consider the timing of actions. For example,
in automated trading systems where market conditions can change in the midst of
computations.
Discrete: Possible states, actions, and outcomes are limited to a set of dis-
tinct, clearly defined values. For example, a chess game has a finite number of possible
moves and positions.
Cooperative: Agents work together towards a common goal, which may in-
volve communication and shared tasks. For example, a collaborative robotics setting
where multiple robots work together to assemble a product.
These agents act solely based on the current perception, ignoring the rest of the
perceptual history. They operate on a condition-action rule, meaning if a condition is
met, an action is taken.
Example: A room light that turns on when it detects motion. It does not re-
member past movements; it only responds if it detects motion currently.
These agents maintain some sort of internal state that depends on the percept
history, allowing them to make decisions in partially observable environments. They
use a model of the world to decide their actions.
Goal-Based Agents
These agents act to achieve goals. They consider future actions and evaluate
them based on whether they lead to the achievement of a set goal.
Example: A navigation system in a car that plans routes not only based on the
current location but also on the destination the user wants to reach.
Utility-Based Agents:
These agents aim to maximize their own perceived happiness or satisfaction, ex-
pressed as a utility function. They choose actions based on which outcome provides
the greatest benefit according to this utility.
Example: An investment bot that decides to buy or sell stocks based on an al-
gorithm designed to maximize the expected return on investment, weighing various
financial indicators and market conditions.
A self-driving car is a learning agent that adapts and improves its driving decisions based on
accumulated driving data and experiences.
Performance Element: This part of the agent controls the car, making real-time driving
decisions such as steering, accelerating, and braking based on current traffic conditions and
sensor inputs.
Learning Element: It processes the data gathered from various sensors and feedback from
the performance element to improve the decision-making algorithms. For example, it learns
to recognize stop signs better or understand the nuances of merging into heavy traffic.
Critic: It evaluates the driving decisions made by the performance element. For instance, if
a particular maneuver led to a near-miss, the critic would flag this as suboptimal.
Problem Generator: This might simulate challenging driving conditions that are not fre-
quently encountered, such as slippery roads or unexpected obstacles, to prepare the car for
a wider range of scenarios.
Over time, by learning from both successes and failures, a self-driving car improves its ca-
pability to drive safely and efficiently in complex traffic environments, demonstrating how
learning agents adapt and enhance their performance based on experience.
Figure 2.1: Initial and Goal State of a 8-Puzzle Game (Russel and Norvig, Artificial Intel-
ligence: A Modern Approach)
List out all possible actions that can be taken from any given state.
Example: In an online booking system, actions could include selecting dates, choosing
a room type, and adding guest information.
In a navigation problem, for example, these actions could be the different paths or
turns one can take at an intersection.
For a sorting algorithm, actions might be the comparisons or swaps between elements.
◦ Problem Formulation:
• Goal: To find the quickest route from a starting point (origin) to a destination
(end point) while considering current traffic conditions.
• States: Each state represents a geographic location within the city’s road
network.
• Initial State: The specific starting location of the vehicle.
• Actions: From any given state (location), the actions available are the set of
all possible roads that can be taken next.
• Transition Model: Moving from one location to another via a chosen road
or intersection.
◦ Problem Formulation:
• Goal: To optimize the power output while minimizing fuel usage and adhering
to safety regulations.
• States: Each state represents a specific configuration of the power plant’s
operational settings (e.g., temperature, pressure levels, valve positions).
• Initial State: The current operational settings of the plant.
• Actions: Adjustments to the operational settings such as increasing or de-
creasing temperature, adjusting pressure, and changing the mix of fuel used.
• Transition Model: Changing from one set of operational settings to another.
• Goal Test: A set of operational conditions that meet all efficiency, safety,
and regulatory requirements.
• Path Cost: Typically involves costs related to fuel consumption, wear and
tear on equipment, and potential safety risks. The cost function aims to
minimize these while maximizing output efficiency.
◦ Heuristic Used:
• Efficiency Metrics: Estimations of how changes in operational settings will
affect output efficiency and resource usage. This might include predictive
models based on past performance data.
◦ Problem Formulation:
• Goal: To assign time slots and rooms to university classes in a way that no
two classes that share students or instructors overlap, and all other constraints
are satisfied.
• States: Each state represents an assignment of classes to time slots and
rooms.
• Initial State: No courses are assigned to any time slots or rooms.
◦ Problem Formulation:
• Goal: To accurately diagnose diseases based on symptoms, patient history,
and test results.
• States: Each state represents a set of features associated with a patient,
including symptoms presented, medical history, demographic data, and results
from various medical tests.
• Initial State: The initial information gathered about the patient, which
includes all initial symptoms and available medical history.
• Actions: jActions are not typically modeled in decision trees as they are used
for classification rather than processes involving sequential decisions.
• Transition Model: Not applicable for decision trees since the process does
not involve moving between states.
• Goal Test: The diagnosis output by the decision tree, determining the most
likely disease or condition based on the input features.
• Path Cost: In decision trees, the cost is not typically measured in terms of
path, but accuracy, specificity, and sensitivity of the diagnosis can be consid-
ered as metrics for evaluating performance.
◦ Features Used:
• Symptoms: Patient-reported symptoms and observable signs.
• Test Results: Quantitative data from blood tests, imaging tests, etc.
Note: This lecture closely follows Chapter 3.6 (Heuristic Functions) and 3.5 (Informed
Search) to 3.5.1 (Greedy Best First Search) of Russel and Norvig, Artificial Intelligence: A
Modern Approach. The images are also borrowed from these chapters
As computer science students, you are already familiar with various search algorithms such as
Breadth-First Search, Depth-First Search, and Dijkstra’s/Best-First Search. These strategies
fall under the category of Uninformed Search or Blind Search, which means they rely solely
on the information provided in the problem definition.
25
Informed Search Algorithms Artificial Intelligence
For example, consider a map of Romania where we want to travel from Arad to Bucharest.
The map indicates that Arad is connected to Zerind by 75 miles, Sibiu by 140 miles, and
Timis, oara by 118 miles. Using a blind search strategy, the next action from Arad would be
chosen based solely on the distances to these connected cities. This approach can be slower
and less efficient as it may explore paths that are irrelevant to reaching the goal efficiently.
In this course, we will focus on informed search strategies, also known as heuristic search.
Informed Search uses additional information—referred to as heuristics—to make educated
guesses about the most promising direction to pursue in the search space. This approach
often results in faster and more efficient solutions because it avoids wasting time on less likely
paths. We will study Greedy Best-First Search and A* search extensively. But first, let’s
explore the concept of heuristics.
Estimation: A heuristic function estimates the cost to reach the goal from a current
node. This estimate does not need to be exact but should never overestimate.
Returning to the example of traveling to Bucharest from Arad: A heuristic function can
estimate the shortest distance from any city in Romania to the goal. For instance, we might
use the straight-line distance as a measure of the heuristic value for a city. The straight-
line distance from Arad to Bucharest is 366 miles, although the optimal path from Arad to
Bucharest actually spans 418 miles. Therefore, the heuristic value for Arad is 366 miles. For
each node (in this problem, city) in the state space (in this problem, the map of Romania) the
heuristic value will be their straight line distance from the goal state (in this case Bucharest).
Guidance: The heuristic guides the search process, helping the algorithm prioritize
which nodes to explore next based on which seem most promising—i.e., likely to lead
to the goal with the least cost.
Efficiency: By providing a way to estimate the distance to the goal, heuristics can
significantly speed up the search process, as they allow the algorithm to focus on more
promising paths and potentially disregard paths that are unlikely to be efficient.
8-Puzzle Game
The number of misplaced tiles (blank not included): For the figure above, all
eight tiles are out of position, so the start state has h1 = 8.
The sum of the distances of the tiles from their goal positions: Be-
cause tiles cannot move along diagonals, the distance is the sum of the horizontal and
vertical distances- sometimes called the city-block distance or Manhattan distance.
Figure 3.1: Initial and Goal State of a 8-Puzzle Game (Russel and Norvig, Artificial Intel-
ligence: A Modern Approach)
Travel Time: Estimating the time needed to reach the goal based on average
speeds and road types. t = vd where d is the distance and v is the average speed.
Traffic Patterns: Using historical or real-time traffic data to estimate the fastest
route. Could involve a weighting factor, w based on traffic data, modifying the travel
time: tadjusted = t × w .
Material Count: Sum of the values of all pieces. For example, in chess, pawns = 1,
knights/bishops = 3, rooks = 5, queen = 9.
Page Rank: Evaluating the number and quality of inbound links to estimate
the page’s importance.
Domain Authority: The reputation and reliability of the website hosting the
information. Often a proprietary metric, but generally a combination of factors like
link profile, site age, traffic, etc.
Let us see how this works for route-finding problems in Romania; we use the straight-
line-distance heuristic, which we will call hSLD . If the goal is Bucharest, we need to know
the straight-line distances to Bucharest, which are shown in the figure below. For example,
hSLD (Arad) = 366. Notice that the values of hSLD cannot be computed from the problem
description itself (that is, the ACTIONS and RESULT functions). Moreover, it takes a certain
amount of world knowledge to know that hSLD is correlated with actual road distances and
is, therefore, a useful heuristic.
The next figure shows the progress of a greedy best-first search using hSLD to find a path
from Arad to Bucharest. The first node to be expanded from Arad will be Sibiu because the
heuristic says it is closer to Bucharest than is either Zerind or Timisoara. The next node to
be expanded will be Fagaras because it is now closest according to the heuristic. Fagaras in
turn generates Bucharest, which is the goal. For this particular problem, greedy best-first
search using hSLD finds a solution without ever expanding a node that is not on the solution
path. The solution it found does not have optimal cost, however: the path via Sibiu and
Fagaras to Bucharest is 32 miles longer than the path through Rimnicu Vilcea and Pitesti.
This is why the algorithm is called “greedy”—on each iteration it tries to get as close to a
goal as it can, but greediness can lead to worse results than being careful.
Greedy best-first graph search is complete in finite state spaces, but not in infinite ones. The
worst-case time and space complexity is O(| V |). With a good heuristic function, however,
the complexity can be reduced substantially, on certain problems reaching O(bm).
◦ Output:
◦ Procedure
• Initialize:
□ Create a priority queue and insert the start node along with its heuristic value
heuristic(start).
□ Define a visited set to keep track of all visited nodes to avoid cycles and
redundant paths.
• Search:
□ While the priority queue is not empty:
∗ Remove the node current with the lowest heuristic value from the pri-
ority queue.
∗ If current is the goal, return the path that led to current.
∗ Add current to the visited set.
∗ For each neighbor n of current:
. If n is not in visited:
– Calculate the heuristic value heuristic(n).
– Add n to the priority queue with the priority set to heuristic(n).
• Failure to find the goal:
□ If the priority queue is exhausted without finding the goal, return None.
Completeness and Optimality: Greedy Best-First Search does not guarantee that
the shortest path will be found, making it neither complete nor optimal. It can get
stuck in loops or dead ends if not careful with the management of the visited set.
Data Structures: The algorithm typically uses a priority queue for the frontier and
a set for the visited nodes. This setup helps in efficiently managing the nodes during
the search process.
Greedy Best-First Search is particularly useful when the path’s exact length is less
important than quickly finding a path that is reasonably close to the shortest possible.
It is well-suited for problems where a good heuristic is available.