INTRODUCTION TO AI
AND PRODUCTION
SYSTEM
ARTIFICIAL INTELLIGENCE
It is the study of how to make computers do things at which, at the moment,
people are better.
The term AI is defined by each author in own ways which falls into 4 categories
1. The system that think like humans.
2. System that act like humans.
3. Systems that think rationally.
4. Systems that act rationally.
SOME DEFINITIONS OF AI
Building systems that think like humans
―The exciting new effort to make computers think … machines
with minds, in the full and literal senseǁ -- Haugeland, 1985
―The automation of activities that we associate with human
thinking, … such as decision-making, problem solving, learning, …ǁ
-- Bellman, 1978
Building systems that act like humans
―The art of creating machines that perform functions that
require intelligence when performed by peopleǁ -- Kurzweil,
1990
―The study of how to make computers do things at which, at
the moment, people are betterǁ -- Rich and Knight, 1991
● Artificial Intelligence (AI) is a branch of computer science that
focuses on creating systems capable of performing tasks that
usually require human intelligence.
● These tasks include problem-solving, learning, understanding
natural language, recognizing patterns, and making decisions.
● AI aims to create machines that can mimic cognitive functions
such as learning from experience and adapting to new
situations.
Problem formulation
Problem formulation is a critical step in AI where a real-world problem is
translated into a format that can be solved using computational methods.
This process involves defining the problem clearly, specifying the inputs, outputs,
and the relationship between them, and identifying the constraints and
objectives.
Chess Playing AI
Problem Definition
Create an AI system capable of playing chess at a competitive level.
Inputs
● The current state of the chessboard.
● The rules of chess.
● The history of moves made during the game.
Outputs
● The next best move for the AI to make.
Constraints
● The AI must adhere to the rules of chess.
● The AI must make a move within a reasonable amount of time (e.g., less than 10
seconds per move).
Objectives
● To maximize the chances of winning the game.
● To minimize the chances of making errors or illegal moves.
Try how tic tac toe game
Problem definition
To build a system to solve a particular problem do four things
1. Define the problem precisely: ie initial situation and final situation
2. Analyze the problem:
3. Isolate and represent the task knowledge that is necessary to solve the
problem.
4. Choose the best problem solving technique.
Define the problem precisely: Create an AI chatbot to handle customer inquiries on
an e-commerce website, reducing response times and improving service quality.
Analyze the problem: Identify key tasks such as answering FAQs, providing product
recommendations, order tracking, handling complaints, and collecting feedback.
Isolate and represent the task knowledge: Gather data on common queries,
products, policies, and integrate NLP and machine learning capabilities.
Choose the best problem-solving technique: Use NLP for language
understanding, machine learning for recommendations, and integration tools for
real-time data access, alongside a user-friendly interface.
Production system
Production system is a mechanism that describes and performs the search process.
A production system consists of four basic components:
1. A set of rules of the form Ci → Ai where Ci is the condition part and Ai is the action part.
The condition determines when a given rule is applied, and the action determines what
happens when it is applied.
(i.e A set of rules, each consist of left side (a pattern) that determines the applicability of
the rule and a right side that describes the operations to be performed if the rule is applied)
Condition (C1): A pawn is on square (x, y) and the square (x, y+1) is empty.
Action (A1): Move the pawn from (x, y) to (x, y+1).
2. One or more knowledge databases that contain whatever
information is relevant for the given problem. Some parts of the
database may be permanent, while others may temporary and
only exist during the solution of the current problem. The
information in the databases may be structured in any appropriate
manner.
3. A control strategy that determines the order in which the rules are
applied to the database, and provides a way of resolving any conflicts
that can arise when several rules match at once.
Eg: If two rules are applicable (e.g., capturing an opponent's queen
vs. moving a pawn), the conflict resolution strategy might choose the
rule that captures the queen due to its higher material value.
4. A rule applier which is the computational system that implements the control
strategy and applies the rules.
In order to solve a problem
● We must first reduce it to one for which a precise statement can be given. This
can be done by defining the problem state space (start and goal states) and a set
of operators for moving that space.
● The problem can be solved by searching for a path through the space from the
initial state to a goal state.
● The process of solving the problem can be usefully modeled as a production
system.
Control strategies
By considering control strategies we can decide which rule to apply next during the process
of searching for a solution to problem.
The two requirements of good control strategy are that
It should cause motion: consider water jug problem, if we implement control strategy of
starting each time at the top of the list of rules, it will never leads to solution. So we need to
consider control strategy that leads to solution.
It should be systematic: choose at random from among the applicable rules. This strategy is
better than the first. It causes the motion. It will lead to the solution eventually. Doing like this
is not a systematic approach and it leads to useless sequence of operators several times
before finding final solution.
Heuristic Search
● Heuristics are criteria for deciding which among several alternatives
be the most effective in order to achieve some goal.
● Heuristic is a technique that improves the efficiency of a search
process possibly by sacrificing claims of systematic and
completeness. It no longer guarantees to find the best answer but
almost always finds a very good answer.
● Using good heuristics, we can hope to get good solution to hard
problems (such as travelling salesman) in less than exponential
time.
Problem characteristics
● Heuristic search is a very general method applicable to a large class of
problem.
● In order to choose the most appropriate method (or combination of
methods) for a particular problem it is necessary to analyze the problem
along several key dimensions:
1. Is the problem decomposable into a set of
independent smaller sub problems?
•Decomposable problems can be solved by the divide and-conquer technique.
•Use of decomposing problems:
-Each sub-problem is simpler to solve
-Each sub-problem can be handed over to a different processor. Thus can be solved in parallel
processing environment.
•There are non-decomposable problems. For example, Traveling salesman problem is non
decomposable.
Example: Suppose we want to solve the problem of computing the integral of the following
expression ∫(x2+ 3x + sin2x * cos2x) dx
2. Can solution steps be ignored or at least undone
if they prove to be unwise?
Example1 :( Ignorable): In theorem proving-(solution steps can be ignored)
•Suppose we have proved some lemma in order to prove a theorem and
eventually realized that lemma is no help at all, then ignore it and prove another
lemma.
•Can be solved by using simple control strategy.
Example2: (Recoverable):8 puzzle-(solution steps can be undone)
•8 puzzle: Objective is to rearrange a given initial configuration of eight numbered
tiles on 3 X 3 board (one place is empty) into a given final configuration (goal
state).
•Rearrangement is done by sliding one of the tiles into Empty Square.
Example3: (Irrecoverable): Chess (solution steps cannot be undone)
•A stupid move cannot be undone
•Can be solved by planning process
3. Is the knowledge Base consistent?
Example: Inconsistent knowledge:
Target problem: A man is standing 150 ft from a target. He plans to hit the target by shooting
a gun that fires bullets with velocity of 1500 ft/sec. How high above the target should he aim?
Solution:
•Velocity of bullet is 1500 ft./sec i.e., bullet takes 0.1 sec to reach the target.
•Assume bullet travels in a straight line.
•Due to gravity, the bullet falls at a distance (1/2) gt2= (1/2)(32)(0.1)2 = 0.16ft.
•So if man aims up 0.16 feet high from the target, then bullet will hit the target.
•Now there is a contradiction to the fact that bullet travel in a straight line because the bullet
in actual will travel in an arc. Therefore there is inconsistency in the knowledge used.
4. What is the role of knowledge?
•In Chess game, knowledge is important to constrain the search for a solution
otherwise just the rule for determining legal moves and some simple control
mechanism that implements an appropriate search procedure is required.
•Newspapers scanning to decide some facts, a lot of knowledge is required
even to be able to recognize a solution.
5.Is a good solution Absolute or Relative?
•In water jug problem there are two ways to solve a problem. If we
follow one path successfully to the solution, there is no reason to
go back and see if some other path might also lead to a solution.
Here a solution is absolute.
•In travelling salesman problem, our goal is to find the shortest
route. Unless all routes are known, the shortest is difficult to
know.
6. Does the task Require Interaction with a Person?
• Solitary problem, in which there is no intermediate communication
and no demand for an explanation of the reasoning process.
Eg: An individual is solving a Sudoku puzzle.
• Conversational problem, in which intermediate communication is to
provide either additional assistance to the computer or additional
information to the user.
Eg: A user interacts with a virtual assistant to plan a trip.
7. Problem classification
• There is a variety of problem-solving methods, but there is no one single way of
solving all problems.
• Not all new problems should be considered as totally new. Solutions of similar
problems can be exploited.
Production system characteristics
Production systems are important in building intelligent matches which can provide
us a
good set of production rules, for solving problems.
There are four types of production system characteristics, namely
1. Monotonic production system
2. Non-monotonic production system
3. Commutative law based production system, and lastly
4. Partially commutative law based production system
Monotonic Production System (MPS):
The Monotonic production system (MPS) is a system in which the application of a
rule never prevents later application of the another rule that could also have been
applied at the time that the first rule was selected.
Eg: Scenario: Intelligent Personal Assistant
Rule 1: If it's a weekday morning, remind the user about their daily stand-up meeting.
Rule 2: If the user has a meeting and the weather forecast predicts rain, remind the
user to take an umbrella.
Rule 3: If the user has marked a task as urgent, prioritize notifications about this task.
Rule 4: If the user cancels the stand-up meeting, retract the reminder about the stand-up
meeting.
User Action: The user cancels the stand-up meeting.
● MPS Limitation: In an MPS, the system cannot retract the fact "Reminder about
stand-up meeting set."
● The system would continue to remind the user about the meeting, despite it
being canceled.
Non-monotonic Production (NMPS):
The non-monotonic production system is a system in which the application of a rule
prevents the later application of the another rule which may not have been applied at
the time that the first rule was selected, i.e. it is a system in which the above rule is
not true, i.e. the monotonic production system rule not true.
Eg: Scenario: Intelligent Personal Assistant
Rule 1: If it's a weekday morning, remind the user about their daily stand-up meeting.
Rule 2: If the user has a meeting and the weather forecast predicts rain, remind the user
to take an umbrella.
Rule 3: If the user has marked a task as urgent, prioritize notifications about this task.
Rule 4: If the user cancels the stand-up meeting, retract the reminder about the stand-up
meeting.
User Action: The user cancels the stand-up meeting.
● Action: Invalidate the reminder about the stand-up meeting.
● Retracted Fact: "Reminder about stand-up meeting set."
● New Fact: "Stand-up meeting canceled."
Applying Rule : The condition "The user cancels the stand-up meeting" is
true.
● Action: "Retract the reminder about the stand-up meeting."
3. Commutative Production System (CPS):
Commutative law based production systems is a system in which it satisfies both
monotonic & partially commutative.
AI-Based Medical Diagnosis System (CPS)
Rules
1. Rule 1: If fever and cough → Possible viral infection.
2. Rule 2: If fever and sore throat → Possible strep throat.
3. Rule 3: If headache and fever → Possible meningitis.
4. Rule 4: If rash and fever → Possible measles.
Initial Facts
● Fact 1: Patient has a fever.
● Fact 2: Patient has a cough.
● Fact 3: Patient has a sore throat.
● Fact 4: Patient has a headache.
Rule Application Sequences
Sequence 1
1. Apply Rule 1 → Possible viral infection.
2. Apply Rule 2 → Possible strep throat.
3. Apply Rule 3 → Possible meningitis.
Sequence 2
1. Apply Rule 3 → Possible meningitis.
2. Apply Rule 2 → Possible strep throat.
3. Apply Rule 1 → Possible viral infection.
Sequence 3
1. Apply Rule 2 → Possible strep throat.
2. Apply Rule 1 → Possible viral infection.
3. Apply Rule 3 → Possible meningitis.
Final Diagnosis
● Possible Diagnoses:
○ Viral infection
○ Strep throat
○ Meningitis
Partially Commutative Production System (PCPS):
The partially commutative production system is a system with the property that
if the application of those rules that is allowable & also transforms from state x
to state y.
In a PCPS, some rules can be applied in any order without affecting the final
outcome (commutative), while the order of applying other rules can affect the
final result (non-commutative).
Problem solving methods
Search techniques are the general problem solving methods. When there is a
formulated search problem, a set of search states, a set of operators, an initial state
and a goal criterion we can use search techniques to solve a problem.
Matching:
Problem solving can be done through search. Search involves choosing among the
rules that can be applied at a particular point, the ones that are most likely to lead to a
solution. This can be done by extracting rules from large number of collections.
Matching techniques are
Indexing:
1.In big problems large number of rules are used. Scanning through all of this
rules at every step of the search would be hopelessly inefficient.
2.It is not clearly visible to find out which condition will be satisfied.
Indexing is used to address the problems mentioned above.
Instead of searching through all the rules, the current state is used as an index to
select the matching rules.
This technique is especially useful in scenarios like chess game playing, where
the set of valid moves is large.
By identifying and storing only the useful moves, the applicability of all moves
can be avoided, making the matching process easier.
However, the indexing technique may lack generality in statement rules and is
not well-suited for rule bases with high-level predicates.
Heuristic functions
● Heuristic functions are strategies or methods that guide the search process
in AI algorithms by providing estimates of the most promising path to a
solution.
● They are often used in scenarios where finding an exact solution is
computationally infeasible. Instead, heuristics provide a practical approach
by narrowing down the search space, leading to faster and more efficient
problem-solving.
Hill climbing
Hill Climbing is an optimization algorithm in AI used to find the best solution from
a set of possible solutions.
Category: It is a local search algorithm.
Initial Solution: Starts with an initial solution.
Iterative Improvement: Makes small changes to improve the solution.
Heuristic Function: Evaluates the quality of each solution.
Local Maximum: Stops when no further improvement is possible.
It is based on local search algorithm, greedy approach, no backtracking
approach
Variations of Hill Climbing
1. Steepest Ascent Hill Climbing:
○ Evaluates all possible moves.
○ Selects the move with the best improvement.
2. First-Choice Hill Climbing:
○ Randomly selects a move.
○ Accepts the move if it leads to any improvement.
3. Simulated Annealing:
○ Probabilistically accepts worse moves.
○ Helps avoid getting stuck in local maxima.
Simple hill climbing algorithm
Step 1: Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
Step 2: Loop until a solution is found or until there are are no new operators
left to be applied in the current state:
(a) Select an operator that has not yet been applied to the current state and
apply it to produce a new state.
(b) Evaluate the new state.
(i) If it is a goal state, then return it and quit
(ii) If it is not a goal state but it is better than the current state, then
make it current state
(iii) If it is not better than the current state, then continue in the loop
Problems:
Local Maximum: The local maximum problem in the context of the hill climbing
algorithm refers to a situation where the algorithm reaches a solution that is
better than its immediate neighbors (i.e., it is a peak), but is not the best possible
solution in the overall search space (i.e., it is not the global maximum).
plateau/flat maximum: The plateau, or flat maximum, is another challenge in the
hill climbing algorithm. It occurs when the search space has regions where the
objective function has the same value for a contiguous set of solutions, forming
a "flat" area.
Depth first search algorithm
DFS explores a graph or tree structure by starting at the root (or any arbitrary node) and
exploring as far as possible along each branch before backtracking. This approach uses a stack
data structure.
stack(lifo)
Deepest node
Backtracking possible
Uninformed search technique: a search algorithm that explores a problem space without any
specific knowledge or information about the problem other than the initial state and the possible
actions to take.
Time complexity O(bd) b- branching factor; d- depth
Steps of Depth First Search
1. Start at the root node (or an arbitrary node in the case of a graph).
2. Mark the current node as visited.
3. Explore each adjacent node in turn by recursively applying the DFS
algorithm.
4. Backtrack to the previous node if a node has no unvisited adjacent nodes.
5. Repeat until all nodes have been visited or the desired goal node is found.
Example
1. Pathfinding in Mazes or Grids:
○ Imagine being trapped in a maze with confusing paths. DFS acts like a smart
guide, systematically exploring each path until finding the way out.
○ Example: Solving a maze by exploring one path at a time until reaching the exit.
2. Strongly Connected Components:
○ DFS helps find strongly connected components in directed graphs.
○ Example: Identifying interconnected communities in social networks.
3. Graph Traversal:
○ DFS helps explore graphs by selecting a path and going as deep as possible
before backtracking.
○ Applications: Topological sorting, cycle detection, and analyzing networks
○ Example: Traversing social networks to find connections between users.
○ https://brilliant.org/wiki/depth-first-search-dfs/
Breadth first search
In artificial intelligence, the Breadth-First Search (BFS) algorithm is an essential
tool for exploring and navigating various problem spaces.
By systematically traversing graph or tree structures, BFS solves tasks such as
pathfinding, network routing, and puzzle solving.
Steps of Breadth First Search
1. Start at the root node (or an arbitrary node in the case of a graph).
2. Mark the node as visited and add it to the queue.
3. While the queue is not empty:
○ Dequeue a node from the front of the queue.
○ For each adjacent node:
■ If the adjacent node has not been visited, mark it as visited and
enqueue it.
4. Repeat until all nodes have been visited or the goal node is found.
Example: Social Network Analysis
Friend Recommendations: BFS can be used to find the shortest path between individuals
in a social network, which can help in identifying mutual friends or suggesting new
connections.
https://github.com/MarcelRyan/sna-and-friend-recommendation-bfs
Influence and Reach: BFS helps analyze the influence of a user by exploring their
connections and the connections' connections, determining the reach of their social
influence.
Constraints satisfaction
The general problem is to find a solution that satisfies a set of constraints. The heuristics which are
used to decide what node to expand next and not to estimate the distance to the goal.
Constraints are conditions or limitations that restrict the behavior, design, or operation of a system. In
various contexts, constraints play a crucial role in defining what is feasible or permissible.
Examples of this technique are design problem, labeling graphs robot path planning and
cryptarithmetic puzzles.
In constraint satisfaction problems a set of constraints are available. This is the search space.
Initial State is the set of constraints given originally in the problem description. A goal state is any
state that has been constrained enough.
Propagation then occurs with this new constraint.
Constraint satisfaction is a two-step process.
1. First constraints are discovered and propagated throughout the system.
2. Then if there is not a solution search begins, a guess is made and added to
this constraint.
1. Propagate available constraints:
Open all objects that must be assigned values in a complete solution.
Repeat until inconsistency or all objects are assigned valid values:
Select an object and strengthen as much as possible the set of constraints that
apply to object.
If set of constraints different from previous set then open all objects that share
any of these constraints. Remove selected object.
2. If union of constraints discovered above defines a solution return
solution.
3. If union of constraints discovered above defines a contradiction
return failure.
4. Make a guess in order to proceed. Repeat until a solution is found or
all possible solutions exhausted:
Select an object with a no assigned value and try to strengthen its
constraints.
Recursively invoke constraint satisfaction with the current set of
constraints plus the selected strengthening constraint.
Heuristics Rules
1. If sum of two ̳n‘ digit operands yields ̳n+1‘ digit result then the ̳n+1‘th digit has
to be
one.
2. Sum of two digits may or may not generate carry.
3. Whatever might be the operands the carry can be either 0 or 1.
4. No two distinct alphabets can have same numeric code.
5. Whenever more than 1 solution appears to be existing, the choice is governed by
the fact
that no two alphabets can have same number code.
Example: Cryptarithmetic problems
1) A 2) A B 3) S E N D
A C B +MORE
+ A BB A MONEY
BA
http://cryptarithms.awardspace.us/puzzle02.html