Intro To AI
Intro To AI
Artificial Intelligence
What is AI?
• Artificial Intelligence is composed of two words Artificial and
Intelligence, where Artificial defines "man-made," and intelligence
defines "thinking power", hence AI means "a man-made thinking
power.<
• It is a branch of computer science by which we can create intelligent
machines which can behave like a human, think like humans, and able
to make decisions.
AI Definitions
• <Intelligence: The ability to learn and solve problems=
– Webster’s Dictionary.
• Human-Agent
• Robotic Agent
• Software Agent
• Sensor
• Actuators
• Effectors
Rules of AI Agent
• Rule 1: An AI agent must have the ability to perceive the
environment.
• Rule 2: The observation must be used to make decisions.
• Rule 3: Decision should result in an action.
• Rule 4: The action taken by an AI agent must be a rational
action.
Rational Agent
• 8 puzzles:
Real-world examples
• Route finding problem
• Traveling salesperson problem
• VLSI layout
• Robot navigation
• Automatic assembly sequencing
• Protein design
Search Algorithm Terminologies
• Search
– Search Space
– Start State
– Goal test
• Search tree
• Actions
• Transition model
• Path Cost
• Solution
• Optimal Solution
Properties of Search Algorithm
• Completeness
• Optimality
• Time Complexity
• Space Complexity
Types of search algorithms
• Uninformed/Blind Search:
– Breadth-first search
– Uniform cost search
– Depth-first search
– Iterative deepening depth-first search
– Bidirectional Search
• Informed Search
– Greedy Search
– A* Search
Uninformed Search Algorithms
• Uninformed search is a class of general-purpose search
algorithms which operates in brute force-way. Uninformed
search algorithms do not have additional information about
state or search space other than how to traverse the tree, so it
is also called blind search.
Types of uninformed search algorithms
• Breadth-first Search
Types of uninformed search algorithms
• Depth-first Search
Types of uninformed search algorithms
• Depth-Limited Search Algorithm
Types of uninformed search algorithms
• Uniform-cost Search Algorithm
Types of uninformed search algorithms
• Iterative deepening depth-first Search
Types of uninformed search algorithms
• Bidirectional Search Algorithm
Informed Search Algorithms
• Heuristics function: It is a function which is used in Informed
Search, and it finds the most promising path.
• h(n) <= h*(n) , Here h(n) is heuristic cost, and h*(n) is the
estimated cost. Hence heuristic cost should be less than or
equal to the estimated cost.
• Pure heuristic search is the simplest form of heuristic search
algorithms. It expands nodes based on their heuristic value
h(n).
Best first search algorithm
• Best-first Search Algorithm (Greedy Search) - Greedy best-
first search algorithm always selects the path which appears
best at that moment.
• f(n)= h(n), where h(n)= estimated cost from node n to the
goal.
• The greedy best first algorithm is implemented by the
priority queue
Best first search algorithm
• Step 1: Place the starting node into the OPEN list.
• Step 2: If the OPEN list is empty, Stop and return failure.
• Step 3: Remove the node n, from the OPEN list which has the lowest value
of h(n), and places it in the CLOSED list.
• Step 4: Expand the node n, and generate the successors of node n.
• Step 5: Check each successor of node n, and find whether any node is a
goal node or not. If any successor node is goal node, then return success
and terminate the search, else proceed to Step 6.
• Step 6: For each successor node, algorithm checks for evaluation function
f(n), and then check if the node has been in either OPEN or CLOSED list. If
the node has not been in both list, then add it to the OPEN list.
• Step 7: Return to Step 2.
Best first search algorithm
A* Search Algorithm
• A* search is the most commonly known form of best-first
search. It uses heuristic function h(n), and cost to reach the
node n from the start state g(n).
• Combines:
– g(n): cost to reach node n
– h(n): cost to get from n to the goal
– f(n) = g(n) + h(n)
A* Search Algorithm
• Step1: Place the starting node in the OPEN list.
• Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
• Step 3: Select the node from the OPEN list which has the smallest value of
evaluation function (g+h), if node n is goal node then return success and
stop, otherwise
• Step 4: Expand node n and generate all of its successors, and put n into
the closed list. For each successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
• Step 5: Else if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.
• Step 6: Return to Step 2.
A* Search Algorithm
A* Search Algorithm
Hill Climbing Algorithm
• Hill climbing algorithm is a local search algorithm which
continuously moves in the direction of increasing
elevation/value to find the peak of the mountain or best
solution to the problem.
• A node of hill climbing algorithm has two components which
are state and value.
• In this algorithm, we don't need to maintain and handle the
search tree or graph as it only keeps a single current state.
Features of Hill Climbing
• Generate and Test variant: Hill Climbing is the variant of
Generate and Test method. The Generate and Test method
produce feedback which helps to decide which direction to
move in the search space.
• Greedy approach: Hill-climbing algorithm search moves in the
direction which optimizes the cost.
• No backtracking: It does not backtrack the search space, as it
does not remember the previous states.
State-space Diagram
• Local Maximum
• Global Maximum
• Current state
• Flat local maximum
• Shoulder
Types of Hill Climbing Algorithm
• Simple Hill Climbing - It only evaluates the neighbor node state at a time and
selects the first one which optimizes current cost and set it as a current state.
• Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
• Step 2: Loop Until a solution is found or there is no new operator left to apply.
• Step 3: Select and apply an operator to the current state.
• Step 4: Check new state:
– If it is goal state, then return success and quit.
– Else if it is better than the current state then assign new state as a current
state.
– Else if not better than the current state, then return to step2.
• Step 5: Exit.
Types of Hill Climbing Algorithm
• Steepest-Ascent hill climbing – This algorithm examines all the
neighboring nodes of the current state and selects one neighbor node
which is closest to the goal state.
• Step 1: Evaluate the initial state, if it is goal state then return success and stop, else make
current state as initial state.
• Step 2: Loop until a solution is found or the current state does not change.
– Let SUCC be a state such that's any successor of the current state will be better than it.
– For each operator that applies to the current state:
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to the SUCC.
• If it is better than SUCC, then set new state as SUCC.
• If the SUCC is better than the current state, then set current state to SUCC.
• Step 5: Exit.
Types of Hill Climbing Algorithm
• Stochastic hill climbing
• Stochastic hill climbing does not examine for all its neighbor
before moving.
• Rather, this search algorithm selects one neighbor node at
random and decides whether to choose it as a current state or
examine another state.
Difference between Informed
and Uninformed Search in AI
Parameters Informed Search Uninformed Search
Known as It is also known as Heuristic Search. It is also known as Blind Search.
It uses knowledge for the searching It doesn’t use knowledge for the
Using Knowledge
process. searching process.
•Greedy Search
•Depth First Search (DFS)
•A* Search
Examples of Algorithms •Breadth First Search (BFS)
•AO* Search
•Branch and Bound
•Hill Climbing Algorithm
Adversarial Search
• Adversarial search is a search, where we examine the problem
which arises when we try to plan ahead of the world and
other agents are planning against us.
• The environment with more than one agent is termed as
multi-agent environment, in which each agent is an opponent
of other agent and playing against each other.
• Searches in which two or more players with conflicting goals
are trying to explore the same search space for the solution,
are called adversarial searches, often known as Games.
Types of Games in AI
• Perfect information
– Chess, Checkers, Go, etc.
• Imperfect information
– Tic-tac-toe, Battleship, blind, Bridge, etc.
• Deterministic games
– Checkers, Go, tic-tac-toe, etc.
• Non-deterministic games
– Backgammon, Monopoly, Poker, etc.
Zero-Sum Game
• Zero-sum games are adversarial search which involves pure
competition.
• Zero-sum game: Embedded thinking
• What to do.
• How to decide the move
• Needs to think about his opponent as well
• The opponent also thinks what to do
Zero-Sum Game
• Formalization of the problem:
– Initial state
– Player(s)
– Action(s)
– Result(s, a)
– Terminal-Test(s)
– Utility(s, p)
Example:
Tic-Tac-Toe game tree
• There are two players
MAX and MIN.
• Players have an alternate
turn and start with MAX.
• MAX maximizes the
result of the game tree
• MIN minimizes the result.
Mini-Max Algorithm in AI
• Mini-max algorithm is a recursive or backtracking algorithm
which is used in decision-making and game theory. It provides
an optimal move for the player assuming that opponent is also
playing optimally.
• Min-Max algorithm is mostly used for game playing in AI. Such
as Chess, Checkers, tic-tac-toe, go, and various two-players
game. This Algorithm computes the minimax decision for the
current state.
• The minimax algorithm performs a depth-first search
algorithm for the exploration of the complete game tree.
Working of Min-Max Algorithm
• Step 1: In the first step, the algorithm generates the entire game-
tree and apply the utility function to get the utility values for the
terminal states.
• Step 2: Now, first we find the utilities value for the Maximizer, its
initial value is -∞, so we will compare each value in terminal state
with initial value of Maximizer and determines the higher nodes
values.
• Step 3: In the next step, it's a turn for minimizer, so it will compare
all nodes value with +∞, and will find the 3rd layer node values.
• Step 4: Now it's a turn for Maximizer, and it will again choose the
maximum of all nodes value and find the maximum value for the
root node.
Properties of Mini-Max algorithm
• Complete
• Optimal
• Time complexity
• Space Complexity
• Gathering Data
– Identify various data sources
– Collect data
– Integrate the data obtained from different sources
• Data preparation
– Data exploration
– Data pre-processing
Machine Learning Life cycle
• Data Wrangling
– Missing Values
– Duplicate data
– Invalid data
– Noise
• Data Analysis
– Selection of analytical techniques
– Building models
– Review the result
Machine Learning Life cycle
• Train Model
– We train our model to improve its performance for better
outcome of the problem.
• Test Model
– We check for the accuracy of our model by providing a test
dataset to it.
• Deployment
– Where we deploy the model in the real-world system.
Supervised Machine Learning
• Supervised learning is the types of machine learning in which
machines are trained using well "labelled" training data, and
on basis of that data, machines predict the output.
• The aim of a supervised learning algorithm is to find a
mapping function to map the input variable(x) with the output
variable(y).
• In the real-world, supervised learning can be used for Risk
Assessment, Image classification, Fraud Detection, spam
filtering, etc.
Steps Involved in Supervised Learning
• First Determine the type of training dataset
• Collect/Gather the labelled training data.
• Split the training dataset into training dataset, test dataset, and validation
dataset.
• Determine the input features of the training dataset, which should have
enough knowledge so that the model can accurately predict the output.
• Determine the suitable algorithm for the model, such as support vector
machine, decision tree, etc.
• Execute the algorithm on the training dataset. Sometimes we need
validation sets as the control parameters, which are the subset of training
datasets.
• Evaluate the accuracy of the model by providing the test set. If the model
predicts the correct output, which means our model is accurate.
Types of supervised Machine learning Algorithms
• Regression algorithms are used if there is a relationship
between the input variable and the output variable. It is used
for the prediction of continuous variables, such as Weather
forecasting, Market Trends, etc.
• Classification algorithms are used when the output variable is
categorical, which means there are two classes such as Yes-No,
Male-Female, True-false, etc.
Advantages and
Disadvantages
• The model can predict the output on the basis of prior
experiences.
• We can have an exact idea about the classes of objects.
• Helps us to solve various real-world problems such as fraud
detection, spam filtering, etc.
• It is simple to implement.
• It is robust to the noisy training data
• It can be more effective if the training data is large.
• Root Node
• Leaf Node
• Splitting
• Branch/Sub Tree
• Pruning
• Parent/Child node
Working of Decision Tree
• Step-1: Begin the tree with the root node, says S, which contains
the complete dataset.
• Step-2: Find the best attribute in the dataset using Attribute
Selection Measure (ASM).
• Step-3: Divide the S into subsets that contains possible values for
the best attributes.
• Step-4: Generate the decision tree node, which contains the best
attribute.
• Step-5: Recursively make new decision trees using the subsets of
the dataset created in step -3. Continue this process until a stage is
reached where you cannot further classify the nodes and called
the final node as a leaf node.
Advantages & Disadvantages
• It is simple to understand as it follows the same process which a
human follow while making any decision in real-life.
• It can be very useful for solving decision-related problems.
• It helps to think about all the possible outcomes for a problem.
• There is less requirement of data cleaning compared to other
algorithms.
The goal of AI is to make a smart computer The goal of ML is to allow machines to learn
system like humans to solve complex from data so that they can give accurate
problems. output.
In AI, we make intelligent systems to perform In ML, we teach machines with data to
any task like a human. perform a particular task and give an accurate
result.
Machine learning and deep learning are the Deep learning is a main subset of machine
two main subsets of AI. learning.
AI has a very wide range of scope. Machine learning has a limited scope.
Difference between AI and ML