AI Updated Format Without Adv
AI Updated Format Without Adv
LAB WORKBOOK
18CS2206 ARTIFICIAL INTELLIGENCE
LABORATORY WORKBOOK
STUDENT NAME
REG. NO
YEAR
SEMESTER
SECTION
FACULTY
ORGANIZATION OF THE STUDENT LAB WORKBOOK
The laboratory framework includes a creative element but shifts the time-intensive aspects outside of the Two-Hour closed laboratory period.
Within this structure, each laboratory includes three parts: Prelab, In-lab, and Post lab.
A) Pre-Lab
The Prelab exercise is a homework assignment that links the lecture with the laboratoryperiod - typically takes 2 hours to complete. The
goalis tosynthesizethe information they learn in lecture with material from their textbook to produce a workingpiece of software. Prelab
Studentsattendinga two-hour closedlaboratory are expected to make a good-faith effort to complete the Prelab exercise before coming to
the lab. Their work need not be perfect, but their effort must be real (roughly 80 percentcorrect).
B) In-Lab
10
11
12
18CS2206 ARTIFICIAL INTELLIGENCE
Table of Contents
Organization of the STUDENT LAB WORKBOOK................................................................................. 2
Lab Session 01: A Simple Chatter Bot........................................................................................................ 5
Lab Session 02: Uninformed Search ....................................................................................................... 19
Lab Session 03: Travelling Salesman Problem........................................................................................ 26
Lab Session 04: Hill Climbing Method ................................................................................................... 38
Lab Session 05: Alpha Beta pruning........................................................................................................ 46
Lab Session 06:Hangman game .............................................................................................................. 55
Lab Session 07: Building Knowledge and reasoning ................................................................................ 62
Lab Session 08: First Order Logic ............................................................................................................ 70
Lab Session 09: Horn Clauses .................................................................................................................. 76
Lab Session 10: Basic Probability Notation .............................................................................................. 85
Lab Session 11: Quantifying uncertainty, Bayes Theorem ........................................................................ 92
Lab Session 12: Hidden Markov Model ................................................................................................. 101
Lab Session 13Case Study ...................................................................................................................... 106
4
18CS2206 ARTIFICIAL INTELLIGENCE
1A) Prateek is working on a project and he is slightly poor in mathematics. The project is based on
performing arithmetic and logical operations with numbers. So help him out by writing a Python program
that considers ‘a’ and ‘b’ as input and gives the result of all arithmetic & logical operations as output .Use
different modules for every operation.
Python code:
5
18CS2206 ARTIFICIAL INTELLIGENCE
6
18CS2206 ARTIFICIAL INTELLIGENCE
7
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
1 A) Jaswanth is doing a problem in which he has to calculate the LCM and HCF of given numbers. So help
him out by writing a Python code that return LCM and HCF values. Use different modules for both LCM
and HCF.
Python code:
8
18CS2206 ARTIFICIAL INTELLIGENCE
9
18CS2206 ARTIFICIAL INTELLIGENCE
10
18CS2206 ARTIFICIAL INTELLIGENCE
11
18CS2206 ARTIFICIAL INTELLIGENCE
1 B) You’re facing many issues with your laptop and you have no idea what’s happening to it .So you need
to send a request by having a conversation with the chat bot of the service company to fix this issue. Based
on the conversation, develop a python code to implement a simple chatter bot using functions (don’t use
modules and packages).For example, if you give “Hi” it must print “Hello”. For every iteration it must take
a new question as input and if you say “Bye”, the loop must be terminated.
12
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
1 A) The monthly challenge contest is going on in the code chef, an online coding platform. Ram and his
friends are participating in the contest. It is based on printing complex patterns. In order to complete that, he
must know the logic of Pascal’s triangle. So help him by writing a python code to generate a Pascal’s triangle
by taking a number n as an input and generating Pascal triangle with n+1 lines as output.
Python code:
13
18CS2206 ARTIFICIAL INTELLIGENCE
14
18CS2206 ARTIFICIAL INTELLIGENCE
15
18CS2206 ARTIFICIAL INTELLIGENCE
16
18CS2206 ARTIFICIAL INTELLIGENCE
1 B) Shruthi is assigned to develop a intelligent agent(like a chatterbot) for the addition of two integers
provided the agent must follow some conditions: the agent work will start with reflex to greeting from user
and continues in his state(prime work addition of two numbers) until user provide agent with stop option.
Python code:
17
18CS2206 ARTIFICIAL INTELLIGENCE
18
18CS2206 ARTIFICIAL INTELLIGENCE
2 A) Laxmi is a delivery agent in Flipkart currently being at Arad. He must travel to deliver an order in
Bucharest but he has only limited amount of petrol in his vehicle. So he has to find the shortest distance from
Arad to Bucharest. Analyze the below diagram and give a prototype of the shortest path.
19
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
2 A) A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a pump which has
unlimited water which you can use to fill the jug, and the ground on which water may be poured. Neither jug
has any measuring markings on it. How can you get exactly 2 gallons of water in the 4-gallon jug?
Let X represent the content of the water in 4-gallon jug.
Let Y represent the content of the water in 3-gallon jug.
Write a program in python to define a set of operators (Rules) that will take us from one state to another:
Start from initial state (X=0, Y=0)
Reach any of the Goal states
(X=2, Y=0)
(X=2, Y=1)
(X=2, Y=2)
(X=2, Y=3)
Find the minimum number of steps to reach any the above mentioned goal states.
20
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem:(For Student’s use only)
21
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
2 A) Solve the same problem using three jugs, a 12-litre,8-litre and a 3-litre .Write a python program to
exactly 1 litre of water.
22
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem:(For Student’s use only)
23
18CS2206 ARTIFICIAL INTELLIGENCE
24
18CS2206 ARTIFICIAL INTELLIGENCE
25
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
3 A) Describe a state space with 5 states, where the number of nodes visited by iterative deepening search
(including the start node) is S5. Where states include S1,S2,S3,S4,S5 where S1 is a root node.
26
18CS2206 ARTIFICIAL INTELLIGENCE
3 B) For the following tree, show the order of nodes visited for breadth-first search, depth-first search,
uniform cost search, and iterative deepening search. The goal node is I and the numbers next to the edges
indicate the associated cost.
Answer:
27
18CS2206 ARTIFICIAL INTELLIGENCE
A. The algorithm starts at the root (assume any node as root node) node and explores as far as
possible along each branch before backtracking.
B. The algorithm starts at the tree root (root node) and explores all of the neighbor nodes at the
present depth prior to moving on to the nodes at the next depth level
28
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
3 A) There is a sales rep who goes around N urban communities. He needs to visit each city once. The
request for city doesn't make a difference. To head out to a specific city, he needs to cover certain separation.
The sales rep needs to travel each city exactly once and come back to his very own territory. He wishes to
travel keeping the separation as low as could be allowed, with the goal that he could limit the expense and
time factor at the same time. Use the graph given below and write a Python program to satisfy the given
conditions.
29
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem:(For Student’s use only)
30
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem:(For Student’s use only)
31
18CS2206 ARTIFICIAL INTELLIGENCE
3 B) Write a program to find the Sum of Manhattan distances between all pairs of points using BFS. The
idea is to use Greedy Approach. First observe, the Manhattan formula can be decomposed into two
independent sums, one for the difference between x coordinates and the second between y coordinates. If we
know how to compute one of them we can use the same method to compute the other.
32
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
3 A) Write a python code to implement Breadth-First Search by considering the following graphs?
a. b.
A A
B C
B C D
D E F
E F G H
33
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
34
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
35
18CS2206 ARTIFICIAL INTELLIGENCE
3 B) There is enthusiastic traveler who visits different cities in his country. There are a total of N cities
numbered from 1 to N. Some cities are connected to each other as well by bidirectional bridges running
over water. He hates to cross those bridges as travelling via transport is expensive. He is standing at city 1
and wants to reach the city N. Find the minimum the number of bridges that he shall have to cross, if he
takes the optimal route.
36
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: (For Student’s use only)
Evaluator:
37
18CS2206 ARTIFICIAL INTELLIGENCE
Pre-requisite:
1. A study on Local search Algorithms.
2. Knowledge about heuristic function and generate and test algorithm
3. Knowledge About mathematical optimization problems
PRE LAB:
4 A) Solve the following block world diagram using hill climbing search
A D
D C
C B
B A
--------- -----------
Initial state Goal state
38
18CS2206 ARTIFICIAL INTELLIGENCE
39
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
4 A) Write a program to solve the following blocks world problem using DFS.
A D
D C
C B
B A
--------- -----------
Initial state Goal state
40
18CS2206 ARTIFICIAL INTELLIGENCE
4 B) Mahesh is a Business man in Vijayawada. He is planning to construct 4 buildings in his land of 1000
acres. He divided his land into 16 plots each of 62.5 acres. He wants his engineers to build those buildings
based on the following restrictions:
None of the buildings should be in
i) Same row
ii) Same column
iii) And should not conflict diagonally(consider all possible diagonals)
Help his engineers to write a python program in order to find out in which plots they should construct those
4 buildings.
41
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
4 A) Write a Python code for the given graph, So that the graph should be colored with minimum number
of colors in which no two adjacent vertices are same?
B F
A G E
C D
42
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem:(For Student’s use only)
43
18CS2206 ARTIFICIAL INTELLIGENCE
44
18CS2206 ARTIFICIAL INTELLIGENCE
45
18CS2206 ARTIFICIAL INTELLIGENCE
Pre-requisite:
a. knowledge on Alpha-beta pruning and optimization problems
b. knowledge on Simulate annealing
c. knowledge on Genetic algorithm
PRE LAB:
5 A) The search which is equal to minimax search but eliminates the branches that can’t
influence the final decision. Specify which search it is and write an Algorithm to that
search
46
18CS2206 ARTIFICIAL INTELLIGENCE
5 B) One aspect of a simulated annealing cooling schedule is the temperature. Discuss the following:
a. What is the effect of having the starting temperature too high or too low?
b. How do you decide on a suitable starting temperature?
c. How do we decide on a final temperature?
47
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
5 A) Vinay is the CEO of a multinational company. He needs to recruit an undergraduate from KLU
dependent on specific qualities he needs to have for his employee. HOD gives him a rundown of 8 scores
dependent on character and academics test. He leads the 3 choice rounds dependent on conduct of
representative he needs. He partitions each into 2 individuals. First round he chooses the understudy having
max marks (communication aptitudes). Second Round he selects based on less no of missteps they have done.
In the last round he chooses an understudy dependent on high checks. Help him to plan a code to choose the
best undergraduate. (Note: The number of undergraduates must be in the number of 2 power of (n)).
48
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: (For Student’s use only)
49
18CS2206 ARTIFICIAL INTELLIGENCE
5 B) Jacob and Oliver are playing chess and it is Jacob's turn. Jacob have found a good move that will
improve his position. Denote this move as 'A'. He continues to look for moves, making sure he hasn't missed
an even better one. Jacob finds a move that appears to be good. Denote this move as 'B'. Jacob then realize
that the move 'B' allows his opponent Oliver to force checkmate in two moves. Thus, Jacob no longer need
to consider any other possible outcomes from playing move 'B', since Jacob know that his opponent can force
a win. Help Jacob to get his optimal move using alpha-beta pruning by using python code.
Tree = [[[5, 1, 2], [8, -8, -9]], [[9, 4, 5], [-3, 4, 3]]]
Root = 0
Pruned = 0
50
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: (For Student’s use only)
51
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
5 A) Alex and newt are playing a game with n stones where Alex always plays first. The two players move
in alternating turns and plays optimally. In a single move a player can remove either 1, 3 or 4 stones from
the pile of stones. If a player is unable to make a move then that player loses the game. Given the number of
stones where n is less than equal to 200, find and print the name of the winner
52
18CS2206 ARTIFICIAL INTELLIGENCE
5 B) Implement python code to perform alpha beta pruning on the following tree?
53
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
54
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
55
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
6 A) What is the search where we examine the problem which arises when we try to plan
ahead of the world and other agents are planning against us and write its algorithm and
provide a code as an example
56
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
6 A) Hangman is a classic word-guessing game. The user should guess the word correctly by entering
alphabets of the user choice. The Program will get input as single alphabet from the user and it will
matchmaking with the alphabets in the original word. If the user given alphabet matches with the alphabet
from the original word then user must guess the remaining alphabets. Once the user successfully found the
word he will be declared as winner otherwise user lose the game.
57
18CS2206 ARTIFICIAL INTELLIGENCE
58
18CS2206 ARTIFICIAL INTELLIGENCE
59
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
6 A) The following problems that can be solved using Constraint Satisfaction Problems (CSP):
60
18CS2206 ARTIFICIAL INTELLIGENCE
61
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
62
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
7 A) What is the order of precedence in propositional logic in AI?
63
18CS2206 ARTIFICIAL INTELLIGENCE
64
18CS2206 ARTIFICIAL INTELLIGENCE
65
18CS2206 ARTIFICIAL INTELLIGENCE
66
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
7 A) Write a python code for the following inference rules and facts such that the inference engine
generates a list. Implement the code by using Forward Chaining.
Seed (A) ==> Plant (A).
Plant (A) ==> Fruit (A).
Plant (A), Eating (A) ==> Human (A).
Plant ("Mango").
Eating ("Mango").
Seed ("Sprouts").
Code:
67
18CS2206 ARTIFICIAL INTELLIGENCE
68
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
7 A) After teacher explained about inference topic in propositional logic topic, then sita gave these
problems to her friend to test her capability. Help her to solve the problems.
1. “If I eat spicy foods, then I have strange dreams.” “I have strange dreams if there is thunder while I
sleep.” “I did not have strange dreams.”
2. “I am dreaming or hallucinating.” “I am not dreaming.” “If I am hallucinating, I see elephants
running down the road.”
69
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: ( For Student’s use only)
70
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
8 A) Write short notes on knowledge based agent with its architecture, and write the two functions of KB
agent. Give the simple algorithm on its functionality.
71
18CS2206 ARTIFICIAL INTELLIGENCE
72
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
8 A) We have an example, you might "know" that "all men are mortal", as in for all(x) (man(x) implies
mortal(x)). Then if you ask a question "is Jung Kook mortal" as mortal (Jung Kook)? You are supposed to
write an algorithm to unify that with the rule to get a new question "is Jung Kook a man" man (Jung Kook)?
Use this concept to write a python program to solve this.
73
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: ( For Student’s use only)
74
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
8 A) Write a python to check satisfiability of a propositional sentence. Returns a model when it succeeds.
Returns {true: true} for trivially true expressions. On setting all models to True, if given expr is satisfiable
then returns a generator of models. However, if expr is unsatisfiable then returns a generator containing the
single element False. (Use SYMPY)
75
18CS2206 ARTIFICIAL INTELLIGENCE
76
18CS2206 ARTIFICIAL INTELLIGENCE
9 A) What is Horn form, can all the proportional logics can convert to Horn form? Explain KB in Horn
normal form? How efficient the inferences in the HNF write propositional symbols can be?
77
18CS2206 ARTIFICIAL INTELLIGENCE
77
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
9 A) A, B, C, D and E are five thief’s living on different floors of an apartment consisting of only 5 floors.
They escaped from the police and hiding in the same building. The police caught them but they don’t know
in which floor they are in.
Here are some clues (Problem statements) to find them:
A does not live on the top floor.
B does not live on the bottom floor.
C does not live on either the top or the bottom floor.
D lives on a higher floor than does B.
E does not live on a floor adjacent to C.
C does not live on a floor adjacent to B.
Write a python code to help the policeman to find out where does everyone live?
78
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: ( For Student’s use only)
79
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
Problem 1:
What new facts can be inferred using forward chaining? (You should explain how facts are combined with
the rules to get new facts; e.g.
Combining rule 13 with facts 1 and 5 under the substitution X=Philip, Y=Charles, Z=William gives the
new fact
17. Grandparent (Philip, William).
You should not trace through the algorithms given in pseudo-code in the class notes.)
80
18CS2206 ARTIFICIAL INTELLIGENCE
81
18CS2206 ARTIFICIAL INTELLIGENCE
Problem 2:
Show how backward chaining can be used to prove the goals:
(A) grandfather (Philip, harry).
(B) Ancestor (Elizabeth, William).
82
18CS2206 ARTIFICIAL INTELLIGENCE
83
18CS2206 ARTIFICIAL INTELLIGENCE
84
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
10 A) Consider the set of all possible five-card poker hands dealt fairly from a standard deck of fifty-two
cards.
How many atomic events are there in the joint probability distribution (i.e., how many five-card hands
are there)?
What is the probability of each atomic event?
What is the probability of being dealt a royal straight flush? Four of a kind?
85
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
86
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
10 A) Choosing to put our insight into likelihood to great use, we experience an opening machine with three
freely turning reels, each creating one of the four images BAR, BELL, LEMON, or CHERRY with equivalent
likelihood. The space machine has the accompanying payout plot for a wager of 1 coin (where "?" indicates
that we couldn't care less what comes up for that wheel):
BAR/BAR/BAR pays 21 coins
BELL/BELL/BELL pays 16 coins
LEMON/LEMON/LEMON pays 5 coins
CHERRY/CHERRY/CHERRY pays 3 coins
CHERRY/CHERRY/? pays 2 coins
CHERRY/?/? pays 1 coin
Gauge the mean and middle number of plays you can hope to make until you become penniless, in the event
that you start with 8 coins. You can run a recreation to evaluate this, as opposed to attempting to process a
precise answer. Implement a python code for it.
87
18CS2206 ARTIFICIAL INTELLIGENCE
88
18CS2206 ARTIFICIAL INTELLIGENCE
10 B) Implement python program to find the probability of drawing a card that is a Heart, a face card (such
as Jacks, Queens, or Kings), or a combination of both, such as a Queen of Hearts
89
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
10 A) Let us assume the weather conditions in Vijayawada ( i.e. state space) as {S,R}.let us assume the
probability of being sunny and continue to be sunny is 0.3,the probability of changing whether from sunny
to rainy is 0.5,sudenly the whether changes then the probability of being rainy is 0.7 and the probability of
changing whether from rainy to sunny is 0.2.The above data can be represented in transition matrix as shown
below:
S R
S 0.3 0.5
R 0.2 0.7
Assuming the transition matrix does not change, write the python code for finding the probability of being
sunny or rainy at the end of 1st, 2nd and 3rd hours and also represent the transition matrix diagrammatically.
90
18CS2206 ARTIFICIAL INTELLIGENCE
91
18CS2206 ARTIFICIAL INTELLIGENCE
Lab Session 11: Quantifying uncertainty, Bayes Theorem
Date of the Session: / / Time of the Session: to
PRE LAB:
11 A) Write a short note on Uncertainty, reasons for uncertainty
92
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
93
18CS2206 ARTIFICIAL INTELLIGENCE
11 B) Sravan wants to go movie this weekend. His neighbour Rohan (is the one Sravan was hoping to ask
out since long time) is also planning to go to the movie this weekend. The probability that it will rain this
weekend is p1. There are two possible ways to reach the movie spot (bus or train). The probability that Sravan
will take the bus is p2 and that Rohan will take the bus is p3. Travel plans of both are independent of each
other and rain. What is the probability prs that Sravan and Rohan meet each other only (should not meet in
bus or train) in a setup (on a home in rain)?
94
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
11 A) The top is PC Computer A, the following 2 are Computer B and C, and the last 4 are Computer BD,
BE, and CD, CE. You are attempting to discover the likelihood that if PC A gets tainted with an infection
what is the likelihood that B or C gets contaminated with an infection. What's more, if B or C gets tainted
what is the likelihood that BD, BE, CD, CE gets contaminated with a virus. You need to run 100 preliminaries
to discover the appropriate response.
aa
ab cc
95
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem: (For Student’s use only)
96
18CS2206 ARTIFICIAL INTELLIGENCE
11 B) Consider a human population that may or may not have cancer (Cancer is True or False) and a medical
test that returns positive or negative for detecting cancer (Test is Positive or Negative), e.g. like a
mammogram for detecting breast cancer. If a randomly selected patient has the test and it comes back
positive, what is the probability that the patient has cancer? Implement a python program to demonstrate
Bayes theorem for the above one .you have provided with the following information.
Sensitivity: 85% of people with cancer will get a positive test result.
Base Rate: 0.02% of people have cancer.
Specificity: 95% of people without cancer will get a negative test result
97
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
98
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
11 A) Jug head is in a carnival and he decided to play a game show, where he is given the choice of three
doors: behind one door is a car; behind the others, goats. he need to choose one door—say, number 1—and
the host (who knows what's behind the doors) opens another door—say number 3—which has a goat behind
it. He is then allowed to stick with the door he picked, or choose the other one—number 2 in the example.
Now you need to write a python program to calculate the probability to win for the both cases (switching the
chosen door and stick to the chosen door) and help jug head to choose the door which has the maximum
probability to win.
99
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
100
18CS2206 ARTIFICIAL INTELLIGENCE
PRE LAB:
12 A) What is HMM (Hidden Markov Model)? What is hidden it? Draw a state diagram for HMM as
general case and show how you can write a transition matrix?
101
18CS2206 ARTIFICIAL INTELLIGENCE
IN LAB:
12 A) Sravan has to go airport on time in morning. His general mode of transport is by car and on a regular
day (no car trouble) the probability that he will reach on time is p1. The probability that he might have car
trouble is p2. If the car runs into trouble he will have to take a train and only 2 trains out of the available N
trains will get him to office on time.
Inputs are p1, p2, N
102
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
103
18CS2206 ARTIFICIAL INTELLIGENCE
POST LAB:
12 A) Write a Python program to implement Kalman filtering to track the position x and velocity v of an
aircraft.
Consider the initial observations as follows
X observations = [4000, 4260, 4550, 4860, 5110]
V observations = [280, 282, 285, 286, 290]
Hint: Eliminate the off-diagonal values for simplification.
104
18CS2206 ARTIFICIAL INTELLIGENCE
Writing space for the Problem :( For Student’s use only)
105
18CS2206 ARTIFICIAL INTELLIGENCE
CASE STUDY
CO-1
Natural language processing (NLP) is one of the most promising fields of artificial
intelligence that uses natural languages to enable human interactions with machines
There are two principles ways to deal with NLP:
1) Rule-based techniques,
2) Statistical methods, i.e., methods related to machine learning.
There are a few energizing Python libraries for NLP, for example, Natural Language Toolkit
(NLTK), spaCy, TextBlob, and so forth.
A chatbot is a PC programming ready to cooperate with people utilizing a characteristic
language. They usually rely on machine learning, especially on NLP. Apple's Siri, Amazon's
Alexa, Google Assistant, and Microsoft's Cortana are some notable instances of
programming ready to process characteristic dialects.
This article tells the best way to make a straightforward chatbot in Python utilizing the
library ChatterBot. Our bot will be utilized for casual discussion, just as to respond to some
math questions. Here, we'll start to expose what's conceivable in building custom chatbots
and NLP when all is said in done.
CO-2
Consider a game which has 4 final states and paths to reach final state are from root to 4
leaves of a perfect binary tree as shown below. Assume you are the maximizing player and
you get the first chance to move, i.e., you are at the root and your opponent at next level.
Which move you would make as a maximizing player considering that your opponent also
plays optimally?
EXPLANATION:
In Minimax the two players are called maximizer and minimizer. The maximizer tries to get
the highest score possible while the minimizer tries to do the opposite and get the lowest
score possible.
there are only two choices for a player. In general, there can be more choices. In that case, we
need to recur for all possible moves and find the maximum/minimum.
106
18CS2206 ARTIFICIAL INTELLIGENCE
CO-2
Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game
for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who
succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the
game.
For Tic-tac-toe, the rules, in the order of importance, are:
Rule 1: If I have a winning move, take it.
Rule 2: If the opponent has a winning move, block it.
Rule 3: If I can create a fork (two winning ways) after this move, do it.
Rule 4: Do not let the opponent creating a fork after my move. (Opponent may block your
winning move and create a fork.)
Rule 5: Place in the position such as I may win in the most number of possible ways.
Rule 1 and 2 can be programmed easily. Rule 3 is harder. Rule 4 is even harder because you
need to lookahead one opponent move, after your move. For rule 5, you need to count the
number of possible winning ways.
In order to solve Tic Tac Toe, we need to go deeper than just to think about it as a game
where two players place X’s and O’s on the board. Formally speaking, Tic Tac Toe is a zero-
sum and perfect information game. It means that each participant’s gain is equal to the other
participants’ losses and we know everything about the current game state.
You can think of the minimax algorithm as a representation of the human thought process
of saying, “OK, if I make this move, then my opponent can only make two moves, and each
of those would let me win. So this is the right move to make.”
As a artificial intelligence creator you have ability to understand and study the algorithm and
proceed with the implementation of the game in python.
107
18CS2206 ARTIFICIAL INTELLIGENCE
CO-4
Consider the names “John” and “Cindy” — most people would instantly mark John as a
male name and Cindy as a female one. Is this the case primarily because we have seen so
many examples of male Johns and female Cindys that our brains have built up a latent
association between the specific name and the corresponding gender? Probably.But some
component of the name itself (its spelling / combination of letters) contributes to the gender
with which it is associated to a large degree as well. Consider the names “Andy” and “Andi.”
They are phonetically identical (/ˈæn.di/), however most people would categorize “Andy”
as male and “Andi” as female upon seeing the spellings. The suffix of a name can indicate
the name’s gender; however, the rules are not cut and dry. For example, names “ending in -
yn appear to be predominantly female, despite the fact that names ending in -n tend to be
male; and names ending in -ch are usually male, even though names that end in -h tend to
be female”. There are many more character patterns that correspond to a certain gender
classification than just the suffix — this task is not trivial.
The gender classification of a name becomes increasingly difficult when you consider the
space of all names from around the world.
Accurate prediction of an unknown individual’s gender is desirable for use in marketing,
social science, and many other applications in academia and industry. Perhaps the most
obvious and telling indicator of a person’s gender is their first name. Most previous work in
classifying gender via first name has concerned using a large corpus of known names to give
a probabilistic prediction on the names that are known. This post attempts to explore the
space of names that are unknown by examining the facets of a first name — specifically
focusing on the sequences of characters within the name — that contain non-trivial gender-
revealing information. It is also an exercise in applying ML/DL to real problems.
It's been a challenge to implement good gender classification agent with good accuracy rate.
Our work is to find some algorithm or network to implement classification of gender for the
given list of names. We can implement the agent with python by using open source libraries
like pandas,numpy etc...
108