AI Unit 1
AI Unit 1
AI is a branch of computer science that enables machines to perform tasks that usually require human
intelligence, such as learning, reasoning, problem-solving, understanding language, and recognizing images
Artificial Intelligence refers to the simulation of human intelligence in machines that are programmed to
think, reason, and learn like humans. Rather than being explicitly programmed for specific tasks,
AI(Artificial Intelligence) systems use algorithms and vast amounts of data to recognize patterns, make
decisions, and improve their performance over time.
Artificial Intelligence encompasses a wide range of technologies, including machine learning, natural
language processing, computer vision, and robotics. These technologies enable AI systems to perform
complex tasks, such as speech recognition and face detection, with remarkable accuracy.
For example:
A voice assistant like Alexa or Siri understands your voice and answers your questions.
A self-driving car can drive without a human driver.
A spam filter removes unwanted emails automatically.
study of AI also involves other disciplines including Psychology, Philosophy, Science, etc.
Input: Data is collected from various sources. This data is then sorted into categories.
Processing: The AI sorts and deciphers the data using patterns it has been programmed to learn until it
recognizes similar patterns in the data.
Adjustments: If the data sets are considered a “fail,” AI learns from that mistake, and the process is
repeated again under different conditions.
Learning and Adapting (Machine Learning - ML):AI can improve its performance over time by learning from
data (e.g., Netflix recommendations, spam filters).
Reasoning and Problem-Solving (Automated Reasoning):AI can analyze information and make decisions
(e.g., Google Maps finding the best route).
Recognizing Patterns (Computer Vision):AI can identify images and objects (e.g., face recognition in
phones).
Physical Interaction (Robotics):AI-powered robots can interact with the physical world (e.g., self-driving
cars, robotic vacuum cleaners).
Thinking Humanly (Cognitive Modeling Approach):AI is designed to think and solve problems like humans,
based on psychology and neuroscience.
Thinking Rationally (Laws of Thought Approach):AI follows logical rules to always make the best possible
decision.
Acting Rationally (Rational Agent Approach):AI makes the best possible decision in a given situation, even
under uncertainty (e.g., self-driving cars making real-time decisions).
Agents can be classified into different types based on their characteristics, such as whether they are reactive or
proactive, whether they have a fixed or dynamic environment, and whether they are single or multi-agent
systems.
Reactive agents are those that respond to immediate stimuli from their environment and take actions
based on those stimuli. Proactive agents, on the other hand, take initiative and plan ahead to achieve their
goals. The environment in which an agent operates can also be fixed or dynamic. Fixed environments have
a static set of rules that do not change, while dynamic environments are constantly changing and require
agents to adapt to new situations.
Multi-agent systems involve multiple agents working together to achieve a common goal. These agents
may have to coordinate their actions and communicate with each other to achieve their objectives. Agents
are used in a variety of applications, including robotics, gaming, and intelligent systems. They can be
implemented using different programming languages and techniques, including machine learning and
natural language processing.
Artificial intelligence is defined as the study of rational agents. A rational agent could be anything that makes
decisions, such as a person, firm, machine, or software. It carries out an action with the best outcome after
considering past and current percepts(agent’s perceptual inputs at a given instance). An AI system is composed
of an agent and its environment. The agents act in their environment. The environment may contain other
agents.
Types of Agents
Simple Reflex Agents: Simple reflex agents make decisions based only on the current situation, ignoring past
experiences. They follow condition-action rules, means perform an action if a certain condition is met. This
works well only in fully observable environments (where all necessary information is available at moment).
How the world changes on its own – Understanding natural changes in the environment.
How the agent’s actions impact the world – Knowing the effects of its decisions.
Goal-Based Agents:Goal-based agents make decisions by focusing on their goal (a desired outcome). They
choose actions that bring them closer to the goal, helping them pick the best option among many. Since their
decision-making process is explicit and adjustable, they are more flexible than simple reflex agents. These
agents rely on search and planning, making it easy to change their behavior when needed.
Utility-Based Agents:They are designed to make the best choice when multiple options are available. They
don’t just focus on reaching a goal but consider factors like speed, safety, & cost to make better decisions.They
use a utility function, which measures how "happy" an agent is in a given situation. Since the world is uncertain,
they choose actions that maximize their expected happiness (utility), ensuring the best outcome.
Learning Agent: A learning agent can learn from experience and improve its performance over time. It starts
with basic knowledge and adapts automatically as it learns.
1. Learning Element – Improves the agent’s performance by learning from the environment.
2. Critic – Gives feedback on how well the agent is performing based on a fixed standard.
3. Performance Element – Chooses the agent’s actions.
4. Problem Generator – Suggests new actions to help the agent gain useful experiences.
Multi-Agent Systems: Multi-Agent Systems (MAS) consist of multiple agents that work together to achieve a
common goal. These agents can be autonomous or semi-autonomous, meaning they make decisions and take
actions based on their environment.
Homogeneous MAS – All agents have the same abilities and goals.
Heterogeneous MAS – Agents have different abilities and goals, making coordination harder but
increasing flexibility.
Cooperative MAS – Agents work together toward a shared goal.
Competitive MAS – Agents compete to achieve their own goals.
Mixed MAS – A mix of cooperation and competition.
Hierarchical Agents:Hierarchical agents are structured in levels, where high-level agents set goals and rules,
and low-level agents perform specific tasks. This setup is useful for managing complex tasks efficiently.
High-level agents decide goals and constraints based on the system’s overall objective.
Low-level agents carry out specific tasks to achieve those goals.
Intermediate-level agents (if present) help coordinate lower-level agents in complex systems.
Nature of environment:
An environment in artificial intelligence is the surrounding of the agent. The agent takes input from the
environment through sensors and delivers the output to the environment through actuators.
When designing an agent, the first step is to clearly define its task environment, which consists of:
To make it easy to remember, this is called the PEAS (Performance, Environment, Actuators, Sensors)
2. Deterministic vs Stochastic
When a uniqueness in the agent’s current state completely determines the next state of the agent, the
environment is said to be deterministic.
The stochastic environment is random in nature which is not unique and cannot be completely
determined by the agent.
Examples:
Chess – there would be only a few possible moves for a chess piece at the current state and these
moves can be determined.
Self-Driving Cars- the actions of a self-driving car are not unique, it varies time to time.
3. Competitive vs Collaborative
An agent is said to be in a competitive environment when it competes against another agent to optimize
the output.
The game of chess is competitive as the agents compete with each other to win the game which is the
output.
An agent is said to be in a collaborative environment when multiple agents cooperate to produce the
desired output.
When multiple self-driving cars are found on the roads, they cooperate with each other to avoid
collisions and reach their destination which is the output desired.
4. Single-agent vs Multi-agent
An environment consisting of only one agent is said to be a single-agent environment.
A person left alone in a maze is an example of the single-agent system.
An environment involving more than one agent is a multi-agent environment.
The game of football is multi-agent as it involves 11 players in each team.
5. Dynamic vs Static
An environment that keeps constantly changing itself when the agent is up with some action is said to be
dynamic.
A roller coaster ride is dynamic as it is set in motion and the environment keeps changing every instant.
An idle environment with no change in its state is called a static environment.
An empty house is static as there’s no change in the surroundings when an agent enters.
6. Discrete vs Continuous
If an environment consists of a finite number of actions that can be deliberated in the environment to
obtain the output, it is said to be a discrete environment.
The game of chess is discrete as it has only a finite number of moves. The number of moves might vary
with every game, but still, it’s finite.
The environment in which the actions are performed cannot be numbered i.e. is not discrete, is said to
be continuous.
Self-driving cars are an example of continuous environments as their actions are driving, parking, etc.
which cannot be numbered.
7.Episodic vs Sequential
In an Episodic task environment, each of the agent’s actions is divided into atomic incidents or episodes.
There is no dependency between current and previous incidents. In each incident, an agent receives
input from the environment and then performs the corresponding action.
Example: Consider an example of Pick and Place robot, which is used to detect defective parts from the
conveyor belts. Here, every time robot(agent) will make the decision on the current part i.e. there is no
dependency between current and previous decisions.
In a Sequential environment, the previous decisions can affect all future decisions. The next action of the
agent depends on what action he has taken previously and what action he is supposed to take in the
future.
Example: Checkers- Where the previous move can affect all the following moves.
8. Known vs Unknown
In a known environment, the output for all probable actions is given. Obviously, in case of unknown
environment, for an agent to make a decision, it has to gain knowledge about how the environment works.
Environment Considerations:
This assumes a simple environment with these properties:
✔ Single-agent (only one decision-maker)
✔ Fully observable (agent has complete knowledge of the state)
✔ Deterministic (actions have predictable results)
✔ Static (environment does not change over time)
✔ Discrete (limited number of states and actions)
✔ Known (agent has information about the world)
1. Ignorable Problems: These are problems or errors that have minimal or no impact on the overall
performance of the AI system. They are minor and can be safely ignored
2. Recoverable Problems: Those problems where the AI system encounters an issue, but it can recover from
the error, either through manual intervention or built-in mechanisms, such as error-handling functions.
3. Irrecoverable Problems: These are critical problems that lead to permanent failure or incorrect outcomes
in AI systems. Once encountered, the system cannot recover
Problem Definition: This initial step involves clearly specifying the inputs and acceptable solutions for the
system. A well-defined problem lays the groundwork for effective analysis and resolution.
Problem Analysis: In this step, the problem is thoroughly examined to understand its components,
constraints, and implications. This analysis is crucial for identifying viable solutions.
Knowledge Representation: This involves gathering detailed information about the problem and defining
all potential techniques that can be applied. Knowledge representation is essential for understanding the
problem’s context and available resources.
Problem Solving: The selection of the best techniques to address the problem is made in this step. It
often involves comparing various algorithms and approaches to determine the most effective method.
State Space - All possible situations the agent can be in. It refers to the area where an agent involved in
problem-solving process can examine all the possible states with the hope of discovering a solution.
State: An entity represents some unique and specific arrangement of elements in a problem-solving
situation
Search Algorithm: A search algorithm describes any process or method targeted for examining and
exploring the given problem space to find a solution.
Heuristic: Heuristic is a thumb rule or guiding principle that is used to make intelligent decisions or solve
the problems that are encountered during the process.
Initial State - The agent's starting point (e.g., Arad).
Goal State(s) - The destination(s) (e.g., Bucharest).
Actions - Possible moves (e.g., travel from Arad to Sibiu).
Transition Model - The result of an action (e.g., traveling from Arad to Zerind leads to the Zerind state).
Action Cost Function - The cost of each action (e.g., distance in miles).
Solution - A sequence of actions leading to a goal (e.g., Arad → Sibiu → Bucharest).
Optimal Solution - The solution with the lowest cost (shortest distance or least time).
Characteristics of AI Problems:
Challenges of AI:
Ethical Challenges in AI
Bias in AI
If the data used to train AI is biased, the AI will also be biased. This can lead to unfair decisions.
Example: An AI trained mostly on male leaders may prefer men for leadership roles.
Lack of Transparency and Accountability
Many AI systems are like “black boxes”—it’s hard to know how they make decisions.
Example: If an AI denies parole to a prisoner, the reason may not be clear, making it hard to challenge the
decision.
Misuse of AI
AI can be used in harmful ways, like spreading fake videos or hacking.
Example: Deepfakes can be used to spread false information or create fake news videos.
Job Losses
AI can do many tasks automatically, which might replace human workers.
Example: Robots in factories can reduce the need for human workers on assembly lines.
Increasing Inequality
Only rich companies might be able to afford advanced AI, increasing the gap between rich and poor.
Example: Big companies may use AI to make more money, while small companies can’t keep up.
Need for Regulations
There should be rules to make sure AI is used safely and fairly.
Example: Laws should control how AI is used in facial recognition to protect people’s privacy
State Space Search is a method used in AI to find solutions by exploring all possible situations (states) of a
problem step-by-step until the goal is reached.It consider the problem as a series of steps and it moves from
one state to another until goal is reached.
Used In
Term Meaning
State A condition or configuration of the problem
Initial State Starting point
Goal State Desired final result
Transition Action to move from one state to another
Path Sequence of states from start to goal
Search Strategy The method used to search the path
Strategy Description
BFS (Breadth-First Search) Explores level by level – guarantees shortest path in unweighted graphs
DFS (Depth-First Search) Goes deep into one path before backtracking – uses less memory
UCS (Uniform Cost Search) Picks the least cost node first – gives cheapest path
Greedy Search Uses a heuristic to pick the node closest to goal
A* Combines cost and heuristic – complete and optimal
Goal is reached
All possibilities are checked
Feature Explanation
Expansiveness How many new states one state can generate
Branching Factor Average number of child nodes per state
Depth Steps needed to reach goal from the start
Completeness Will it always find a solution if one exists?
Optimality Will it find the best (cheapest/shortest) solution?
Time Complexity How much time the search takes
Space Complexity How much memory is needed
Unit 2
Adversarial search:
The Adversarial search is a well-suited approach in a competitive environment, where two or more agents
have conflicting goals. The adversarial search can be employed in two-player zero-sum games which means
what is good for one player will be the misfortune for the other. In such a case, there is no win-win outcome.
In artificial intelligence, adversarial search plays a vital role in decision-making, particularly in competitive
environments associated with games and strategic interactions. By employing adversarial search, AI agents
can make optimal decisions while anticipating the actions of an opponent with their opposing objectives. It
aims to establish an effective decision for a player by considering the possible moves and the counter-moves
of the opponents.
The adversarial search in competitive environments can be utilized in the below scenarios where the AI
system can assist in determining the best course of action by both considering the possible moves and
counter-moves of the opponents.
Each agent seeks to boost their utility or minimize their loss.
One agent’s action impacts the outcomes and objectives of the other agents.
Additionally, strategic uncertainty arises when the agents may lack sufficient information about each
other’s strategies.
Game-playing: The Adversarial search finds a significant application in game-playing scenarios, including
renowned games like chess, Go, and poker. The adversarial search offers the simplified nature of these
games that represents the state of a game in a straightforward approach and the agents are limited to a
small number of actions whose effects are governed by precise rules.
Decision-making: Decision-making plays a central role in adversarial search algorithms, where the goal is
to find the best possible move or strategy for a player in a competitive environment against one or more
components. This requires strategic thinking, evaluation of potential outcomes, and adaptive decision-
making throughout the game.
Adversarial Search is a type of search used in games or problems involving competition between two or more
players, where each player tries to win and the opponent tries to stop them.
In normal search (like path finding), we only try to reach a goal state.
But in games:
The game tree for the game is defined by the beginning state, ACTIONS function, and RESULT function—a
tree in which the nodes are game states and the edges represent movements. The figure below depicts a
portion of the tic-tac-toe game tree (noughts and crosses). MAX may make nine different maneuvers from his
starting position. The game alternates between MAXs setting an X and MINs placing an O until we reach leaf
nodes corresponding to terminal states, such as one player having three in a row or all of the squares being
filled. The utility value of the terminal state from the perspective of MAX is shown by the number on each
leaf node; high values are thought to be beneficial for MAX and bad for MIN
The game tree for tic-tac-toe is relatively short, with just 9! = 362,880 terminal nodes. However, because
there are over 1040 nodes in chess, the game tree is better viewed as a theoretical construct that cannot be
realized in the actual world. But, no matter how big the game tree is, MAX's goal is to find a solid move. A
tree that is superimposed on the whole game tree and examines enough nodes to allow a player to identify
what move to make is referred to as a search tree.
A sequence of actions leading to a goal state—a terminal state that is a win—would be the best solution in a
typical search problem. MIN has something to say about it in an adversarial search. MAX must therefore
devise a contingent strategy that specifies M A X's initial state move, then MAX's movements in the states
resulting from every conceivable MIN response, then MAX's moves in the states resulting from every possible
MIN reaction to those moves, and so on. This is quite similar to the AND-OR search method, with MAX acting
as OR and MIN acting as AND. When playing an infallible opponent, an optimal strategy produces results that
are as least as excellent as any other plan. We'll start by demonstrating how to find the best plan.
We'll move to the trivial game in the figure below since even a simple game like tic-tac-toe is too complex for
us to draw the full game tree on one page. MAX's root node moves are designated by the letters a1, a2, and
a3. MIN's probable answers to a1 are b1, b2, b3, and so on. This game is over after MAX and MIN each make
one move. (In game terms, this tree consists of two half-moves and is one move deep, each of which is
referred to as a ply.) The terminal states in this game have utility values ranging from 2 to 14.
The optimal strategy can be found from the minimax value of each node, which we express as MINIMAX,
given a game tree (n). Assuming that both players play optimally from there through the finish of the game,
the utility (for MAX) of being in the corresponding state is the node's minimax value. The usefulness of a
terminal state is obviously its minimax value. Furthermore, if given the option, MAX prefers to shift to a
maximum value state, whereas MIN wants to move to a minimum value state. So here's what we've got:
Optimal decision making in games means choosing the best possible move at every step, assuming your
opponent also plays perfectly. It aims to maximize your chances of winning or minimize losses.
Where is it used?
It is used in Game Theory and Artificial Intelligence to develop intelligent agents that can play games like chess,
tic-tac-toe, etc.
Minimax Algorithm:
Alpha-Beta Pruning:
Disadvantages:
Stochastic games:
A stochastic game is a type of game where multiple players make decisions over time, and those decisions affect
not only the current situation (called the state) but also what happens next. The word "stochastic" means there’s
some randomness involved—so it's not just skill or logic, but also luck.
Key Elements:
States (S): These are like different scenes or situations in the game.
Actions (A): Choices each player can make.
Transition Probabilities (P): These decide how the game moves from one state to another. It’s not always
certain—random events (like dice rolls) influence it.
Reward Function (R): Based on the state and action, each player gets a reward (or points).
Discount Factor (γ): This tells us how much future rewards matter. A low value means “care more about
now,” and a high value means “care more about the future.”
Real-World Example: Think of playing a board game where you roll a dice (randomness), decide how to move
your pieces (decision-making), and earn or lose points depending on your moves and luck.
Multi-Agent Systems: AI systems often involve more than one “agent” (like self-driving cars or robots) that
need to cooperate or compete. Stochastic games help model how these agents interact.
Uncertainty: Real-life isn’t always predictable. These games help AI learn to deal with randomness.
Sequential Decisions: Many AI tasks require decisions that affect the future. Stochastic games help in
planning ahead.
Reinforcement Learning (RL): This is a way for AI to learn by trial and error. RL is based on Markov
Decision Processes (a special kind of stochastic game), and multi-agent RL extends it to more than one
player.
Zero-Sum Games: One player's gain is exactly the other’s loss (e.g., chess or a two-player war game).
General-Sum Games: Players may cooperate or compete, and rewards aren't balanced (used in negotiation or
teamwork AI).
Markov Games: These follow the “Markov Property,” meaning the next state depends only on the current
state and actions, not on past history.
Solving a game means finding the best strategy for each player. This is tough when there are many players or
states.
Backgammon is a classic board game involving dice rolls. It’s part-skill and part-luck, making it a great example
of a stochastic game.
How it works:
In chess, a game tree shows all possible moves. In backgammon, we use a stochastic game tree, which includes:
Since outcomes are random, we can’t always know what’s best. Instead, we calculate the expected value for each
option—how good the outcome is on average.
Expectiminimax Algorithm
This is an upgrade of the Minimax algorithm for games that include chance.
How it works:
If it’s your turn (MAX): choose the action that gives the highest expected value.
If it’s the opponent’s turn (MIN): assume they’ll make the move that hurts you the most.
If it’s a chance node (CHANCE): take the weighted average of all outcomes based on their probabilities.
Expectiminimax(s) =
If it’s the end → Return the final score
If MAX’s turn → Pick the action that gives the max value
If MIN’s turn → Pick the action that gives the min value
If CHANCE’s turn → Calculate expected value = ∑ probability × value of resulting state
Autonomous Systems (e.g., robots or self-driving cars): They operate in unpredictable environments and
must make smart decisions.
Financial Markets: Traders and AI bots make decisions under uncertain market conditions.
Healthcare: Doctors, patients, and insurers are all agents making decisions under uncertainty.
Cybersecurity: AI models defend against attacks that are unpredictable or random.