AI Notes
AI Notes
Aristotle (384–322 B.C.), was the first to formulate a precise set of laws
governing the rational part of the mind. He developed an informal system of
syllogisms for proper reasoning, which in principle allowed one to generate
conclusions mechanically, given initial premises.
2) Mathematics
What are the formal rules to draw valid conclusions?
What can be computed?
Logic:
1 / 29
∀x, King(x) ^ Greedy (x) ⇒ Evil (x)
3) Economics
How should we make decisions so as to maximize payoff?
How should we do this when the payoff may be far in the future?
The science of economics got its start in 1776, when Scottish philosopher
Adam Smith treated it as a science, using the idea that economies can be
thought of as consisting of individual agents maximizing their own economic
well-being.
4) Neuroscience (1861-present)
How do brains process information?
Neuroscience is the study of the nervous system, particularly the brain. The
exact way in which the brain enables thought is one of the great mysteries of
science. It has been appreciated for thousands of years that the brain is
somehow involved in thought, because of the evidence that strong blows to
the head can lead to mental incapacitation. The brain is recognized as the
seat of consciousness. Before then, candidate locations included the heart,
the spleen, and the pineal gland. The truly amazing conclusion is that a
collection of simple cells can lead to thought, action, and consciousness or,
brains cause minds. It has also long been known that human brains are
somehow different; in about 335 B.C. Aristotle wrote, “Of all the animals, man
has the largest brain in proportion to his size.”
5) Psychology
How do humans and animals think and act?
2 / 29
1. Stimulus is translated into an internal representation
2. The representation is manipulated by cognitive processes to derive new
internal representations
3. These are translated into actions
6) Computer Engineering
How can we build an efficient computer?
History of AI
Maturation of Artificial Intelligence (1943-1952)
Year 1943: The first work which is now recognized as AI was done by
Warren McCulloch and Walter Pitts in 1943. They proposed a model of
artificial neurons.
Year 1949: Donald Hebb demonstrated an updating rule for modifying
the connection strength between neurons. His rule is now called
Hebbian learning.
Year 1950: Alan Turing, an English mathematician, pioneered Machine
learning in 1950. Alan Turing published "Computing Machinery and
Intelligence" in which he proposed a test. The test can check the
machine's ability to exhibit intelligent behavior equivalent to human
intelligence, called a Turing test.
3 / 29
Year 1956: The word "Artificial Intelligence" was first adopted by
American Computer scientist John McCarthy at the Dartmouth
Conference. For the first time, AI was coined as an academic field. At
that time high-level computer languages such as FORTRAN, LISP, or
COBOL were invented. The enthusiasm for AI was very high at that time.
The duration between 1974 to 1980 was the first AI winter duration. AI winter
refers to the time period where computer scientists dealt with a severe
shortage of funding from the government for AI research. During AI winters,
the interest of publicity on artificial intelligence decreased.
A Boom of AI (1980-1987)
Year 1980: After the AI winter duration, AI came back with "Expert
System". Expert systems were programmed to emulate the decision-
making ability of a human expert. In 1980, the first national conference
of the American Association of Artificial Intelligence was held at
Stanford University.
The duration between the years 1987 to 1993 was the second AI Winter
duration. Again, investors and the government stopped funding for AI
research due to high costs but not efficient results. The expert system such as
XCON was very cost-effective.
4 / 29
The Emergence of Intelligent Agents (1993-2011)
Year 1997: In 1997, IBM Deep Blue beat world chess champion Gary
Kasparov and became the first computer to beat a world chess
champion.
Year 2002: For the first time, AI entered the home in the form of
Roomba, a vacuum cleaner.
Year 2006: AI came into the business world. Companies like Facebook,
Twitter, and Netflix started using AI.
5 / 29
2. Robotic Vehicles: Today's robots are far more sophisticated than their
predecessors. Many are semi-autonomous, with machine vision systems
to interact within a changing environment. Some can even work side-by-
side with humans. All signs suggest we are in the middle of a new
industrial robot boom.
3. Autonomous Planning and Scheduling: A hundred million miles
from Earth, NASA's Remote Agent program became the first on-board
autonomous planning program to control the scheduling of operations
for a spacecraft.
4. Game Playing (GP): It is the design of artificial intelligence programs
to be able to play more than one game successfully. For many games like
chess, computers are programmed to play these games using a specially
designed algorithm, which cannot be transferred to another context. For
example, a chess-playing computer program cannot play checkers.
5. Spam Fighting: The spam filter now uses an artificial neural network
to detect and block especially sneaky or dishonest spam mails.
6. Machine Translation: A computer program automatically translates
from Arabic to English, allowing an English speaker to understand the
content.
Above are just a few examples of artificial intelligence systems that exist
today. Not magic or science fiction, but rather science, engineering, and
mathematics.
What is an Agent?
An agent can be anything that perceives its environment through
sensors and acts upon that environment through actuators.
An Agent runs in the cycle of perceiving, thinking, and acting.
An agent gets percepts one at a time and maps this percept sequence to
action.
Percepts are the electrical signals from sensors after processing objects
in the visual field (like location, colors, loudness, direction, etc.)
6 / 29
Types of Agents:
Human-Agent: A human agent has eyes, ears, and other organs which
work for sensors and hand, legs, vocal tract work for actuators.
Robotic Agent: A robotic agent can have cameras, infrared range
finder, NLP for sensors and various motors for actuators.
Software Agent: Software agent can have keystrokes, file contents as
sensory input and act on those inputs and display output on the screen.
Sensors:
Sensor is a device that detects the change in the environment and sends the
information to other electronic devices. An agent observes its environment
through sensors.
Actuators:
Actuators are the components of machines that convert energy into motion.
The actuators are only responsible for moving and controlling a system. An
actuator is a device that causes machines or other devices to operate. An
actuator can be an electric motor, gears, rails, etc.
Effectors:
Effectors are the devices that affect the environment. Effectors can be legs,
wheels, arms, fingers, wings, fins, and display screens.
Intelligent Agents:
7 / 29
from the environment to achieve its goals. A thermostat is an example of an
intelligent agent.
Architecture:
This refers to machinery or devices that consist of actuators and sensors. The
intelligent agent executes on this machinery. Examples include a personal
computer, a car, or a camera.
Agent Function:
8 / 29
Agent Program:
Perception:
Action:
Action is an active interaction between the agent and the environment where
the environment changes when the action is performed. This involves the
utilization of an 'Effector' or an 'Actuator' which completes an action but leads
to changes in the surroundings while doing so. For example, in the case of a
virtual agent, when the virtual agent reads and interprets the information
provided by the user, it is known as 'Perception' while when it replies to the
user based on the interpretation it is known as 'Action'.
They have some level of autonomy that allows them to perform certain
tasks on their own.
9 / 29
They have a learning ability that enables them to learn even as tasks are
carried out.
They can interact with other entities such as agents, humans, and
systems.
New rules can be accommodated by intelligent agents incrementally.
They exhibit goal-oriented habits.
They are knowledge-based. They use knowledge regarding
communications, processes, and entities.
Rational Agent:
A rational agent is an agent that has clear preferences, models uncertainty,
and acts in a way to maximize its performance measure with all possible
actions. A rational agent is said to perform the right things. AI is about
creating rational agents to use for game theory and decision theory for
various real-world scenarios. For an AI agent, the rational action is most
important because in the AI reinforcement learning algorithm, for each best
possible action, the agent gets a positive reward and for each wrong action,
an agent gets a negative reward.
Rationality:
PEAS Representation
PEAS is a type of model on which an AI agent works upon. When we define
an AI agent or rational agent, then we can group its properties under the
PEAS representation model. It is made up of four words:
10 / 29
P: Performance measure
E: Environment
A: Actuators
S: Sensors
11 / 29
Discrete vs. Continuous
The discrete/continuous distinction can be applied to the state of the
environment, to the way time is handled, and to the percepts and
actions of the agent.
For example, a discrete-state environment such as a chess game has a
finite number of distinct states.
Chess also has a discrete set of percepts and actions.
Taxi driving is a continuous-state and continuous-time problem:
The speed and location of the taxi and of the other vehicles sweep
through a range of continuous values and do so smoothly over
time.
Taxi-driving actions are also continuous (steering angles, etc.)
Performance can be improved and better action can be generated for each of
these types of agents in AI.
12 / 29
Simple Reflex Agents
This is a simple type of agent that works on the basis of the current percept
and not based on the rest of the percepts history. The agent function, in this
case, is based on condition-action rule where the condition or the state is
mapped to the action such that action is taken only when the condition is true
or else it is not. If the environment associated with this agent is fully
observable, only then is the agent function successful, if it is partially
observable, in that case, the agent function enters into infinite loops that can
be escaped only on randomization of its actions. The problems associated
with this type include very limited intelligence, no knowledge of non-
perceptual parts of the state, huge size for generation and storage, and
inability to adapt to changes in the environment.
Example: A thermostat in a heating system.
Model-Based Agents
Model-based agents utilize the condition-action rule, where it works by
finding a rule that will allow the condition, which is based on the current
situation, to be satisfied. Irrespective of the first type, it can handle partially
observable environments by tracking the situation and using a particular
model related to the world. It consists of two important factors, which are
Model and Internal State. The model provides knowledge and understanding
of the process of occurrence of different things in the surroundings such that
the current situation can be studied and a condition can be created. Actions
are performed by the agent based on this model. Internal State uses the
perceptual history to represent a current percept. The agent keeps track of
this internal state and is adjusted by each of the percepts. The current
internal state is stored by the agent inside it to maintain a kind of structure
that can describe the unseen world. The state of the agent can be updated by
gaining information about how the world evolves and how the agent's action
affects the world.
Example: A vacuum cleaner that uses sensors to detect dirt and obstacles and
moves and cleans based on a model.
13 / 29
Goal-Based Agents
This type takes decisions on the basis of its goal or desirable situations so that
it can choose such an action that can achieve the goal required. It is an
improvement over model-based agents where information about the goal is
also included. This is because it is not always sufficient to know just about the
current state, knowledge of the goal is a more beneficial approach.
The aim is to reduce the distance between action and the goal so that the best
possible way can be chosen from multiple possibilities. Once the best way is
found, the decision is represented explicitly which makes the agent more
flexible.
Utility-Based Agents
The Utility-Based Agents are similar to the Goal-Based Agents. There are
multiple sequences in which a goal state can be achieved. Some sequences
may be better than the others. The success or failure of this agent depends on
the choice of the appropriate route taken to reach the goal.
The difference in Goal-Based and Utility-Based Agents lies in the fact that
Goal-Based Agents only measure if a state can be a possible goal state or not.
But the Utility-Based Agents keep a measure of the desirability
(preference/utility) of these multiple routes to reach the goal state. This
measure is kept by a utility function. The utility function maps a state with a
real number which describes the happiness degree of the agent.
14 / 29
output. Hence these agents involve a great deal of perception, reasoning,
learning, and representation.
Learning Agents
As the name suggests, a learning agent has the capability to learn from its
past experiences. It starts its working in unknown environments by using its
basic knowledge and then it automatically adapts to the environment through
its learning process to reach its goal.
Evaluation Function
The evaluation function, ( f(x) ), for the greedy best-first search algorithm is
the following:
[ f(x) = h(x) ]
Here, the evaluation function is equal to the heuristic function. Since this
search disregards edge weights, finding the lowest-cost path is not
guaranteed.
Heuristic Function
1. Initialize a tree with the root node being the start node in the open list.
16 / 29
2. If the open list is empty, return a failure, otherwise, add the current
node to the closed list.
3. Remove the node with the lowest ( h(x) ) value from the open list for
exploration.
4. If a child node is the target, return a success. Otherwise, if the node has
not been in either the open or closed list, add it to the open list for
exploration.
A* Search
A* Search is an informed best-first search algorithm that efficiently
determines the lowest cost path between any two nodes in a directed
weighted graph with non-negative edge weights. This algorithm is a variant of
Dijkstra’s algorithm. A slight difference arises from the fact that an evaluation
function is used to determine which node to explore next.
Evaluation Function
The evaluation function, ( f(x) ), for the A* search algorithm is the following:
[ f(n) = g(n) + h(n) ]
Where ( g(n) ) represents the cost to get to node ( n ) and ( h(n) ) represents
the estimated cost to arrive at the goal node from node ( n ). For the
algorithm to generate the correct result, the evaluation function must be
admissible, meaning that it never overestimates the cost to arrive at the goal
node.
Steps
17 / 29
A closed list which stores the nodes that have already been evaluated.
When a node is in the closed list, it means that the lowest-cost path to
that node has been found.
To find the lowest cost path, a search tree is constructed in the following way:
1. Initialize a tree with the root node being the start node ( S ).
2. Remove the top node from the open list for exploration.
3. Add the current node to the closed list.
4. Add all nodes that have an incoming edge from the current node as
child nodes in the tree.
5. Update the lowest cost to reach the child node.
6. Compute the evaluation function for every child node and add them to
the open list.
Just like in Dijkstra’s algorithm, the lowest cost is updated as the algorithm
progresses in the following way:
[ \text{current_lowest_cost} = \min(\text{current_lowest_cost},
\text{parent_node_cost} + \text{edge_weight}) ]
All nodes except for the start node start with a lowest cost of infinity. The
start node has an initial lowest cost of 0. The algorithm concludes when the
goal node ( G ) is removed from the open list and explored, indicating that a
shortest path has been found. The shortest path is the path from the start
node ( S ) to the goal node ( G ) in the tree.
Note: The algorithm ends when the goal node ( G ) has been explored, NOT
when it is added to the open list.
Decision Trees
A decision tree is a type of supervised machine learning used to categorize or
make predictions based on how a previous set of questions were answered.
The model is a form of supervised learning, meaning that the model is
trained and tested on a set of data that contains the desired categorization.
18 / 29
Root node: The base of the decision tree.
Splitting: The process of dividing a node into multiple sub-nodes.
Decision node: When a sub-node is further split into additional sub-
nodes.
Leaf node: When a sub-node does not further split into additional sub-
nodes; represents possible outcomes.
Pruning: The process of removing sub-nodes of a decision tree.
Branch: A subsection of the decision tree consisting of multiple nodes.
Disadvantages
1. Entropy
Entropy basically tells us how impure a collection of data is. The term impure
here defines non-homogeneity. In other words, we can say, “Entropy is the
measurement of homogeneity. It returns us the information about an
arbitrary dataset that how impure/non-homogeneous the dataset is". Entropy
controls how a Decision Tree decides to split the data.
19 / 29
Learning from Examples
An agent is learning if it improves its performance on future tasks after
making observations about the world.
Forms of Learning
Supervised Learning
Supervised learning is a learning method in which a model learns from a
labeled dataset containing input-output pairs. Each input in the dataset has a
corresponding correct output (the label), and the model's task is to learn the
relationship between the inputs and outputs. This enables the model to make
predictions on new, unseen data by applying the learned mapping.
Predicting house prices: The input might be house features such as size,
location, and number of bedrooms, and the output would be the house price.
The supervised learning model would learn the relationship between these
features and house prices from historical data, and then it could predict
prices for new houses entering the market.
20 / 29
such as the Simple Linear Regression Algorithm, Multivariate
Regression Algorithm, Decision Tree Algorithm, and Lasso Regression.
Classification: In instances where the output variable is a category,
like distinguishing between 'spam' and 'not spam' in email filtering,
several widely-used classification algorithms come into play. These
encompass the following algorithms: Random Forest, Decision Tree,
Logistic Regression, and Support Vector Machine.
21 / 29
Autonomous Vehicles: These are used to recognize traffic signs and
pedestrians.
Speech Recognition: In virtual assistants and transcription services.
Unsupervised Learning
In unsupervised learning, the agent learns patterns in the input even though
no explicit feedback is supplied. Unlike supervised learning, where the
training data includes both input vectors and corresponding target labels,
unsupervised learning algorithms try to learn patterns and relationships
directly from the input data.
22 / 29
No Need for Labeled Data: Works with unlabeled data, making it
useful where obtaining labels is expensive or impractical.
Reduction of Complexity in Data: Helps reduce the dimensionality of
data, making complex data more comprehensible.
Feature Discovery: This can be used to find useful features that can
improve the performance of supervised learning algorithms.
Flexibility: Can handle changes in input data or the environment since
it doesn’t rely on predefined labels.
Reinforcement Learning
In reinforcement learning, the agent learns from a series of reinforcements—
rewards or punishments. For example, the lack of a tip at the end of the
journey gives the taxi agent an indication that it did something wrong.
23 / 29
Example of Reinforcement Learning
24 / 29
Optimization: RL is geared towards optimization of the decision-
making process, aiming to find the best sequence of actions for any
given situation.
25 / 29
Ensemble Learning
Ensemble learning is a combination of several learning models in one
problem. These models are known as weak learners. The intuition is that
when you combine several weak learners, they can become strong learners.
Each weak learner is fitted on the training set and provides predictions
obtained. The final prediction result is computed by combining the results
from all the weak learners.
Max Voting
In classification, the prediction from each model is a vote. In max voting, the
final prediction comes from the prediction with the most votes.
Let’s take an example where you have three classifiers with the following
predictions:
Classifier 1 – class A
Classifier 2 – class B
Classifier 3 – class B
The final prediction here would be class B since it has the most votes.
Averaging
In averaging, the final output is an average of all predictions. This goes for
regression problems. For example, in random forest regression, the final
result is the average of the predictions from individual decision trees.
Let’s take an example of three regression models that predict the price of a
commodity as follows:
Regressor 1 – 200
Regressor 2 – 300
Regressor 3 – 400
The final prediction would be the average of 200, 300, and 400.
26 / 29
Weighted Average
In weighted averaging, the base model with higher predictive power is more
important. In the price prediction example, each of the regressors would be
assigned a weight. The sum of the weights would equal one. Let’s say that the
regressors are given weights of 0.35, 0.45, and 0.2 respectively. The final
model prediction can be computed as follows:
[ 0.35 \times 200 + 0.45 \times 300 + 0.2 \times 400 = 285 ]
27 / 29
Bagging (Bootstrap Aggregating)
28 / 29
Boosting
Boosting, on the other hand, aims to correct the errors made by previous
models sequentially. Unlike bagging, boosting assigns different weights to
each data point, emphasizing the misclassified ones. It trains weak models in
an iterative manner, where each model focuses on the samples that the
previous models struggled with. The final prediction is a weighted sum of the
individual model predictions.
29 / 29