Module 1
Module 1
Algorithms
Gahan A V
Assistant Professor
Department of Electronics and Communication Engineering
Bangalore Institute of Technology
BANGALORE INSTITUTE OF TECHNOLOGY
Syllabus
Text Book
"Imagine you have a personal assistant that can learn from your daily habits and preferences. What tasks would you want it to
handle for you“
"Can you think of a movie or book where an intelligent system played a significant role? How did it interact with the humans in
the story?"
"Why do you think self driving cars need machine learning algorithms? What kind of decisions do these cars need to make that
require them to 'learn'?"
"How do you think social media platforms use machine learning to personalize your feed? What are some potential benefits and
drawbacks of this?"
Module 1
7
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY
For thousands of years, we have tried to understand how we think; that is, how a mere
handful of matter can perceive, understand, predict, and manipulate a world far larger and
more complicated than itself.
The field of artificial intelligence, or AI, goes further still: it attempts not just to
understand but also to build intelligent entities such as robots, AI systems, or software
with advanced problemsolving capabilities.
Work started in earnest soon after World War II, and the name itself was coined in
1956.
What is AI ?
We have claimed that AI is exciting, but we have not said what it is.
"humanly" is more about the emotional and social aspects of human behavior, while
"rationally" focuses on logical and analytical thinking.
Historically, all four approaches to AI have been followed, each by different people
with different methods.
The Turing Test, proposed by Alan Turing TURING TEST (1950), was designed to
provide a satisfactory operational definition of intelligence.
For now, we note that programming a computer to pass a rigorously applied test provides
plenty to work on.
Thinking rationally: The "laws of thought" approach means using clear, logical rules to
guide thinking and decision making.
It’s about following strict principles of logic, like a set of rules, to ensure that
conclusions make sense and are correct.
The aim is to create systems or models that think in a perfectly logical way, similar to
how an ideal rational person would think.
+ =
Involves designing systems or agents that make decisions and take actions in a way that
maximizes their chances of achieving their goals.
This approach focuses on creating agents that use available information and logical
reasoning to act in the most effective and efficient manner.
In simple terms, a rational agent is one that does what is most likely to lead to the best
outcome, based on what it knows and its goals.
For example, a navigation app that chooses the fastest route to your destination,
considering current traffic conditions, is using a rational agent approach.
• A brief history of the disciplines that contributed ideas, viewpoints, and techniques to AI.
Philosophy
Mathematics
Economics
Neuroscience
Psychology
Computer engineering
Linguistics
• Chapter 1 identified the concept of rational agents as central to our approach to artificial intelligence.
• How well an agent can behave depends on the nature of the environment; some environments are more
difficult than others.
• We give a crude categorization of environments and show how properties of an environment influence
the design of suitable agents for that environment
A Rational agent in artificial intelligence is an entity that acts to achieve the best possible outcome or, when there is
uncertainty, aims for the most expected success based on the information it has.
3.Action Choice: An agent makes decisions based on everything it has perceived so far
(the percept sequence), not on things it hasn’t encountered.
2. Building the Table: In theory, we can construct this table by testing all possible
percept sequences and recording the agent's responses.
- Various vacuumworld agents can be defined by adjusting their responses in the table.
- The key challenge is determining what makes an agent good, bad, intelligent, or not.
- The agent concept is a tool for analysis, not a strict classification of systems.
- A rational agent is one that always does the right thing by correctly filling in the agent function
table.
- Doing the right thing means the agent’s actions lead to desirable outcomes.
- The correctness of an agent’s actions is determined by the consequences of its behavior in the
environment.
- If the resulting sequence of states is desirable, the agent has performed well.
- Performance measure is used to evaluate how desirable the sequence of environment states is,
helping assess the agent’s performance.
- Success is defined in terms of environment states, not the agent's internal state or
opinion.
- If success were based on the agent’s own opinion, it could wrongly believe it
performed perfectly.
- Self-deception could lead to the agent thinking it is perfectly rational, even when it
isn’t.
- Performance measures vary depending on the task and agent; they need to be
designed for the specific circumstances.
- For the vacuum-cleaner agent, measuring performance by the amount of dirt cleaned
could lead to counterproductive behavior, like repeatedly cleaning and dumping dirt.
- A better measure would focus on the cleanliness of the floor, such as awarding points
for each clean square and possibly factoring in penalties for energy use and noise.
- The performance measure should reflect what is actually desired in the environment,
not just how one thinks the agent should act.
A rational agent should choose an action that it expects will best improve
its performance measure, based on the current percept sequence and any
built-in knowledge it has.
- Define the performance measure: One point for each clean square per time step over 1000 time steps.
- Know the environment: The layout is known, but dirt distribution and the agent's starting position are
unknown. Cleaning a square and moving left or right are the actions available.
- Confirm the agent's capabilities: It can perceive its location and whether there's dirt, and it can move or
clean accordingly.
The agent’s rationality depends on whether it effectively maximizes the performance measure under these
conditions.
Under the given circumstances, the agent is rational because its performance is as high as or higher
than any other agent’s. However, the same agent could be irrational in different scenarios:
- If all the dirt is cleaned, the agent will unnecessarily move back and forth, which could lead to poor
performance if there is a penalty for each move.
- An improved agent would stop moving once it ensures all squares are clean or would occasionally
check and clean if dirt can reappear.
- If the environment's layout is unknown, the agent should explore rather than limit itself to specific
squares.
These considerations highlight that rationality depends on the performance measure and the specific
conditions of the environment.
•Learning: Learning allows an agent to improve its performance over time by gaining new knowledge or updating
its strategies based on experience. A learning agent can adapt to changes in the environment and refine its
actions to achieve better results.
•Autonomy: Autonomy refers to an agent’s ability to make decisions and perform actions without human
intervention. An autonomous agent operates independently, relying on its sensors and built-in knowledge to make
decisions and achieve its goals.
In summary, while omniscience is ideal but unrealistic, learning and autonomy are crucial for agents to effectively
interact with and adapt to their environments.
- Rationality vs. Omniscience: Rationality involves making the best decisions based on available
information, while omniscience means knowing all outcomes in advance.
- Example: Crossing the street to meet a friend is rational, even if unforeseen events (like a cargo
door falling) lead to bad outcomes. It doesn't mean the action was irrational.
- Rationality vs. Perfection: Rationality aims to maximize expected performance given what’s
known, whereas perfection would require knowing and achieving the best possible outcome after
the fact.
- Design Implications: Expecting agents to always perform perfectly based on outcomes is unrealistic
because it requires knowing future events, which is impossible without advanced tools like crystal
balls or time machines.
- Rationality depends on the percepts available and does not require knowing all future
outcomes.
- Looking Before Crossing: An agent must gather information (like looking both ways) to
avoid dangerous situations. Without this, the agent's decision may not be rational.
- Information Gathering: Rational agents take actions to improve future percepts, such as
checking their environment or exploring unknown areas to make better decisions.
- Learning Requirement: A rational agent must learn from its experiences and adapt its
behavior accordingly. It may start with some prior knowledge but should update this
knowledge as it gains new experiences.
- Complete Knowledge: In cases where the environment is fully known from the start,
the agent does not need to perceive or learn; it can act correctly based on the
complete information.
- Fragility of Fixed Behaviors: Agents with rigid behaviors based on fixed assumptions
can be fragile.
- Dung Beetle: The beetle keeps trying to plug its nest with dung even if the dung ball it
was carrying gets lost. It doesn’t adjust its behaviour when things change, which means it
fails to adapt.
- Sphex Wasp: The wasp has a set routine for dealing with its prey (a caterpillar) but
doesn’t change its actions if the caterpillar is moved. It keeps following its plan without
adapting, showing it doesn’t learn from changes in its environment.
- Autonomy: An agent that depends too much on its designer’s prior knowledge lacks autonomy. A
truly rational agent should be able to learn from its experiences and adapt, rather than just relying
on initial instructions.
- Example: A vacuum-cleaning agent that learns to predict where and when dirt will appear will
perform better than one that doesn’t learn.
- Initial Knowledge: It’s practical to give an agent some initial knowledge or guidance when it starts,
as it may otherwise act randomly due to lack of experience.
- Learning and Independence: Over time, as the agent gains experience, it can become more
independent and rely less on prior knowledge. This makes it capable of succeeding in a wide range of
environments.
• A task environment is essentially the "problem" that a rational agent is meant to solve.
• Different task environments require different agent designs, so it's important to specify the environment
correctly.
• By understanding the nature of the task environment, we can determine the most suitable approach for
designing an agent to operate effectively within it.
• This is summarized by the acronym PEAS. The first step in designing an agent is fully defining its task
environment.
• While the vacuum cleaner is a simple example, a more complex case like an automated taxi driver
highlights how challenging and unpredictable real-world environments can be for agents.
• For an automated taxi driver, the performance measure would include reaching the correct destination,
minimizing fuel consumption, trip time, and costs, obeying traffic laws, maximizing safety, ensuring
passenger comfort, and possibly maximizing profits. Some of these goals might conflict, so trade-offs will be
necessary.
• The driving environment could involve various types of roads, traffic, pedestrians, animals, road obstacles,
and weather conditions. The environment might vary depending on the location, such as snowy areas
versus regions with little snow, and whether the taxi operates on the right or left side of the road.
• The actuators would include controls for the engine, steering, and braking, similar to those of a human
driver. Additionally, it would need displays or voice outputs to communicate with passengers and possibly
other vehicles.
• The sensors would include cameras to view the road, infrared or sonar sensors to detect distances to other
objects, a speedometer, an accelerometer, and sensors to monitor the car's mechanical condition. It might
also use a GPS to navigate and a keyboard or microphone for passengers to input destinations.
• In Figure 2.5, different agent types are shown with their basic PEAS elements. Surprisingly, some
agents operate in artificial environments, like software that responds to keyboard input and
screen output.
• The key point isn't whether the environment is "real" or "artificial," but rather how complex the
relationship is between the agent's behaviour, its perceptions, and the performance measure.
• Some "real" environments are quite simple, such as a robot inspecting parts on a conveyor belt
with fixed conditions. On the other hand, software agents, or softbots, can operate in highly
complex domains like the Internet.
• For instance, a softbot managing a website must process language, learn user preferences, and
adapt to changing circumstances, such as fluctuating connections or new sources. The Internet's
complexity, with both human and artificial agents, can rival that of the physical world.
• The variety of task environments in AI is immense, but we can categorize them based on a few key
dimensions. These dimensions help guide the design of appropriate agents and determine which
techniques are most suitable for their implementation.
• First, we list these dimensions, and then we examine different task environments to clarify the
concepts. While the definitions provided here are informal, more precise explanations and examples
will be given in later chapters.
• In a fully observable environment, the agent's sensors provide complete information about the
environment's state at every point, making it easier for the agent to act without needing to track or guess
missing details.
• This is ideal because the agent doesn't need to maintain internal memory about the world.
• On the other hand, a partially observable environment provides incomplete or noisy data, requiring the
agent to infer or keep track of missing information.
• For instance, a vacuum cleaner agent with a limited dirt sensor can't detect dirt in other rooms, and an
automated taxi can't predict what other drivers will do.
• If the environment is completely unobservable (no sensors at all), the agent may still achieve its goals
under certain conditions, even though it seems challenging.
• However, it's not always obvious when something should be treated as an agent. For example, should a
taxi driver view another vehicle as just an object obeying physical laws or as an agent with its own goals?
• The distinction depends on whether the other entity's behavior is best understood as trying to maximize
its own performance measure, which may depend on the first agent's actions.
• In chess, the opponent aims to minimize the first player's success, making it a competitive multiagent
environment.
• In contrast, in taxi driving, agents cooperate to avoid collisions, making it partially cooperative, though
there are competitive elements like fighting for parking spaces. In multiagent environments,
communication and even random behavior can be important strategies, especially in competitive
settings.
• In a deterministic environment, the next state is fully determined by the current state and the agent's
action, with no uncertainty involved.
• In contrast, a stochastic environment has some level of unpredictability, meaning that the same action
might lead to different outcomes. In fully observable deterministic environments, the agent doesn't need
to worry about uncertainty.
• However, if the environment is only partially observable, it may seem stochastic because the agent lacks
full information.
• Most real-world environments, like taxi driving, are treated as stochastic because it's impossible to predict
everything, such as traffic behavior or unexpected events like tire blowouts.
• An uncertain environment is either not fully observable or not deterministic. "Stochastic" implies that
uncertainty is measured with probabilities, while "nondeterministic" means there are multiple possible
outcomes, but no probabilities are specified. In such cases, the agent must succeed across all possible
outcomes.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY
• In an episodic environment, the agent's actions are divided into separate, independent episodes.
• In each episode, the agent receives a percept and performs an action, and the outcome of one episode
does not affect future ones.
• For example, an agent inspecting defective parts on an assembly line makes decisions based only on the
current part, without considering past actions or affecting future parts.
• In a sequential environment, actions have long-term consequences. Decisions made now can influence
future decisions, as in chess or taxi driving, where short-term moves can impact the entire game or driving
trip.
• Episodic environments are simpler because the agent doesn’t need to plan ahead, unlike in sequential
environments.
• In a static environment, nothing changes while the agent is making a decision, allowing it to focus
without worrying about time or external changes.
• Dynamic environments, however, change continuously, requiring the agent to make decisions quickly; if
it takes too long, that inaction is effectively a decision to do nothing.
• If the environment itself doesn’t change but the agent’s performance score does over time, it is termed
semi dynamic.
• For example, taxi driving is dynamic because other vehicles are constantly moving. Chess played with a
timer is semi dynamic, as the state of the game doesn’t change, but the clock affects decision-making.
• In contrast, crossword puzzles are static, as they remain unchanged while the agent works on them.
• The discrete vs. continuous distinction relates to the state of the environment, how time is managed,
and the agent's percepts and actions.
• In a discrete environment, like chess, there are a finite number of distinct states and a limited set of
percepts and actions.
• Conversely, taxi driving is a continuous environment because both the state (e.g., speed and location)
and time are not limited to specific values; they vary smoothly over a range.
• Actions in this context, such as steering angles, are also continuous. While inputs from digital cameras
are technically discrete, they often represent continuously varying intensities and locations, so they are
treated as continuous for practical purposes.
• The known vs. unknown distinction pertains to the agent's knowledge about the environment's "laws of
physics."
• In a known environment, the agent understands the outcomes of its actions (or their probabilities if
stochastic). In an unknown environment, the agent must learn how it operates to make informed
decisions.
• This distinction is different from the fully vs. partially observable classifications. A known environment
can still be partially observable, like in solitaire card games where the rules are clear, but not all cards
are visible.
• Conversely, an unknown environment can be fully observable; for instance, in a new video game, the
screen may display the entire game state, but the agent doesn't know how the controls work until it
experiments.
• The most challenging environment for an agent is one that is partially observable, multiagent, stochastic,
sequential, dynamic, continuous, and unknown.
• Taxi driving exemplifies many of these challenges, though generally, the driver has knowledge of the
environment. However, driving a rented car in a new country introduces unfamiliar geography and traffic
laws, making it more complex.
• Figure 2.6 categorizes various familiar environments, showing that some classifications can be nuanced.
For instance, a part-picking robot is usually considered episodic, as it assesses each part independently.
However, if it encounters a batch of defective parts, it should adapt its behavior based on this new
information.
The known vs. unknown distinction isn't included because it relates more to the agent's knowledge than
the environment itself. Games like chess and poker can have clear rules, but it’s still interesting to think
about how an agent could learn to play these games without prior knowledge of the rules.
• Now, we need to discuss the internal workings of agents. The goal of AI is to create an agent program that
implements the agent function, which maps percepts to actions.
• The agent is defined as the combination of the architecture and the program: agent = architecture +
program.
• The chosen program must be suitable for the architecture; for example, if the program suggests actions
like "walk," the architecture should include legs.
• The architecture could be anything from a standard PC to a robotic car equipped with various sensors and
computers.
• In general, the architecture processes the sensor inputs, runs the agent program, and sends the generated action
choices to the actuators. Most of the book focuses on designing agent programs, while later chapters will address
the specifics of sensors and actuators.
Agent programs
• The agent programs we design in this book follow a standard structure: they take the current percept
from the sensors as input and return an action for the actuators.
• It’s important to distinguish between the agent program, which only uses the current percept, and the
agent function, which considers the entire history of percepts.
• If the agent needs to make decisions based on the full sequence of percepts, it must store that history.
• We describe these agent programs using a simple pseudocode language, with real implementations
available in an online repository.
• For instance, one example program keeps track of the percept sequence and uses it to look up actions in a table. This
table represents the agent function, mapping every possible percept sequence to the appropriate action. To create a
rational agent, designers must construct a comprehensive table that accounts for every potential percept sequence.
1. Function Definition: The function `TABLE-DRIVEN-AGENT` takes a `percept` as input and returns an action.
2. Persistent Variables:
- `percepts`: A sequence that starts empty and will store the history of percepts received.
- `table`: A predefined table of actions that is indexed by percept sequences.
3. Action Steps:
- Append the current `percept` to the end of the `percepts` sequence.
- Look up the appropriate `action` in the `table` using the current `percepts` as the key.
- Return the chosen `action`.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
BANGALORE INSTITUTE OF TECHNOLOGY
In the remainder of this section, we outline four basic kinds of agent programs that embody the principles
underlying almost all intelligent systems:
• Imagine a robot vacuum cleaner. It's a simple machine with a single task: to clean up dirt.
• How does it know where to go? It doesn't have a map or a complex brain.
• It's a type of artificial intelligence that makes decisions based on the current situation without considering past experiences.
Key Points:
* Relies on the present: Simple reflex agents only look at what's happening right now.
* No memory: They don't remember what they've done in the past.
* Rule-based: Their actions are guided by simple rules.
Limitations:
While simple reflex agents are useful for basic tasks, they have limitations:
• Can't handle complex situations: They struggle when the environment changes or when there are multiple factors to
consider.
In conclusion, simple reflex agents are like a robot vacuum cleaner: they're good at their specific task but don't have the
intelligence to handle more complex situations.
Imagine a robot that can't see everything around it. How can it make smart decisions?
Model-Based Agents are like robots that have a mental map. This map helps them figure out what's happening even
when they can't see everything.
• Internal State: Think of this as the robot's mental map. It keeps track of what the robot knows about the world, even
if it can't see it all.
• Model of the World: This is like the robot's understanding of how the world works. It knows things like how fast
cars usually move or how traffic lights work.
* Updating the Map: The robot uses its sensors (like cameras) to see what's happening now. It then combines this
information with its mental map (internal state) and its understanding of the world (model) to update its map.
Example:
* Making Smart Decisions: By having a mental map, the robot can make better decisions, even in situations where it
doesn't have all the information.
* Handling Uncertainty: The world can be unpredictable. Model-based agents can handle this by using their mental map
to make educated guesses.
Imagine a robot that wants to get to a specific place. It's not enough for it to just know where it is now and what's around
it. It also needs to know where it wants to go.
Goal-Based Agents are like robots that have a destination in mind. They use their knowledge of the world and their goal
to figure out the best way to get there.
• Model of the World: This is the robot's understanding of how the world works, similar to what we discussed in the
previous section.
* Decision Making: The robot uses its goal and its understanding of the world to plan a series of actions that will lead it
to its destination.
Example:
* Flexibility: Goal-based agents can adapt to changing situations. If the robot's path is blocked, it can find a new way.
* Planning: These agents can plan ahead, thinking about the consequences of their actions.
* Complex Tasks: They can handle more complex tasks that require multiple steps to achieve a goal.
In simple terms, Goal-Based Agents are like robots that have a purpose and can plan their actions to achieve that
purpose. They're more flexible and capable than simple reflex agents that just react to their surroundings.
It also needs to consider factors like safety, traffic, and fuel efficiency.
Utility-Based Agents are like robots that have a way to measure how good or bad different outcomes are.
They use this measurement (called utility) to make decisions that maximize their overall happiness or satisfaction.
• Utility: This is a measure of how good or bad a situation is for the robot. It takes into account factors like safety, speed,
cost, and other things that the robot values.
* Decision Making: The robot chooses actions that it believes will lead to the highest utility. It considers the possible
outcomes and their associated utilities.
• Complex Decisions: Utility-based agents can make complex decisions that involve multiple factors.
• Trade-offs: They can weigh the pros and cons of different options and make decisions that balance competing goals.
* Uncertainty: They can handle uncertainty by considering the probabilities of different outcomes and their associated
utilities.
In simple terms, Utility-Based Agents are like robots that can make smart decisions by considering the overall value of
different outcomes. They're able to weigh factors like speed, safety, and cost to make the best choices.
Imagine a robot that can learn from its mistakes. Unlike a robot that follows fixed rules, a learning agent can improve
over time.
Learning Agents are like robots that can get smarter. They have four main parts:
1. Performance Element: This is the part that makes decisions and takes actions.
3. Critic: This is the part that tells the learning element how well the agent is doing.
* Adaptability: Learning agents can adapt to new situations and improve their performance over time.
* Flexibility: They can handle tasks that are difficult to define with fixed rules.
* Real-World Applications: Learning agents are used in many areas, such as self-driving cars, medical diagnosis, and
language translation.
In simple terms, Learning Agents are robots that can learn from their experiences and become better at what they do.
They're a key part of creating intelligent systems that can adapt to the real world.
Think of AI representations as different ways to describe the world. Just like you can describe a picture using words, an
AI agent can describe the world using different kinds of representations.
* Simple and Basic: These are like single words or symbols that represent a whole idea.
* Limited Detail: They don't provide much information about the details of the world.
* Example: Describing a car as just "car" without mentioning its color, make, or model.
* More Detailed: These representations break down things into smaller parts, like attributes or variables.
* Flexible: They can represent different combinations of these parts.
* Example: Describing a car as a "red" "Toyota" "Camry."
* Most Complex: These representations show how things are connected or related to each other.
* Real-World Complexity: They can capture the complex relationships in the real world.
* Example: Describing a car as having "four wheels," "a steering wheel," and "a driver."
* Different Tasks: Some tasks require simple representations, while others need more complex ones.
* Trade-offs: More complex representations can capture more details but can also be harder to work with.
* Real-World Complexity: The real world is complex, so we need representations that can capture its complexity.
In simple terms, atomic representations are like single words, factored representations are like sentences, and structured
representations are like stories. Each type of representation has its own strengths and weaknesses, and the best choice depends
on the specific task at hand.