AI Notes
AI Notes
Concept of AI
Definition: Artificial Intelligence (AI) is when machines or computers are designed to
think and act like humans. This means they can learn, solve problems, make decisions, or
even understand language.
Advantages of AI:
Disadvantages of AI:
Types:
Narrow AI: Built for one task, like translating languages or playing chess; it’s fast
and focused but can’t adapt beyond its job.
General AI: Aims to think like a human across any task, such as solving problems or
learning new skills; it’s flexible but doesn’t fully exist yet.
Example: Doesn’t fully exist yet, but think of a robot that can cook, drive, and write
music.
Advantage: Super flexible and smart.
Disadvantage: Hard to create, might be unpredictable
Super AI: Imagined as smarter than humans in everything, from creativity to science;
it could revolutionize the world but raises control and safety fears.
1|Page
History of AI
1. 1950s – Early Beginnings: Alan Turing proposed the "Turing Test" to evaluate a
machine’s ability to think.
2. 1956 – Birth of AI: The Dartmouth Conference introduced the term "Artificial
Intelligence."
3. 1960s-70s – Growth and Challenges: Early AI programs solved algebra, played
chess, and proved theorems but faced limitations due to hardware.
4. 1980s – Expert Systems: AI research saw success with expert systems used in
medicine and industry.
5. 1990s – Machine Learning: AI shifted towards data-driven learning approaches.
6. 2000s-Present – Deep Learning & Modern AI: AI powers self-driving cars, voice
assistants, and recommendation systems.
Current Status of AI
AI in Everyday Life: Chatbots, voice assistants (Siri, Alexa), and recommendation
systems (Netflix, YouTube).
AI in Industries: Healthcare (disease detection), Finance (fraud detection), and
Automation (robotic process automation).
Advanced AI: Deep learning, computer vision, and natural language processing
(NLP).
Advantages:
Disadvantages:
Scope of AI
Healthcare: AI-based diagnosis, robotic surgery.
Finance: AI-powered fraud detection, automated trading.
2|Page
Disadvantages:
Needs lots of money, data, and skilled people.
Agents:
Definition: An AI agent is something (software or robot) that senses its surroundings and
takes actions to achieve a goal.
Types of AI Agents
1. Simple Reflex Agents: Act only based on current conditions (e.g., thermostat).
2. Model-Based Reflex Agents: Use memory to make decisions (e.g., self-driving cars).
3. Goal-Based Agents: Act to achieve specific goals (e.g., chess-playing AI).
4. Utility-Based Agents: Choose actions based on maximizing overall benefit (e.g.,
recommendation systems).
5. Learning Agents: Improve over time using experience (e.g., AI chatbots).
Advantages & Disadvantages of AI Agents
Advantages:
Automation of tasks
Faster decision-making
Reduction of human error
Disadvantages:
High cost
Lack of common sense
Ethical concerns
Types of AI Environments
1. Fully Observable vs. Partially Observable: Whether the agent has complete or
partial data.
2. Deterministic vs. Stochastic: Whether the environment follows fixed rules or
includes randomness.
3. Static vs. Dynamic: Whether the environment changes over time.
3|Page
4. Discrete vs. Continuous: Whether the environment consists of distinct steps or a
continuous range.
5. Single-Agent vs. Multi-Agent: Whether one or multiple agents interact.
Advantages & Disadvantages of AI Environments
Advantages:
Problem Formulation in AI
AI problem formulation involves defining a problem clearly so that an AI agent can solve it.
Components of Problem Formulation
1. Initial State: Starting point of the problem.
2. Actions: Possible moves AI can take.
4|Page
1. Binary Tree: Each node has up to two children.
2. Binary Search Tree (BST): Sorted binary tree for fast searching.
3. Decision Tree: Used in AI for decision-making.
Types of Graphs
1. Directed Graph: Edges have direction.
2. Undirected Graph: Edges have no direction.
3. Weighted Graph: Edges have weights (costs).
Advantages & Disadvantages of Graphs
Advantages:
Represents complex relationships.
Useful for AI pathfinding.
Disadvantages:
Requires significant memory.
Algorithms can be computationally expensive.
5|Page
State Space Representation
State space is the collection of all possible states a problem can have.
Components of State Space Representation
6|Page
Some searches may lead to infinite loops.
Unit 02: Search Algorithms Random search, Search with closed and
open list, Depth first and Breadth first search, Heuristic search, Best
first search, A* algorithm, Game Search.
Solution:
1. Random Search
Definition
Random search is an uninformed search algorithm that explores possible solutions
randomly without using any prior knowledge. It does not follow a specific strategy or
heuristic, making it inefficient for large problem spaces.
Example
Imagine a robot in a maze that moves randomly in different directions until it finds the exit.
It does not remember where it has been before.
Advantages Disadvantages
Can sometimes find solutions by Does not guarantee an optimal or even a valid
chance solution
Example
In A search*, the open list contains paths that are still being explored, while the closed list
keeps track of paths that have already been checked.
7|Page
Advantages & Disadvantages
Advantages Disadvantages
Ensures completeness and correctness Not always the best approach for simple problems
Definition
DFS explores the deepest possible nodes first before backtracking when no further moves
are possible. It uses a stack (LIFO - Last In, First Out) for storing nodes.
Example
Consider a file system where you explore the deepest folder first before coming back up.
Advantages & Disadvantages
Advantages Disadvantages
Requires less memory than BFS May get stuck in infinite loops if cycles exist
Can find solutions quickly in deep search spaces Does not guarantee the shortest path
Useful for solving puzzles like mazes Inefficient for wide search spaces
Advantages Disadvantages
Guarantees the shortest path in an unweighted graph Requires more memory than DFS
8|Page
Advantages Disadvantages
Always finds a solution if one exists Can be slow in deep search spaces
Useful for applications like web crawling Not efficient for very large graphs
5. Heuristic Search
Definition
Heuristic search uses domain-specific knowledge (heuristics) to estimate which paths are
most promising, improving search efficiency.
Example
In a GPS navigation system, the straight-line distance to the destination is used as a
heuristic to guide the search.
Advantages & Disadvantages
Advantages Disadvantages
Faster than uninformed searches May not always find the best path
6. Best-First Search
Definition
This algorithm expands the most promising node first based on a heuristic function. It uses a
priority queue to always explore the best candidate next.
Example
Google Maps prioritizing highways over smaller roads when suggesting a route.
Advantages & Disadvantages
Advantages Disadvantages
Faster than blind searches May not always find the optimal solution
9|Page
Advantages Disadvantages
7. A Algorithm*
Definition
A* is an informed search algorithm that combines BFS and Best-First Search. It uses the
formula:
f(n)=g(n)+h(n)f(n) = g(n) + h(n)f(n)=g(n)+h(n)
where:
g(n)g(n)g(n) is the cost from the start node to node nnn.
h(n)h(n)h(n) is the estimated cost from node nnn to the goal.
Example
Finding the shortest route in a GPS navigation system, considering both distance traveled
and estimated remaining distance.
Advantages & Disadvantages
Advantages Disadvantages
Guarantees the shortest path if h(n)h(n)h(n) is Requires more computation than simpler
admissible searches
8. Game Search
Definition
Game search algorithms are used in AI to find optimal strategies in competitive
environments like chess or tic-tac-toe. These algorithms simulate possible moves and
counter-moves.
Example
The Minimax Algorithm evaluates all possible moves for both players and selects the best
one. Alpha-Beta Pruning optimizes this process by ignoring unnecessary calculations.
Advantages & Disadvantages
10 | P a g e
Advantages Disadvantages
11 | P a g e
UNIT 3: Probabilistic Reasoning
Probability, conditional probability, Bayes Rule, Bayesian Networks-
representation, construction and inference, temporal model,
hidden Markov model.
Solution:
1. Probability
Definition
Types
Classical Probability: Assumes equally likely outcomes. For example, the probability
of rolling a 3 on a fair six-sided die is 16\frac{1}{6}61.
Empirical Probability: Based on observed data. For instance, if it rained 30 out of 100
days, the empirical probability of rain on any given day is 0.3.
Subjective Probability: Based on personal judgment or belief. For example,
estimating a 70% chance of a project’s success based on expert opinion.
Advantages
Provides a structured approach to quantify uncertainty.
Facilitates decision-making under uncertainty.
Example
In a deck of 52 cards, the probability of drawing an Ace is 452=113\frac{4}{52} =
\frac{1}{13}524=131.
2. Conditional Probability
Definition
12 | P a g e
Conditional Probability is the probability of an event occurring given that another event has
already occurred. It is denoted as P(A∣B)P(A|B)P(A∣B), representing the probability of event
A occurring given that event B has occurred.
Mathematically:
P(A∣B)=P(A∩B)P(B)P(A|B) = \frac{P(A \cap B)}{P(B)}P(A∣B)=P(B)P(A∩B)
Advantages
Disadvantages
Requires prior probabilities, which may be subjective.
Computationally intensive for complex models.
13 | P a g e
Example
In medical diagnostics, Bayes' Rule helps calculate the probability of a disease given a
positive test result, considering the test's accuracy and the disease's prevalence.
For a comprehensive understanding, see GFG's article on Bayes' Theorem.
4. Bayesian Networks
Definition
Bayesian Networks are graphical models that represent probabilistic relationships among a
set of variables. They consist of nodes (variables) and directed edges (dependencies),
forming a Directed Acyclic Graph (DAG).
Representation
Each node is associated with a Conditional Probability Table (CPT) that quantifies the effect
of the parent nodes. The joint probability distribution is factored into these conditional
probabilities.
Construction
1. Identify Variables: Determine relevant variables for the domain.
2. Establish Dependencies: Define directed edges based on causal or influential
relationships.
3. Assign Probabilities: Populate CPTs with appropriate conditional probabilities.
Inference
Inference involves computing the posterior probabilities of certain variables given observed
evidence. Techniques include:
Exact Inference: Methods like Variable Elimination and Belief Propagation.
Approximate Inference: Methods like Monte Carlo simulations.
Advantages
Compact representation of joint probability distributions.
14 | P a g e
In a medical diagnosis system, a Bayesian Network can represent diseases and symptoms,
where edges denote the influence of diseases on symptoms. Given observed symptoms, the
network can infer the probabilities of various diseases.
For more information, refer to GFG's articles on Understanding Bayesian Networks and Exact
Inference in Bayesian Networks.
5. Temporal Models
Definition
Temporal Models represent systems that evolve over time, capturing temporal
dependencies between variables. They are essential for modeling time-series data and
sequential processes.
Types
State-Space Models: Represent systems with hidden states evolving over time,
observed through noisy measurements.
Hidden Markov Models (HMMs): A specific type of state-space model with discrete
hidden states and observable outputs.
Advantages
Capture temporal dynamics and dependencies.
Useful for forecasting and sequential decision-making.
Applicable in various domains, including finance and speech recognition.
Disadvantages
15 | P a g e
States: Hidden conditions of the system.
Observations: Visible outputs influenced by hidden states.
Transition Probabilities: Probabilities of moving between states.
Disadvantages
Assumes the Markov property, which may not always hold.
Requires large datasets for accurate parameter estimation.
Computationally intensive for large state spaces.
Example
16 | P a g e
Reward Function (R): Immediate reward received after transitioning from one state
to another due to an action.
The goal in an MDP is to find a policy (a mapping from states to actions) that maximizes the
expected sum of rewards over time.
For a detailed explanation, refer to GFG's article on Markov Decision Process.
Advantages
Advantages
Quantitative Decision-Making: Provides a numerical basis for comparing and making
decisions between different outcomes.
Captures Preferences: Effectively models the preferences and risk attitudes of
agents.
Disadvantages
17 | P a g e
Subjectivity: Utility assignments can be subjective and vary between individuals.
Simplification: May oversimplify complex preferences and ignore factors like
emotions or irrational behaviors.
Example
In investment decisions, a risk-averse investor may have a utility function that reflects a
preference for certain outcomes over uncertain ones with the same expected return.
3. Value Iteration
Definition
Value Iteration is an algorithm used to compute the optimal policy and value function in an
MDP. It iteratively updates the value of each state based on the expected utility of available
actions until convergence.
For a practical implementation, refer to GFG's article on Implement Value Iteration in
Python.
Advantages
Convergence to Optimal Policy: Guarantees finding the optimal policy if the process
converges.
Simplicity: Conceptually straightforward and easy to implement.
Disadvantages
2. Policy Improvement: Update the policy by choosing actions that maximize the
expected utility based on the current value function.
18 | P a g e
These steps are repeated until the policy converges to the optimal policy.
For a detailed comparison between value iteration and policy iteration, refer to GFG's article
on Difference Between Value Iteration and Policy Iteration.
Advantages
Efficiency: Often converges faster than value iteration in practice.
A Partially Observable Markov Decision Process (POMDP) extends the MDP framework to
situations where the agent cannot fully observe the current state. Instead, the agent
receives observations that provide partial information about the state. A POMDP is defined
by:
States (S): Possible situations in which an agent can be.
19 | P a g e
For a detailed explanation, refer to GFG's article on Partially Observable Markov Decision
Process (POMDP) in AI.
Advantages
Realistic Modeling: More accurately represents real-world scenarios where agents
have limited or noisy perceptions.
Robust Decision-Making: Enables the development of policies that account for
uncertainty in observations.
Disadvantages
Definition
Passive Reinforcement Learning refers to scenarios where an agent follows a fixed policy
and learns the value of states or state-action pairs without influencing the environment
through its actions. The agent observes the outcomes of the policy and updates its value
estimates accordingly.
Types
Direct Utility Estimation: The agent estimates the utility (value) of each state directly
by averaging the observed rewards obtained from that state.
Adaptive Dynamic Programming (ADP): The agent uses a model of the
environment's dynamics to compute the value function, often employing techniques
like value iteration or policy iteration.
20 | P a g e
Advantages
Simplicity: Easier to implement as the policy is fixed, and the agent only needs to
evaluate it.
Stability: Since the policy doesn't change, the learning process is stable and
predictable.
Disadvantages
Lack of Exploration: The agent cannot explore alternative actions that might lead to
higher rewards.
Suboptimal Policies: The fixed policy may not be optimal, limiting the agent's
performance.
Example
Consider a robot following a predetermined path in a maze. It learns the value of each
position based on the rewards received (e.g., reaching the exit) but doesn't deviate from its
path to explore potentially better routes.
2. Direct Utility Estimation
Definition
Direct Utility Estimation involves the agent estimating the utility (value) of each state by
averaging the rewards observed from that state under a fixed policy. This method doesn't
require a model of the environment's dynamics.
Advantages
Model-Free: Doesn't require knowledge of the environment's transition probabilities.
Definition
21 | P a g e
Adaptive Dynamic Programming (ADP) is a method where the agent uses a model of the
environment's dynamics to compute the value function. Techniques like value iteration or
policy iteration are employed to find the optimal policy based on the estimated model.
Advantages
Efficiency: Utilizes a model to compute value functions, potentially speeding up
learning.
Optimality: Can converge to the optimal policy if the model is accurate.
Disadvantages
Model Dependence: Requires an accurate model of the environment, which may not
always be available.
Online Learning: Updates can be made after each step, allowing for real-time
learning.
22 | P a g e
Definition
Active Reinforcement Learning involves an agent that not only learns from the environment
but also actively makes decisions to influence it. The agent explores different actions to
discover which yield the highest rewards, balancing exploration and exploitation.
Types
Q-Learning: A model-free algorithm where the agent learns the value of action-state
pairs (Q-values) and derives a policy by selecting actions that maximize these values.
Advantages
A robotic vacuum learns to navigate a room efficiently by trying different cleaning paths and
learning which ones cover the area most effectively.
6. Q-Learning
Definition
Q-Learning is a model-free reinforcement learning algorithm that seeks to learn the value of
state-action pairs (Q-values). The agent updates its Q-values based on the reward received
and the maximum expected future rewards, following the Bellman equation:
Q(s,a)←Q(s,a)+α[R+γmaxa′Q(s′,a′)−Q(s,a)]Q(s, a) \leftarrow Q(s, a) + \alpha \left[ R +
\gamma \max_{a'} Q(s', a') - Q(s, a) \right]Q(s,a)←Q(s,a)+α[R+γmaxa′Q(s′,a′)−Q(s,a)]
Where:
sss = current state
23 | P a g e
For a detailed explanation and Python implementation, refer to GFG's article on Q-Learning
in Python.
Advantages
Model-Free: Doesn't require a model of the environment, making it widely
applicable.
Convergence: Proven to converge to the optimal policy given sufficient exploration
and learning time.
Disadvantages
24 | P a g e