6CS4 AI Unit-3@Zammers
6CS4 AI Unit-3@Zammers
(6CS4-05)
Unit III
Knowledge & Reasoning
BUILDING A
KNOWLEDGE
BASE
INTRODUCTION
a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number.
Following are some basic facts about
propositional logic:
•Propositional logic is also called Boolean logic as it works on
0 and 1.
•In propositional logic, we use symbolic variables to represent
the logic, and we can use any symbol for a representing a
proposition, such A, B, C, P, Q, R, etc.
•Propositions can be either true or false, but it cannot be both.
•Propositional logic consists of an object, relations or
function, and logical connectives.
•These connectives are also called logical operators.
Following are some basic facts about
propositional logic:
•The propositions and connectives are the basic elements of the propositional logic.
•A proposition formula which has both true and false values is called Statements
which are questions, commands, or opinions are not propositions such as "Where
is Rohini", "How are you", "What is your name", are not propositions.
Syntax of propositional logic:
Example:
a) "It is raining today, and street is wet."
b) "Ankit is a doctor, and his clinic is in Mumbai."
Logical Connectives:
Logical connectives are used to connect two simpler propositions or representing a sentence logically. We can create
compound propositions with the help of logical connectives. There are mainly five connectives, which are given as
follows:
Negation: A sentence such as ¬ P is called negation of P. A literal can be either Positive literal or negative literal.
Disjunction: A sentence which has ∨ connective, such as P ∨ Q. is called disjunction, where P and Q are the
propositions.
•First-order logic (like natural language) does not only assume that the world contains
facts like propositional logic but also assumes the following things in the world:
Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
Relations: It can be unary relation such as: red, round, is adjacent, or n-any
relation such as: the sister of, brother of, has color, comes between
Function: Father of, best friend, third inning of, end of, ......
•As a natural language, first-order logic also has two main parts:
Syntax
Semantics
Syntax of First-Order logic:
Variables x, y, z, a, b,....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences:
Atomic sentences are the most basic sentences of first-order
logic. These sentences are formed from a predicate symbol
followed by a parenthesis with a sequence of terms.
We can represent atomic sentences as Predicate (term1,
term2, ......, term n).
Example:
Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
Complex Sentences:
Example:
All man drink coffee.
It will be read as: There are all x where x is a man
who drink coffee.
∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables)
∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ eats(Anil, x) V eats(Harry, x)
∀x¬ [¬ killed(x) ] V alive(x)
∀x ¬ alive(x) V ¬ killed(x)
likes(John, Peanuts).
Move negation (¬)inwards and rewrite
∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables)
∀x ∀y ¬ eats(x, y) V killed(x) V food(y)
eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ eats(Anil, x) V eats(Harry, x)
∀x ¬killed(x) ] V alive(x)
∀x ¬ alive(x) V ¬ killed(x)
likes(John, Peanuts).
Rename variables or standardize variables
∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables)
∀y ∀z ¬ eats(y, z) V killed(y) V food(z)
eats (Anil, Peanuts) Λ alive(Anil)
∀w¬ eats(Anil, w) V eats(Harry, w)
∀g ¬killed(g) ] V alive(g)
∀k ¬ alive(k) V ¬ killed(k)
likes(John, Peanuts).
Eliminate existential instantiation quantifier by
elimination.
In this step we will drop all universal quantifier since all the statements are not implicitly
quantified so we don't need it.
¬ food(x) V likes(John, x)
food(Apple)
food(vegetables)
¬ eats(y, z) V killed(y) V food(z)
eats (Anil, Peanuts)
alive(Anil)
¬ eats(Anil, w) V eats(Harry, w)
killed(g) V alive(g)
¬ alive(k) V ¬ killed(k)
likes(John, Peanuts).
Distribute conjunction ∧ over disjunction ¬.
With Partial Order Planning, problems can be decomposed so it can work well with non-
cooperative environments. Thus, it is a plan which specifies all actions that need to be
taken, but only specifies the order between actions when necessary.
•A complete plan: Every precondition of every step is achieved by some other step.
To make this rule complete, we will have to list all the possible causes of toothache.
But this is not feasible due to:
•Laziness- It will require a lot of effort to list the complete set of antecedents and
consequents to make the rules complete.
•Theoretical ignorance- Medical science does not have complete theory for the
domain
•Practical ignorance- It might not be practical that all tests have been or can be
conducted for the patients.
Solution:
For example,
P(It will rain tomorrow| It is raining today) represents conditional probability of it
raining tomorrow as it is raining today.
P(A|B) + P(NOT(A)|B) = 1
Joint probability is the probability of 2 independent events happening simultaneously
like rolling two dice or tossing two coins together.
For example, Probability of getting 2 on one dice and 6 on the other is equal to 1/36.
Joint probability has a wide use in various fields such as physics, astronomy, and comes
into play when there are two independent events. The full joint probability distribution
specifies the probability of each complete assignment of values to random variables.
Bayes Theorem
It is based on the principle that every pair of features being classified is independent of
each other.
It calculates probability P(A|B) where A is class of possible outcomes and B is given
instance which has to be classified.
P(A|B) = P(B|A) * P(A) / P(B)
Where:
P(A|B) – the probability of event A occurring, given event B has occurred
P(B|A) – the probability of event B occurring, given event A has occurred
P(A) – the probability of event A
P(B) – the probability of event B
Fuzzy logic
Without the ability to reason we are doing little more than a lookup when we use
information.
In fact, this is the difference between a standard data base system and a knowledge base.
Both have information which can be accessed in various ways but the data base, unlike
the knowledge base in the expert system, has no reasoning facilities and can therefore
answer only limited specific questions.
example
•What are the types of reasoning we come across?
• How do we know what to expect when we go on a train journey? What do
we think when our friend is annoyed with us?
•How do we know what will happen if our car has a flat battery?
•Whether we are aware of it or not, we will use a number of different
methods of reasoning, depending on the problem we are considering and the
information that we have before us.
The three everyday situations mentioned above illustrate three key types of
reasoning which we use. In the first case we know what to expect on a train
journey because of our experience of numerous other train journeys. We
infer that the new journey will share common features with the examples.
example
We are aware of the first example called induction, which can be
summarised as generalisation from cases seen to infer information about
cases unseen.
We use it frequently in learning about the world around us. For example,
every crow we see is black; therefore we infer that all crows are black. If
we think about it, such reasoning is unreliable, we can never prove our
inferences to be true, we can only prove them to be false.
Take the crow again.
To prove that all crows are black we would have to confirm that all crows
which exist, have existed or will exist are black. This is obviously not
possible. However, to disprove the statement, all we need is to produce a
single crow which is white or pink.
example
So at best we can amass evidence to support our belief that all crows are
black. In spite of its unreliability inductive reasoning is very useful and is
the basis of much of our learning. It is used particularly in machine
learning.
This is abduction, the process of reasoning back from something to the state or event
which caused it.
Of course this too is unreliable; it may be possible that our friend is angry for some
other reason (perhaps we had promised to telephone him before coming to him but
had avoided).
Abduction can be used in cases where the knowledge is incomplete, Abduction can
provide a “best guess” given, the available evidence.
The third problem is usually solved by deduction: we have knowledge about cars
such as “if the battery is flat the headlights won’t work”; we know the battery is flat
so we can infer that the lights won’t work. This is the reasoning of standard logic.
Indeed, we would express our car problem in
terms of logic given that:
System Biology
Turbo Code
Spam Filter
Image Processing
Semantic Search
Information Retrieval
Document Classification
Biomonitoring
Medicine
Gene Regulatory Network
The 4 major Bayesian analytics disciplines are:
example:
It could address the probabilistic connections among
symptoms and diseases. Given symptoms, the network
can be utilized to register the possibilities of the
appearance of different illnesses.
BAYES THEOREM
Where,
C and D are sure events.
P(C) is the probability of occasion C happening.
P(C|D) is the conditional probability of occasion C
happening given that D has occurred.
P(D) is the probability of the occasion D happening.
P(D|C) is the conditional probability of occasion D
happening given that C has occurred.
BAYES THEOREM
“Events” Are different from “tests.” For example, there is a test for liver disease, but
that’s separate from the event of actually having liver disease.
Tests are flawed: just because you have a positive test does not mean you actually
have the disease. Many tests have a high false positive rate. Rare events tend to have
higher false positive rates than more common events. We’re not just talking about
medical tests here. For example, spam filtering can have high false positive rates.
Bayes’ theorem takes the test results and calculates your real probability that the test
has identified the event.
Bayes’ Theorem Example #1
You might be interested in finding out a patient’s probability of having liver disease if they
are an alcoholic. “Being an alcoholic” is the test (kind of like a litmus test) for liver disease.
A could mean the event “Patient has liver disease.” Past data tells you that 10% of patients
entering your clinic have liver disease. P(A) = 0.10.
B could mean the litmus test that “Patient is an alcoholic.” Five percent of the clinic’s
patients are alcoholics. P(B) = 0.05.
You might also know that among those patients diagnosed with liver disease, 7% are
alcoholics. This is your B|A: the probability that a patient is alcoholic, given that they have
liver disease, is 7%.
Bayes’ theorem tells you:
P(A|B) = (0.07 * 0.1)/0.05 = 0.14
In other words, if the patient is an alcoholic, their chances of having liver disease is 0.14
(14%). This is a large increase from the 10% suggested by past data. But it’s still unlikely
that any particular patient has liver disease.
Bayes’ Theorem Problems Example #2
Another way to look at the theorem is to say that one event follows another. Above I said “tests” and
“events”, but it’s also legitimate to think of it as the “first event” that leads to the “second event.” There’s no
one right way to do this: use the terminology that makes most sense to you.
In a particular pain clinic, 10% of patients are prescribed narcotic pain killers. Overall, five percent of the
clinic’s patients are addicted to narcotics (including pain killers and illegal substances). Out of all the people
prescribed pain pills, 8% are addicts. If a patient is an addict, what is the probability that they will be
prescribed pain pills?
Step 1: Figure out what your event “A” is from the question. That information is in the italicized part of
this particular question. The event that happens first (A) is being prescribed pain pills. That’s given as 10%.
Step 2: Figure out what your event “B” is from the question. That information is also in the italicized part
of this particular question. Event B is being an addict. That’s given as 5%.
Step 3: Figure out what the probability of event B (Step 2) given event A (Step 1). In other words, find
what (B|A) is. We want to know “Given that people are prescribed pain pills, what’s the probability they are
an addict?” That is given in the question as 8%, or .8.
Step 4: Insert your answers from Steps 1, 2 and 3 into the formula and solve.
P(A|B) = P(B|A) * P(A) / P(B) = (0.08 * 0.1)/0.05 = 0.16
The probability of an addict being prescribed pain pills is 0.16 (16%).
Example #3: the Medical Test
A slightly more complicated example involves a medical test (in this case, a
genetic test):
There are several forms of Bayes’ Theorem out there, and they are all
equivalent (they are just written in slightly different ways). In this next
equation, “X” is used in place of “B.” In addition, you’ll see some changes in
the denominator. The proof of why we can rearrange the equation like this is
beyond the scope of this article (otherwise it would be 5,000 words instead of
2,000!). However, if you come across a question involving medical tests,
you’ll likely be using this alternative formula to find the answer:
Example 3
1% of people have a certain genetic defect.90% of tests for the gene detect the defect (true positives).
9.6% of the tests are false positives.If a person gets a positive test result, what are the odds they
actually have the genetic defect?
The first step into solving Bayes’ theorem problems is to assign letters to events:
A = chance of having the faulty gene. That was given in the question as 1%. That also means the
probability of not having the gene (~A) is 99%.
X = A positive test result.
So:
P(A|X) = Probability of having the gene given a positive test result.
P(X|A) = Chance of a positive test result given that the person actually has the gene. That was given
in the question as 90%.
p(X|~A) = Chance of a positive test if the person doesn’t have the gene. That was given in the
question as 9.6%
Now we have all of the information we need to put into the equation:
P(A|X) = (.9 * .01) / (.9 * .01 + .096 * .99) = 0.0865 (8.65%).
The probability of having the faulty gene on the test is 8.65%.
Bayes’ Theorem Problems: Another Way to Look at
It.
Bayes’ theorem problems can be figured out without using the equation (although using the
equation is probably simpler). But if you can’t wrap your head around why the equation works
(or what it’s doing), here’s the non-equation solution for the same problem in #1 (the genetic test
problem) above.
Step 1: Find the probability of a true positive on the test. That equals people who actually have
the defect (1%) * true positive results (90%) = .009.
Step 2: Find the probability of a false positive on the test. That equals people who don’t have the
defect (99%) * false positive results (9.6%) = .09504.
Step 3: Figure out the probability of getting a positive result on the test. That equals the chance
of a true positive (Step 1) plus a false positive (Step 2) = .009 + .09504 = .0.10404.
Step 4: Find the probability of actually having the gene, given a positive result. Divide the
chance of having a real, positive result (Step 1) by the chance of getting any kind of positive
result (Step 3) = .009/.10404 = 0.0865 (8.65%)
THANK
YOU