unit 1
unit 1
Introduction:
Artificial Intelligence is concerned with the design of intelligence in an
artificial device. The term was coined by John McCarthy in 1956.
Intelligence is the ability to acquire, understand and apply the knowledge to
achieve goals in the world.
AI is the study of the mental faculties through the use of computational models
AI is the study of intellectual/mental processes as computational processes.
AI program will demonstrate a high level of intelligence to a degree that
equals or exceeds the intelligence required of a human in performing some
task.
AI is unique, sharing borders with Mathematics, Computer
Science, Philosophy, Psychology, Biology, Cognitive Science
and many others.
Although there is no clear definition of AI or even Intelligence, it can be
described as an attempt to build machines that like humans can think and
act, able to learn and use knowledge to solve problems on their own.
History of AI
o Throughout history, people have been intrigued by the idea of making non-living
things smart. In ancient times, Greek stories mentioned gods creating clever
machines, and in Egypt, engineers made statues move. Thinkers like Aristotle and
Ramon Llull laid the groundwork for AI by describing how human thinking works
using symbols.
o In the late 1800s and early 1900s, modern computing started to take shape. Charles
Babbage and Ada Lovelace designed machines that could be programmed in the
1830s. In the 1940s, John Von Neumann came up with the idea of storing computer
programs. At the same time, Warren McCulloch and Walter Pitts started building the
basics of neural networks.
o The 1950s brought us modern computers, letting scientists dig into machine
intelligence. Alan Turing's Turing test became a big deal in computer smarts. The
term "artificial intelligence" was first used in a 1956 Dartmouth College
meeting, where they introduced the first AI program, the Logic Theorist.
o The following years had good times and bad times for AI, called "AI Winters." In the
1970s and 1980s, we hit limits with computer power and complexity. But in the late
1990s, things got exciting again. Computers were faster, and there was more
data. IBM's Deep Blue beating chess champion Garry Kasparov in 1997 was a big
moment.
o The 2000s started a new era with machine learning, language processing, and
computer vision. This led to cool new products and services. The 2010s saw AI take
off with things like voice assistants and self-driving cars. Generative AI, which makes
creative stuff, also started getting big.
o In the 2020s, generative AI like ChatGPT-3 and Google's Bard grabbed everyone's
attention. These models can create all sorts of new things when you give them a
prompt, like essays or art. But remember, this tech is still new, and there are things to
fix, like making sure it doesn't make things up.
5. Creating some system which can exhibit intelligent behavior, learn new things by
itself, demonstrate, explain, and can advise to its user.
Challenges of AI
Artificial Intelligence offers incredible advantages, but it also presents some challenges that
need to be addressed:
o Doing the Right Thing: AI should make the right choices, but sometimes it doesn't.
It can make mistakes or do things that aren't fair. We need to teach AI to be better at
making good choices.
o Government and AI: Sometimes, governments use AI to keep an eye on people.
This can be a problem for our freedom. We need to make sure they use AI in a good
way.
o Bias in AI: AI can sometimes be a bit unfair, especially when it comes to recognizing
people's faces. This can cause problems, especially for people who aren't like the
majority.
o AI and Social Media: What you see on social media is often decided by AI. But
sometimes, AI shows things that aren't true or are kind of mean. We need to make
sure AI shows the right stuff.
o Legal and Regulatory Challenges: The rapid evolution of AI has outpaced the
development of comprehensive laws and regulations, leading to uncertainty about
issues like liability and responsibility.
Intelligent Agent
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:
o Checkers- Where the previous move can affect all the
following moves.
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.
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.
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:
o Chess – there would be only a few possible moves for a chess
piece at the current state and these moves can be determined.
o Self-Driving Cars- the actions of a self-driving car are not
unique, it varies time to time.
A: Actuators
An actuator is a part of the agent that delivers the output of action to the environment.
They are responsible for executing the actions decided by the agent based on its perceptions
and decisions. In essence, actuators are the “hands and feet” of the agent, enabling it to
carry out tasks.
The actuators for a smart thermostat include the heating system, cooling system, and fans,
which it controls to adjust the room temperature and maintain the desired comfort level.
The design and choice of actuators are crucial because they directly affect the agent’s
ability to perform its functions in the environment.
S: Sensors
Sensors are the receptive parts of an agent that takes in the input for the agent.
Sensors collect data from the environment, which is then processed by the agent to make
informed decisions. Sensors are the “eyes and ears” of the agent, providing it with the
necessary information to act intelligently.
The sensors for a smart thermostat include temperature sensors to measure the current room
temperature, humidity sensors to detect moisture levels, and motion sensors to determine if
people are present in the house.
The quality and variety of sensors used in an AI system greatly influence its ability to
perceive and understand its environment.
Importance of PEAS in AI
The PEAS framework is vital for the design and development of AI system because it
provides a structured approach to defining the agent’s interaction with its environment. By
clearly specifying the performance measure, environment, actuators, and sensors,
developers can create AI systems that are more effective and adaptable to their tasks.
Using PEAS helps in:
Defining clear goals: The performance measure ensures that the agent’s actions
are aligned with the desired outcomes.
Understanding the operational context: Analyzing the environment allows
developers to anticipate challenges and design solutions that are robust and
effective.
Designing effective interactions: Selecting the right actuators and sensors
ensures that the agent can perceive and interact with its environment in a
meaningful way.
Exploring Different Types of AI Agents with PEAS Examples
Performance
Agent Measure Environment Actuator Sensor
Patient’s health,
Hospital Prescription, Symptoms,
Admission Hospital,
Management Diagnosis, Scan Patient’s
process, Doctors, Patients
System report response
Payment
The comfortable
Steering wheel, Camera,
Automated trip, Safety, Roads, Traffic,
Accelerator, GPS,
Car Drive Maximum Vehicles
Brake, Mirror Odometer
Distance
students Students
Percentage of Camera,
Part-picking Conveyor belt Jointed arms
parts in correct joint angle
robot with parts; bins and hand
bins sensors
Satellite
Display
image Correct image Downlink from Color pixel
categorization
analysis categorization orbiting satellite arrays
of scene
system
Advantages of PEAS in AI
1. Structured Design: Provides a clear framework for designing intelligent agents
by breaking down their components.
2. Versatility: Applicable to various AI systems, from simple bots to complex
autonomous agents.
3. Goal-Oriented: Ensures that agents are designed with specific, measurable
objectives, leading to better performance.
4. Systematic Development: Facilitates organized planning and development,
making the process more efficient.
Disadvantages of PEAS in AI
1. Complexity: Can be complex to implement in dynamic environments with many
variables.
2. Over-Simplification: Might oversimplify real-world scenarios, leading to gaps
in agent behavior.
3. Resource-Intensive: Requires significant resources to accurately define and
implement each PEAS component.
4. Limited Adaptability: May struggle to adapt to unexpected changes if not
designed with enough flexibility.
Types of Agents
Agents can be grouped into five classes based on their degree of perceived intelligence and
capability :
Simple Reflex Agents
Model-Based Reflex Agents
Goal-Based Agents
Utility-Based Agents
Learning Agent
Multi-agent systems
Hierarchical agents
Simple Reflex Agents
Simple reflex agents ignore the rest of the percept history and act only on the basis of
the current percept. Percept history is the history of all that an agent has perceived to date.
The agent function is based on the condition-action rule. A condition-action rule is a rule
that maps a state i.e., a condition to an action. If the condition is true, then the action is
taken, else not. This agent function only succeeds when the environment is fully
observable. For simple reflex agents operating in partially observable environments, infinite
loops are often unavoidable. It may be possible to escape from infinite loops if the agent
can randomize its actions.
Problems with Simple reflex agents are :
Very limited intelligence.
No knowledge of non-perceptual parts of the state.
Usually too big to generate and store.
If there occurs any change in the environment, then the collection of rules needs
to be updated.
Simple Reflex Agents
Model-Based Reflex Agents
It works by finding a rule whose condition matches the current situation. A model-based
agent can handle partially observable environments by the use of a model about the
world. The agent has to keep track of the internal state which is adjusted by each percept
and that depends on the percept history. The current state is stored inside the agent which
maintains some kind of structure describing the part of the world which cannot be seen.
Updating the state requires information about:
How the world evolves independently from the agent?
How do the agent’s actions affect the world?
Model-Based Reflex Agents
Goal-Based Agents
These kinds of agents take decisions based on how far they are currently from
their goal(description of desirable situations). Their every action is intended to reduce their
distance from the goal. This allows the agent a way to choose among multiple possibilities,
selecting the one which reaches a goal state. The knowledge that supports its decisions is
represented explicitly and can be modified, which makes these agents more flexible. They
usually require search and planning. The goal-based agent’s behavior can easily be
changed.
Goal-Based Agents
Utility-Based Agents
The agents which are developed having their end uses as building blocks are called utility-
based agents. When there are multiple possible alternatives, then to decide which one is
best, utility-based agents are used. They choose actions based on a preference (utility) for
each state. Sometimes achieving the desired goal is not enough. We may look for a quicker,
safer, cheaper trip to reach a destination. Agent happiness should be taken into
consideration. Utility describes how “happy” the agent is. Because of the uncertainty in the
world, a utility agent chooses the action that maximizes the expected utility. A utility
function maps a state onto a real number which describes the associated degree of
happiness.
Utility-Based Agents
Learning Agent
A learning agent in AI is the type of agent that can learn from its past experiences or it has
learning capabilities. It starts to act with basic knowledge and then is able to act and adapt
automatically through learning. A learning agent has mainly four conceptual components,
which are:
1. Learning element: It is responsible for making improvements by learning from
the environment.
2. Critic: The learning element takes feedback from critics which describes how
well the agent is doing with respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action.
4. Problem Generator: This component is responsible for suggesting actions that
will lead to new and informative experiences.
Learning Agent
Multi-Agent Systems
These agents interact with other agents to achieve a common goal. They may have to
coordinate their actions and communicate with each other to achieve their objective.
A multi-agent system (MAS) is a system composed of multiple interacting agents that are
designed to work together to achieve a common goal. These agents may be autonomous or
semi-autonomous and are capable of perceiving their environment, making decisions, and
taking action to achieve the common objective.
MAS can be used in a variety of applications, including transportation systems, robotics,
and social networks. They can help improve efficiency, reduce costs, and increase
flexibility in complex systems. MAS can be classified into different types based on their
characteristics, such as whether the agents have the same or different goals, whether the
agents are cooperative or competitive, and whether the agents are homogeneous or
heterogeneous.
In a homogeneous MAS, all the agents have the same capabilities, goals, and
behaviors.
In contrast, in a heterogeneous MAS, the agents have different capabilities,
goals, and behaviors.
This can make coordination more challenging but can also lead to more flexible and robust
systems.
Cooperative MAS involves agents working together to achieve a common goal, while
competitive MAS involves agents working against each other to achieve their own goals. In
some cases, MAS can also involve both cooperative and competitive behavior, where
agents must balance their own interests with the interests of the group.
MAS can be implemented using different techniques, such as game theory, machine
learning, and agent-based modeling. Game theory is used to analyze strategic interactions
between agents and predict their behavior. Machine learning is used to train agents to
improve their decision-making capabilities over time. Agent-based modeling is used to
simulate complex systems and study the interactions between agents.
Overall, multi-agent systems are a powerful tool in artificial intelligence that can help solve
complex problems and improve efficiency in a variety of applications.
Uses of Agents
Agents are used in a wide range of applications in artificial intelligence, including:
Robotics: Agents can be used to control robots and automate tasks in
manufacturing, transportation, and other industries.
Smart homes and buildings: Agents can be used to control heating, lighting,
and other systems in smart homes and buildings, optimizing energy use and
improving comfort.
Transportation systems: Agents can be used to manage traffic flow, optimize
routes for autonomous vehicles, and improve logistics and supply chain
management.
Healthcare: Agents can be used to monitor patients, provide personalized
treatment plans, and optimize healthcare resource allocation.
Finance: Agents can be used for automated trading, fraud detection, and risk
management in the financial industry.
Games: Agents can be used to create intelligent opponents in games and
simulations, providing a more challenging and realistic experience for players.
Natural language processing: Agents can be used for language translation,
question answering, and chatbots that can communicate with users in natural
language.
Cybersecurity: Agents can be used for intrusion detection, malware analysis,
and network security.
Environmental monitoring: Agents can be used to monitor and manage natural
resources, track climate change, and improve environmental sustainability.
Social media: Agents can be used to analyze social media data, identify trends
and patterns, and provide personalized recommendations to users.
o A State Space. Set of all possible states where you can be.
o A Start State. The state from where the search begins.
o A Goal State. A function that looks at the current state returns whether or
not it is the goal state.
The Solution to a search problem is a sequence of actions, called the plan that
transforms the start state to the goal state.
This plan is achieved through search algorithms.
Types of search algorithms:
Output: 1 0 2 3 4
Explanation: The source vertex s is 1. We visit it first, then we visit an adjacent.
Start at 1: Mark as visited. Output: 1
Move to 0: Mark as visited. Output: 0 (backtrack to 1)
Move to 2: Mark as visited. Output: 2 (backtrack to 0)
Move to 3: Mark as visited. Output: 3 (backtrack to 2)
Move to 4: Mark as visited. Output: 4 (backtrack to 2)
Not that there can be more than one DFS Traversals of a Graph. For example, after 1, we
may pick adjacent 2 instead of 0 and get a different DFS. Here we pick in the insertion
order.
Input: [[2,3,1], [0], [0,4], [0], [2]]
Output: 0 2 4 3 1
Explanation: DFS Steps:
Start at 0: Mark as visited. Output: 0
Move to 2: Mark as visited. Output: 2
Move to 4: Mark as visited. Output: 4 (backtrack to 2, then backtrack to 0)
Move to 3: Mark as visited. Output: 3 (backtrack to 0)
Move to 1: Mark as visited. Output: 1
Output: [0, 1, 2, 3, 4]
Explanation: Starting from 0, the BFS traversal proceeds as follows:
Visit 0 → Output: 0
Visit 1 (the first neighbor of 0) → Output: 0, 1
Visit 2 (the next neighbor of 0) → Output: 0, 1, 2
Visit 3 (the first neighbor of 2 that hasn’t been visited yet) → Output: 0, 1, 2, 3
Visit 4 (the next neighbor of 2) → Final Output: 0, 1, 2, 3, 4
Input: adj = [[1], [0, 2, 3], [1], [1, 4], [3]]
Output: [0, 1, 2, 3, 4]
Explanation: Starting the BFS from vertex 0:
Visit vertex 0 → Output: [0]
Visit vertex 1 (first neighbor of 0) → Output: [0, 1]
Visit vertex 2 (first unvisited neighbor of 1) → Output: [0, 1, 2]
Visit vertex 3 (next neighbor of 1) → Output: [0, 1, 2, 3]
Visit vertex 4 (neighbor of 3) → Final Output: [0, 1, 2, 3, 4]
Uniform Cost Search (UCS)
Uniform Cost Search is a pathfinding algorithm that expands the least cost node first,
ensuring that the path to the goal node has the minimum cost.
Key Concepts of Uniform Cost Search
1. Priority Queue: UCS uses a priority queue to store nodes. The node with the
lowest cumulative cost is expanded first. This ensures that the search explores
the most promising paths first.
2. Path Cost: The cost associated with reaching a particular node from the start
node. UCS calculates the cumulative cost from the start node to the current node
and prioritizes nodes with lower costs.
3. Exploration: UCS explores nodes by expanding the least costly node first,
continuing this process until the goal node is reached. The path to the goal node
is guaranteed to be the least costly one.
4. Termination: The algorithm terminates when the goal node is expanded,
ensuring that the first time the goal node is reached, the path is the optimal one.
A* Search Algorithm
A* (pronounced "A-star") is a powerful graph traversal and pathfinding algorithm widely
used in artificial intelligence and computer science. It is mainly used to find the shortest path
between two nodes in a graph, given the estimated cost of getting from the current node to the
destination node.
A heuristic function, denoted h(n), estimates the cost of getting from any given node n to the
destination node.
The main idea of A* is to evaluate each node based on two parameters:
1. g(n): the actual cost to get from the initial node to node n. It represents the sum of the
costs of node n outgoing edges.
2. h(n): Heuristic cost (also known as "estimation cost") from node n to destination node
n. This problem-specific heuristic function must be acceptable, meaning it never
overestimates the actual cost of achieving the goal. The evaluation function of node n
is defined as f(n) = g(n) h(n).
Algorithm A* selects the nodes to be explored based on the lowest value of f(n), preferring
the nodes with the lowest estimated total cost to reach the goal. The A* algorithm works:
1. Create an open list of foundbut not explored nodes.
2. Create a closed list to hold already explored nodes.
3. Add a startingnode to the open list with an initial value of g
4. Repeat the following steps until the open list is empty or you reachthe target node:
1. Find the node with the smallest f-value (i.e., the node with the minor g(n)
h(n)) in the open list.
2. Move the selected node from the open list to the closed list.
3. Createall valid descendantsof the selected node.
4. For each successor, calculateits g-value as the sum of the current node's g
value and the cost of movingfrom the current node to the successor node.
Update the g-value of the tracker when a better path is found.
5. If the followeris not in the open list, add it with the calculated g-value and
calculate its h-value. If it is already in the open list, update its g value if the
new path is better.
6. Repeat the cycle. Algorithm A* terminates when the target node is reached or
when the open list empties, indicating no paths from the start node to the
target node. The A* search algorithm is widely used in various fields such as
robotics, video games, network routing, and design problems because it is
efficient and can find optimal paths in graphs or networks.
o GreedyBest-FirstSearch:
This informed search algorithm chooses the nodes, taking into consideration the goal's
cost estimate. It favors those nodes that look like they are closest to the goal, but it
does not always guarantee an optimal solution. It is useful when a good heuristic is
found, meaning that we do not always have to solve the problem from scratch.
Hill Climbing
Hill climbing is a widely used optimization algorithm in Artificial Intelligence (AI) that
helps find the best possible solution to a given problem. As part of the local search
algorithms family, it is often applied to optimization problems where the goal is to
identify the optimal solution from a set of potential candidates.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than
its surrounding areas, but itself has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can
improve this problem.
4. Current State: The current state refers to the algorithm’s position in the state-space
diagram during its search for the optimal solution.
5. Shoulder: A shoulder is a plateau with an uphill edge, allowing the algorithm to move
toward better solutions if it continues searching beyond the plateau.
Simulated annealing search
A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be
incomplete because it can get stuck on a local maximum. And if algorithm applies a random
walk, by moving a successor, then it may complete but not efficient. Simulated Annealing is
an algorithm which yields both efficiency and completeness.
In mechanical term Annealing is a process of hardening a metal or glass to a high
temperature then cooling gradually, so this allows the metal to reach a low-energy crystalline
state. The same process is used in simulated annealing in which the algorithm picks a random
move, instead of picking the best move. If the random move improves the state, then it
follows the same path. Otherwise, the algorithm follows the path which has a probability of
less than 1 or it moves downhill and chooses another path.
The algorithm is characterized by three main steps: initialization, temperature initialization,
and iteration.
Initialization
The algorithm begins with an initial solution to the optimization problem. This solution can
be generated randomly or through heuristic methods. The quality of the initial solution can
significantly impact the performance of the algorithm.
Temperature Initialization
An initial temperature, denoted as T, is set at the start of the algorithm. This temperature
plays a crucial role in determining the probability of accepting worse solutions initially. As
the algorithm progresses, the temperature gradually decreases, influencing the exploration of
the solution space.
Iteration Phase
During the iteration phase, the algorithm continues until a stopping criterion is met, such as
reaching a maximum number of iterations or when the temperature drops below a certain
threshold. The first step in each iteration typically involves perturbing the current solution to
generate a neighboring solution. This perturbation can include minor adjustments to the
current solution.
The algorithm then calculates the change in energy (∆Energy) between the current and
neighboring solutions. If ∆Energy is negative, indicating that the neighboring solution is
better, it is accepted. If not, the neighboring solution may still be accepted based on a
probability determined by the current temperature. This mechanism allows the algorithm to
escape local minima and explore the solution space more effectively.
Cooling Schedule
The cooling schedule is a critical component of the algorithm, controlling the rate at which
the temperature decreases. It can be linear, exponential, or follow other schemes. The choice
of cooling schedule affects the balance between exploration and exploitation, ultimately
influencing how quickly the algorithm converges to an optimal solution.
Simulated Annealing's ability to initially accept worse solutions with a certain probability
enables it to escape local optima, potentially leading to better solutions.
Advantages:
Can be computationally efficient, as it focuses on a smaller region
of the solution space.