You are on page 1of 140

Advance Topic in Artificial

Intelligence & Neural Computing


Areas of AI and Some
Dependencies
Knowledge
Search Logic Representation

Machine
Planning
Learning

Expert
NLP Vision Robotics Systems
• 1.Norvig P. Russells S., Artificial Intelligence - A Modern Approach; First
Edition;
Prentice Hall; ISBN: 0-13-103805-2
2. R Beale and T Jackson, Neural Computing: An Introduction; R Beale and T
Jackson;
Institute of Physics Publishing; ISBN: 0-85-274262-2
3. Publisher: Van Nostrand Reinhold, 1993, Advanced Methods in Neural
Computing,
ISBN 0442004613
4. Publisher: Prentice Hall, 1998, Neural Networks: A comprehensive
foundation,
ISBN 0132733501
5. Publisher: IGI Global, 2008, Artificial Intelligence for Advanced Problem
Solving
Techniques, ISBN 9781599047058
What is Artificial Intelligence ?
• making computers that think?
• the automation of activities we associate with human thinking,
like decision making, learning ... ?
• the art of creating machines that perform functions that
require intelligence when performed by people ?
• the study of mental faculties through the use of computational
models ?
What is Artificial Intelligence ?
• the study of computations that make it possible to
perceive, reason and act ?
• a field of study that seeks to explain and emulate
intelligent behaviour in terms of computational
processes ?
• a branch of computer science that is concerned with the
automation of intelligent behaviour ?
• anything in Computing Science that we don't yet know
how to do properly ? (!)
What is Artificial Intelligence ?

THOUGHT Systems that thinkSystems that think


like humans rationally

Systems that act Systems that act


BEHAVIOUR like humans rationally

HUMAN RATIONAL
Systems that act like humans:
Turing Test
• “The art of creating machines that perform
functions that require intelligence when
performed by people.” (Kurzweil)
• “The study of how to make computers do
things at which, at the moment, people are
better.” (Rich and Knight)
Systems that act like humans

?
• You enter a room which has a computer
terminal. You have a fixed period of time to type
what you want into the terminal, and study the
replies. At the other end of the line is either a
human being or a computer system.
• If it is a computer system, and at the end of the
period you cannot reliably determine whether it
is a system or a human, then the system is
deemed to be intelligent.
Systems that act like humans

• The Turing Test approach


– a human questioner cannot tell if
• there is a computer or a human answering his
question, via teletype (remote communication)
– The computer must behave intelligently
• Intelligent behavior
– to achieve human-level performance in all
cognitive tasks
Systems that act like humans

• These cognitive tasks include:


– Natural language processing
• for communication with human
– Knowledge representation
• to store information effectively & efficiently
– Automated reasoning
• to retrieve & answer questions using the stored
information
– Machine learning
• to adapt to new circumstances
The total Turing Test
• Includes two more issues:
– Computer vision
• to perceive objects (seeing)
– Robotics
• to move objects (acting)
What is Artificial Intelligence ?

THOUGHT Systems that thinkSystems that think


like humans rationally

Systems that act Systems that act


BEHAVIOUR like humans rationally

HUMAN RATIONAL
Systems that think like humans:
cognitive modeling
• Humans as observed from ‘inside’
• How do we know how humans think?
– Introspection vs. psychological experiments
• Cognitive Science
• “The exciting new effort to make computers think
… machines with minds in the full and literal
sense” (Haugeland)
• “[The automation of] activities that we associate
with human thinking, activities such as decision-
making, problem solving, learning …” (Bellman)
What is Artificial Intelligence ?

THOUGHT Systems that thinkSystems that think


like humans rationally

Systems that act Systems that act


BEHAVIOUR like humans rationally

HUMAN RATIONAL
Systems that think ‘rationally’
"laws of thought"
• Humans are not always ‘rational’
• Rational - defined in terms of logic?
• Logic can’t express everything (e.g. uncertainty)
• Logical approach is often not feasible in terms of
computation time (needs ‘guidance’)
• “The study of mental facilities through the use of
computational models” (Charniak and
McDermott)
• “The study of the computations that make it
possible to perceive, reason, and act” (Winston)
What is Artificial Intelligence ?

THOUGHT Systems that thinkSystems that think


like humans rationally

Systems that act Systems that act


BEHAVIOUR like humans rationally

HUMAN RATIONAL
Systems that act rationally:
“Rational agent”
• Rational behavior: doing the right thing
• The right thing: that which is expected to
maximize goal achievement, given the
available information
• Giving answers to questions is ‘acting’.
• I don't care whether a system:
– replicates human thought processes
– makes the same decisions as humans
– uses purely logical reasoning
Systems that act rationally
• Logic  only part of a rational agent, not all of
rationality
– Sometimes logic cannot reason a correct
conclusion
– At that time, some specific (in domain) human
knowledge or information is used
• Thus, it covers more generally different situations of
problems
– Compensate the incorrectly reasoned conclusion
Systems that act rationally
• Study AI as rational agent –
2 advantages:
– It is more general than using logic only
• Because: LOGIC + Domain knowledge
– It allows extension of the approach with more
scientific methodologies
Rational agents
An agent is an entity that perceives and acts

This course is about designing rational agents

Abstractly, an agent is a function from percept histories to


actions:
[f: P*  A]
For any given class of environments and tasks, we seek the
agent (or class of agents) with the best performance
Computational limitations make perfect rationality
unachievable
 design best program for given machine resources



• Artificial
– Produced by human art or effort, rather than
originating naturally.
• Intelligence
• is the ability to acquire knowledge and use it"
[Pigford and Baur]
• So AI was defined as:
– AI is the study of ideas that enable computers to
be intelligent.
– AI is the part of computer science concerned with
design of computer systems that exhibit human
intelligence(From the Concise Oxford Dictionary)
From the above two definitions, we can see that
AI has two major roles:
– Study the intelligent part concerned with humans.
– Represent those actions using computers.
Goals of AI
• To make computers more useful by letting
them take over dangerous or tedious tasks
from human
• Understand principles of human intelligence
The Foundation of AI
• Philosophy
– At that time, the study of human intelligence
began with no formal expression
– Initiate the idea of mind as a machine and its
internal operations
The Foundation of AI
Mathematics formalizes the three main area
of AI: computation, logic, and probability
Computation leads to analysis of the problems that
can be computed
complexity theory
Probability contributes the “degree of belief” to
handle uncertainty in AI
Decision theory combines probability theory and
utility theory
The Foundation of AI
• Psychology
– How do humans think and act?
– The study of human reasoning and acting
– Provides reasoning models for AI
– Strengthen the ideas
• humans and other animals can be considered as
information processing machines
The Foundation of AI
• Computer Engineering
– How to build an efficient computer?
– Provides the artifact that makes AI application
possible
– The power of computer makes computation of
large and difficult problems more easily
– AI has also contributed its own work to computer
science, including: time-sharing, the linked list
data type, OOP, etc.
The Foundation of AI
• Control theory and Cybernetics
– How can artifacts operate under their own control?
– The artifacts adjust their actions
• To do better for the environment over time
• Based on an objective function and feedback from the
environment
– Not limited only to linear systems but also other
problems
• as language, vision, and planning, etc.
The Foundation of AI
• Linguistics
– For understanding natural languages
• different approaches has been adopted from the
linguistic work
– Formal languages
– Syntactic and semantic analysis
– Knowledge representation
The main topics in AI
Artificial intelligence can be considered under a number of
headings:
– Search (includes Game Playing).
– Representing Knowledge and Reasoning with it.
– Planning.
– Learning.
– Natural language processing.
– Expert Systems.
– Interacting with the Environment
(e.g. Vision, Speech recognition, Robotics)
We won’t have time in this course to consider all of these.
Some Advantages of Artificial
Intelligence

– more powerful and more useful computers


– new and improved interfaces
– solving new problems
– better handling of information
– relieves information overload
– conversion of information into knowledge
The Disadvantages

– increased costs
– difficulty with software development - slow and
expensive
– few experienced programmers
– few practical products have reached the market
as yet.
Search
• Search is the fundamental technique of AI.
– Possible answers, decisions or courses of action are structured into
an abstract space, which we then search.
• Search is either "blind" or “uninformed":
– blind
• we move through the space without worrying about
what is coming next, but recognising the answer if we
see it
– informed
• we guess what is ahead, and use that information to
decide where to look next.
• We may want to search for the first answer that satisfies our goal, or we
may want to keep searching until we find the best answer.
Knowledge Representation & Reasoning
• The second most important concept in AI
• If we are going to act rationally in our environment, then we must have
some way of describing that environment and drawing inferences from
that representation.
– how do we describe what we know about the world ?
– how do we describe it concisely ?
– how do we describe it so that we can get hold of the right piece of
knowledge when we need it ?
– how do we generate new pieces of knowledge ?
– how do we deal with uncertain knowledge ?
Knowledge

Declarative Procedural

• Declarative knowledge deals with factoid questions


(what is the capital of India? Etc.)
• Procedural knowledge deals with “How”
• Procedural knowledge can be embedded in
declarative knowledge
Planning
Given a set of goals, construct a sequence of actions that achieves
those goals:
– often very large search space
– but most parts of the world are independent of most other parts
– often start with goals and connect them to actions
– no necessary connection between order of planning and order of
execution
– what happens if the world changes as we execute the plan
and/or our actions don’t produce the expected results?
Learning
• If a system is going to act truly appropriately,
then it must be able to change its actions in
the light of experience:
– how do we generate new facts from old ?
– how do we generate new concepts ?
– how do we learn to distinguish different
situations in new environments ?
Interacting with the Environment
• In order to enable intelligent behaviour, we will
have to interact with our environment.
• Properly intelligent systems may be expected to:
– accept sensory input
• vision, sound, …
– interact with humans
• understand language, recognise
speech,
generate text, speech and graphics, …
– modify the environment
• robotics
History of AI
• AI has a long history
– Ancient Greece
• Aristotle
– Historical Figures Contributed
• Ramon Lull
• Al Khowarazmi
• Leonardo da Vinci
• David Hume
• George Boole
• Charles Babbage
• John von Neuman
– As old as electronic computers themselves (c1940)
The ‘von Neuman’ Architecture
History of AI
• Origins
– The Dartmouth conference: 1956
• John McCarthy (Stanford)
• Marvin Minsky (MIT)
• Herbert Simon (CMU)
• Allen Newell (CMU)
• Arthur Samuel (IBM)
• The Turing Test (1950)
Periods in AI
• Early period - 1950’s & 60’s
– Game playing
• brute force (calculate your way out)
– Theorem proving
• symbol manipulation
– Biological models
• neural nets
• Symbolic application period - 70’s
– Early expert systems, use of knowledge
• Commercial period - 80’s
– boom in knowledge/ rule bases
Periods in AI cont’d
• period - 90’s and New Millenium
• Real-world applications, modelling, better evidence,
use of theory, ......?
• Topics: data mining, formal models, GA’s, fuzzy logic,
agents, neural nets, autonomous systems
• Applications
– visual recognition of traffic
– medical diagnosis
– directory enquiries
– power plant control
– automatic cars
Fashions in AI
Progress goes in stages, following funding booms and crises: Some examples:
1. Machine translation of languages
1950’s to 1966 - Syntactic translators
1966 - all US funding cancelled
1980 - commercial translators available

2. Neural Networks
1943 - first AI work by McCulloch & Pitts
1950’s & 60’s - Minsky’s book on “Perceptrons” stops nearly all work on nets
1986 - rediscovery of solutions leads to massive growth in neural nets research

The UK had its own funding freeze in 1973 when the Lighthill report reduced AI work
severely -Lesson: Don’t claim too much for your discipline!!!!
Look for similar stop/go effects in fields like genetic algorithms and evolutionary computing.
This is a very active modern area dating back to the work of Friedberg in 1958.
Symbolic and Sub-symbolic AI
• Symbolic AI is concerned with describing and
manipulating our knowledge of the world as explicit
symbols, where these symbols have clear relationships to
entities in the real world.
• Sub-symbolic AI (e.g. neural-nets) is more concerned with
obtaining the correct response to an input stimulus
without ‘looking inside the box’ to see if parts of the
mechanism can be associated with discrete real world
objects.
AI Applications
• Autonomous Planning
& Scheduling:
– Autonomous rovers.
AI Applications
• Autonomous Planning & Scheduling:
– Telescope scheduling
AI Applications
• Autonomous Planning & Scheduling:
– Analysis of data:
AI Applications
• Medicine:
– Image guided surgery
AI Applications
• Medicine:
– Image analysis and enhancement
AI Applications
• Transportation:
– Autonomous
vehicle control:
AI Applications
• Transportation:
– Pedestrian detection:
AI Applications

Games:
AI Applications
• Games:
AI Applications
• Robotic toys:
AI Applications
Other application areas:
• Bioinformatics:
– Gene expression data analysis
– Prediction of protein structure
• Text classification, document sorting:
– Web pages, e-mails
– Articles in the news
• Video, image classification
• Music composition, picture drawing
• Natural Language Processing .
• Perception.
Homework
Read Pg (1 – 31) From the book
Read Turing’s original paper on AI (Turing, 1950). In the paper, he discusses
several objections to his proposed enterprise and his test for
intelligence. Which objections still carry weight? Are his refutations
valid? Can you think of new objections arising from developments since
he wrote the paper? In the paper, he predicts that, by the year 2000, a
computer will have a 30% chance of passing a five-minute Turing Test
with an unskilled interrogator.What chance do you think a computer
would have today? In another 50 years?
Propositional logic in Artificial intelligence

• Propositional logic (PL) is the simplest form of


logic where all the statements are made by
propositions.
• A proposition is a declarative statement which
is either true or false.
• It is a technique of knowledge representation
in logical and mathematical form.
Example:

a) It is Sunday.  
b) The Sun rises from West (False proposition)  
c) 3+3= 7(False proposition)  
d) 5 is a prime number.   
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.
• These connectives are also called logical operators.
• The propositions and connectives are the basic
elements of the propositional logic.
• Connectives can be said as a logical operator which
connects two sentences.
• A proposition formula which is always true is
called tautology, and it is also called a valid sentence.
• A proposition formula which is always false is
called Contradiction.
Syntax of propositional logic:

• The syntax of propositional logic defines the


allowable sentences for the knowledge
representation. There are two types of
Propositions:
• Atomic Proposition  2+2 is 4,
• Compound proposition:
 It is raining today, and street is wet.
Table for Propositional Logic Connectives
Truth Table:
Precedence of connectives:
Logical equivalence:
• Logical equivalence is one of the features of
propositional logic. Two propositions are said
to be logically equivalent if and only if the
columns in the truth table are identical to
each other.
Properties of Operators:
Limitations of Propositional logic:

• We cannot represent relations like ALL, some, or


none with propositional logic. Example:
– All the girls are intelligent.
– Some apples are sweet.
• Propositional logic has limited expressive power.
• In propositional logic, we cannot describe
statements in terms of their properties or logical
relationships.
Rules of Inference in Artificial intelligence

• In artificial intelligence, we need intelligent


computers which can create new logic from
old logic or by evidence, so generating the
conclusions from evidence and facts is
termed as Inference.
Inference rules:

• Inference rules are the templates for


generating valid arguments. Inference rules
are applied to derive proofs in artificial
intelligence, and the proof is a sequence of
the conclusion that leads to the desired goal.
• In inference rules, the implication among all
the connectives plays an important role.
• Implication: It is one of the logical connectives which
can be represented as P → Q. It is a Boolean
expression.
• Converse: The converse of implication, which means
the right-hand side proposition goes to the left-hand
side and vice-versa. It can be written as Q → P.
• Contrapositive: The negation of converse is termed as
contrapositive, and it can be represented as ¬ Q → ¬ P.
• Inverse: The negation of implication is called inverse. It
can be represented as ¬ P → ¬ Q.
Types of Inference rules:
Modus Ponens:
• The Modus Ponens rule is one of the most important rules of inference,
and it states that if P and P → Q is true, then we can infer that Q will be
true. It can be represented as:

• Example:
• Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
Statement-2: "I am sleepy" ==> P
Conclusion: "I go to bed." ==> Q. 
Hence, we can say that, if P→ Q is true and P is true then Q will be true.

• Proof by Truth table:


Modus Tollens:
• The Modus Tollens rule state that if P→ Q is true and ¬ Q is
true, then ¬ P will also true. It can be represented as:

• Statement-1: "If I am sleepy then I go to bed" ==> P→ Q 


Statement-2: "I do not go to the bed."==> ~Q
Statement-3: Which infers that "I am not sleepy" => ~P
Hypothetical Syllogism:
• The Hypothetical Syllogism rule state that if P→R is true whenever P→Q is
true, and Q→R is true. It can be represented as the following notation:
• Example:
• Statement-1: If you have my home key then you can unlock my
home. P→Q
Statement-2: If you can unlock my home then you can take my
money. Q→R
Conclusion: If you have my home key then you can take my money. P→R
Disjunctive Syllogism:
• The Disjunctive syllogism rule state that if P∨Q is true, and ¬P is true, then
Q will be true. It can be represented as:

• Example:
• Statement-1: Today is Sunday or Monday. ==>P∨Q
Statement-2: Today is not Sunday. ==> ¬P
Conclusion: Today is Monday. ==> Q
Addition:
• The Addition rule is one the common inference rule, and it
states that If P is true, then P∨Q will be true.
• Example:
• Statement: I have a vanilla ice-cream. ==> P
Statement-2: I have Chocolate ice-cream. 
Conclusion: I have vanilla or chocolate ice-cream. ==> (P∨Q)
 Simplification:
• The simplification rule state that if P∧ Q is true, then Q or
P will also be true. It can be represented as:
Resolution:
• The Resolution rule state that if P∨Q and ¬ P∧R is true, then
Q∨R will also be true. It can be represented as
Wumpus world:

• The Wumpus world is a simple world example


to illustrate the worth of a knowledge-based
agent and to represent knowledge
representation. It was inspired by a video
game Hunt the Wumpus by Gregory Yob in
1973.
The Wumpus world Properties:

• Partially observable: The Wumpus world is partially observable


because the agent can only perceive the close environment such
as an adjacent room.
• Deterministic: It is deterministic, as the result and outcome of
the world are already known.
• Sequential: The order is important, so it is sequential.
• Static: It is static as Wumpus and Pits are not moving.
• Discrete: The environment is discrete.
• One agent: The environment is a single agent as we have one
agent only and Wumpus is not considered as an
agent.
Knowledge-base for Wumpus
world
• Atomic proposition variable for Wumpus
world:
Representation of Knowledgebase
for Wumpus world:
Outline
• Why FOL?
• Syntax and semantics of FOL
• Using FOL
• Wumpus world in FOL
• Knowledge engineering in FOL
Pros and cons of propositional
logic
 Propositional logic is declarative
 Propositional logic allows partial/negated information

 Propositional logic is compositional

 Propositional logic is context-independent

 Propositional logic has very limited expressive power


First-Order logic:
• First-order logic is another way of knowledge
representation in artificial intelligence. It is an
extension to propositional logic.
• FOL is sufficiently expressive to represent the natural
language statements in a concise way.
• First-order logic is also known as Predicate logic or
First-order predicate logic. First-order logic is a
powerful language that develops information about
the objects in a more easy way and can also express
the relationship between those objects.
First-order logic
• Whereas propositional logic assumes the world
contains facts,
• first-order logic (like natural language) assumes
the world contains
– Functions: father of, best friend, one more than, plus,

• Objects: people, houses, numbers, colors,
baseball games, wars, …
• Relations: red, round, prime, brother of, bigger
than, part of, comes between, …
First-order logic
• As a natural language, first-order logic also has
two main parts:
• Syntax
• Semantics
Syntax of FOL: Basic elements
• Constants KingJohn, 2, NUS,...
• Predicates Brother,...
• Functions Sqrt, LeftLegOf,...
• Variables x, y, a, b,...
• Connectives , , , , 
• Equality =
• Quantifiers , 
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).
Atomic sentences
Atomic sentence = predicate (term1,...,termn)
or term1 = term2

Term = function (term1,...,termn)


or constant or variable

• E.g., Brother(KingJohn,RichardTheLionheart) >


(Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))
Complex sentences
• Complex sentences are made from atomic
sentences using connectives
S, S1  S2, S1  S2, S1  S2, S1  S2,


Truth in first-order logic
• Sentences are true with respect to a model and an interpretation

• Model contains objects (domain elements) and relations among them

• Interpretation specifies referents for


constant symbols → objects
predicate symbols → relations
function symbols → functional relations

• An atomic sentence predicate(term1,...,termn) is true


iff the objects referred to by term1,...,termn
are in the relation referred to by predicate
First-order logic statements
• First-order logic statements can be divided into two parts:
• Subject: Subject is the main part of the statement.
• Predicate: A predicate can be defined as a relation, which
binds two atoms together in a statement.
• Consider the statement: "x is an integer.",
• it consists of two parts, the first part x is the subject of the
statement
• second part "is an integer," is known as a predicate.
Quantifiers in First-order logic:

• A quantifier is a language element which generates


quantification, and quantification specifies the quantity of
specimen in the universe of discourse.
• These are the symbols that permit to determine or identify
the range and scope of the variable in the logical expression.
There are two types of quantifier:
– Universal Quantifier, (for all, everyone, everything)
– Existential quantifier, (for some, at least one).
Universal Quantifier:
• Universal quantifier is a symbol of logical
representation, which specifies that the statement
within its range is true for everything or every
instance of a particular thing.
• The Universal quantifier is represented by a symbol
∀, which resembles an inverted A.
• If x is a variable, then ∀x is read as:
• For all x
• For each x
• For every x.
Example:
• All man drink coffee.
• Let a variable x which refers to a cat so all x
can be represented in UOD as below:
Existential Quantifier:

• Existential quantifiers are the type of quantifiers, which express that the
statement within its scope is true for at least one instance of something.
• It is denoted by the logical operator ∃, which resembles as inverted E. When it is
used with a predicate variable then it is called as an existential quantifier.
• If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
• There exists a 'x.'
• For some 'x.'
• For at least one 'x.‘

• It will be read as: There are some x where x is a boy who is intelligent.
• The main connective for universal
quantifier ∀ is implication →.
• The main connective for existential
quantifier ∃ is and ∧.
• In universal quantifier, ∀x∀y is similar to ∀y∀x.
• In Existential quantifier, ∃x∃y is similar to ∃y∃x.
• ∃x∀y is not similar to ∀y∃x.
• Some Examples of FOL using quantifier:
Examples 
• 1. All birds fly.
In this question the predicate is "fly(bird)." 
And since there are all birds who fly so it will be represented as follows.
              ∀x bird(x) →fly(x).
• 2. Every man respects his parent.
In this question, the predicate is "respect(x, y)," where x=man, and y= parent.
Since there is every man so will use ∀, and it will be represented as follows:
              ∀x man(x) → respects (x, parent).
• 3. Some boys play cricket.
In this question, the predicate is "play(x, y)," where x= boys, and y= game. Since there are some boys so we
will use ∃, and it will be represented as:
              ∃x boys(x) → play(x, cricket).
• 4. Not all students like both Mathematics and Science.
In this question, the predicate is "like(x, y)," where x= student, and y= subject.
Since there are not all students, so we will use ∀ with negation, so following representation for this:
              ¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
• 5. Only one student failed in Mathematics.
In this question, the predicate is "failed(x, y)," where x= student, and y= subject.
Since there is only one student who failed in Mathematics, so we will use following representation for this:
              ∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x,
Mathematics)].
Inference in First-Order Logic
• Inference in First-Order Logic is used to
deduce new facts or sentences from existing
sentences.

Substitution:
• Substitution is a fundamental operation performed on terms
and formulas. It occurs in all inference systems in first-order
logic. The substitution is complex in the presence of
quantifiers in FOL. If we write F[a/x], so it refers to substitute
a constant "a" in place of variable "x".
Equality:
• First-Order logic does not only use predicate
and terms for making atomic sentences but
also uses another way, which is equality in
FOL. For this, we can use equality
symbols which specify that the two terms
refer to the same object.
• Example: Brother (John) = Smith.
• Example: ¬ (x=y) which is equivalent to x ≠y
FOL inference rules for quantifier:

• Universal Generalization
• Universal Instantiation
• Existential Instantiation
• Existential introduction
Universal Generalization:
• Universal generalization is a valid inference rule which states
that if premise P(c) is true for any arbitrary element c in the
universe of discourse, then we can have a conclusion as ∀ x
P(x).
• This rule can be used if we want to show that every element
has a similar property.
• In this rule, x must not appear as a free variable.
• Example: Let's represent, P(c): "A byte contains 8 bits", so
for ∀ x P(x) "All bytes contain 8 bits.", it will also be true.
Universal Instantiation
• Universal instantiation is also called as universal elimination or UI is a valid
inference rule. It can be applied multiple times to add new sentences.
• The new KB is logically equivalent to the previous KB.
• As per UI, we can infer any sentence obtained by substituting a ground
term for the variable.
• The UI rule state that we can infer any sentence P(c) by substituting a
ground term c (a constant within domain x) from ∀ x P(x) for any object
in the universe of discourse.
• Example:1.
• IF "Every person like ice-cream"=> ∀x P(x) so we can infer that 
"John likes ice-cream" => P(c)
Example: 2.
• Let's take a famous example,
• "All kings who are greedy are Evil." So let our knowledge base
contains this detail as in the form of FOL:
• ∀x king(x) ∧ greedy (x) → Evil (x),
• So from this information, we can infer any of the following
statements using Universal Instantiation:
• King(John) ∧ Greedy (John) → Evil (John),
• King(Richard) ∧ Greedy (Richard) → Evil (Richard),
• King(Father(John)) ∧ Greedy (Father(John)) → Evil
(Father(John)),
Existential Instantiation:
• Existential instantiation is also called as Existential Elimination,
which is a valid inference rule in first-order logic.
• It can be applied only once to replace the existential sentence.
• The new KB is not logically equivalent to old KB, but it will be
satisfiable if old KB was satisfiable.
• This rule states that one can infer P(c) from the formula given
in the form of ∃x P(x) for a new constant symbol c.
• Example:
• From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),
• So we can infer: Crown(K) ∧ OnHead( K, John), as long as K
does not appear in the knowledge base.
Existential introduction
• An existential introduction is also known as an
existential generalization, which is a valid inference
rule in first-order logic.
• This rule states that if there is some element c in the
universe of discourse which has a property P, then
we can infer that there exists something in the
universe which has the property P.
• Example: Let's say that, 
"Priyanka got good marks in English."
"Therefore, someone got good marks in English."
Equality
• term1 = term2 is true under a given interpretation if
and only if term1 and term2 refer to the same object

• E.g., definition of Sibling in terms of Parent:


x,y Sibling(x,y)  [(x = y)  m,f  (m = f)  Parent(m,x)
 Parent(f,x)  Parent(m,y)  Parent(f,y)]
»


A simple knowledge base
• Knowledge Base
World Model, Agent Perception Model
Facts in Knowledge base (Prepositions)
Px,y is true if there is a pit in [x, y].
Wx,y is true if there is a wumpus in [x, y], dead or alive.
Bx,y is true if the agent perceives a breeze in [x, y].
Sx,y is true if the agent perceives a stench in [x, y]

Rules
A simple inference procedure
• Entailment -Model-checking approach
Forward Chaining and backward
chaining
• Inference engine:
The inference engine is the component of the
intelligent system in artificial intelligence, which
applies logical rules to the knowledge base to infer
new information from known facts. The first inference
engine was part of the expert system. Inference
engine commonly proceeds in two modes, which are:
Forward chaining
Backward chaining
Horn Clause and Definite clause:
• Horn clause and definite clause are the forms of sentences,
which enables knowledge base to use a more restricted and
efficient inference algorithm. Logical inference algorithms use
forward and backward chaining approaches, which require KB in
the form of the first-order definite clause.
• Definite clause: A clause which is a disjunction of literals
with exactly one positive literal is known as a definite clause or
strict horn clause.
• Horn clause: A clause which is a disjunction of literals with at
most one positive literal is known as horn clause. Hence all the
definite clauses are horn clauses.
• Example: (¬ p V ¬ q V k). It has only one positive literal k.
Forward Chaining
• Forward chaining is also known as a forward deduction or
forward reasoning method when using an inference
engine. Forward chaining is a form of reasoning which
start with atomic sentences in the knowledge base and
applies inference rules (Modus Ponens ) in the
forward direction to extract more data until a goal is
reached.
• The Forward-chaining algorithm starts from known facts,
triggers all rules whose premises are satisfied, and add
their conclusion to the known facts. This process repeats
until the problem is solved.
Properties of Forward-Chaining:

• It is a down-up approach, as it moves from bottom to


top.
• It is a process of making a conclusion based on known
facts or data, by starting from the initial state and
reaches the goal state.
• Forward-chaining approach is also called as data-
driven as we reach to the goal using available data.
• Forward -chaining approach is commonly used in the
expert system, such as business, and production rule
systems.
Example:
• "As per the law, it is a crime for an American to sell
weapons to hostile nations. Country A, an enemy of
America, has some missiles, and all the missiles
were sold to it by Robert, who is an American
citizen."
• Prove that "Robert is criminal."
• To solve the above problem, first, we will convert all
the above facts into first-order definite clauses, and
then we will use a forward-chaining algorithm to
reach the goal.
Facts Conversion into FOL:
• It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are
variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)       ...(1)
• Country A has some missiles. Quantifier p Owns(A, p) ∧ Missile(p). It can be written in
two definite clauses Owns(A, T1)             ......(2)
Missile(T1)             .......(3)
• All of the missiles were sold to country A by Robert.
QUANTYIFIER ALL p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A)       ......(4)
• Missiles are weapons.
Missile(p) → Weapons (p)             .......(5)
• Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p)             ........(6)
• Country A is an enemy of America.
Enemy (A, America)             .........(7)
• Robert is American
American(Robert).             ..........(8)
Forward chaining proof:

• step-1:
• In the first step we will start with the known facts and will choose the
sentences which do not have implications, such as: American(Robert),
Enemy(A, America), Owns(A, T1), and Missile(T1). All these facts will be
represented as below.
• Step-2:
• At the second step, we will see those facts which infer from available facts and with satisfied
premises.
• Rule-(1) does not satisfy premises, so it will not be added in the first iteration.
• Rule-(2) and (3) are already added.
• Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added, which infers
from the conjunction of Rule (2) and (3).
• Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and which infers from
Rule-(7).
Step-3:

• At step-3, as we can check Rule-(1) is satisfied with the substitution {p/Robert,


q/T1, r/A}, so we can add Criminal(Robert)which infers all the available facts. And
hence we reached our goal statement.

Hence it is proved that Robert is Criminal using forward chaining approach.


B. Backward Chaining:
Backward Chaining:
• Backward-chaining is also known as a backward
deduction or backward reasoning method when
using an inference engine. A backward chaining
algorithm is a form of reasoning, which starts with
the goal and works backward, chaining through rules
to find known facts that support the goal.
Properties of backward chaining:

• It is known as a top-down approach.


• Backward-chaining is based on modus ponens inference rule.
• In backward chaining, the goal is broken into sub-goal or sub-goals to
prove the facts true.
• It is called a goal-driven approach, as a list of goals decides which rules are
selected and used.
• Backward -chaining algorithm is used in game theory, automated theorem
proving tools, inference engines, proof assistants, and various AI
applications.
• The backward-chaining method mostly used a depth-first search strategy
for proof.
• Example:
Knowledge engineering in FOL
1. Identify the task
• Assemble the relevant knowledge
• Decide on a vocabulary of predicates, functions, and
constants
• Encode general knowledge about the domain
• Encode a description of the specific problem instance
• Pose queries to the inference procedure and get
answers
• Debug the knowledge base
Code of Wumpus
(Implementation Level)
• Int main(int argc, char *argv[]) {
• int realWorld[NOCOLS][NOROWS]; // Array of ints holding real world map
• int agentWorld[NOCOLS][NOROWS]; // Array of ints holding agents world map
• int x, y; // Counters
• struct coord currentCoord; // Current position coordinates
• struct coord start = {0, 0}; // Starting position

• // Initialize random number generator seed


• srand((unsigned int)time(0));

• // Initialize both worlds to zero.


• for(y=0; y<NOROWS; y++){
• for(x=0; x<NOCOLS; x++){
• realWorld[x][y] = 0;
• agentWorld[x][y] = 0;
• }
• }

• // Generate realWorld.
• generateRealWorld(realWorld);

• // Generate agentWorld
• setFlag(agentWorld, start, CURRENT); // Initialy player is at (0,0)
• // Go to the nearest safe field if any safe field exists in agent world
• int takeSafeAction(int agentWorld[NOCOLS][NOROWS], struct coord field){
• int random,z;
• struct coord neighbors[4]; // Neighbors coordinates

• // Get neighbors coordinates


• neighborFieldsCoords(field, neighbors);

• int except_i; /* Indexing into except array. */


• int except_size; /* No. of exceptions inside except array. */

• int *exceptSF = NULL; /* Array with exceptions */


• int *exceptSF_temp = NULL; /* Intermediate for validating realloc(). */

• except_i = 0;
• except_size = 0;

• // First we will see are there any neighbor fields that are SAFE
• for(z=0; z<4; z++){
• if ( (
• ((neighbors[z].y > NOROWS-1) && (z == 0))
• ||
• ((neighbors[z].x > NOCOLS-1) && (z == 1))
• ||
• ((neighbors[z].y < 0) && (z == 2))
• ||
• ((neighbors[z].x < 0) && (z == 3))
• )
• ||
• (testFlag(agentWorld, neighbors[z], VISITED))
• ||
• (testFlag(agentWorld, neighbors[z], SAFE) == 0)
• ){
• if(except_i == 0){
• except_size++;
• if ((exceptSF = (int*)calloc(except_size, sizeof(int))) == NULL) {
• fprintf(stderr, "Error allocating memory.\n");
• exit(EXIT_FAILURE);
• }
• }else if(except_i == except_size){
• except_size++;
• if ((exceptSF_temp = (int*)realloc(exceptSF, except_size * sizeof(int))) == NULL) {
• fprintf(stderr, "Ran out of memory while expanding except array.\n");
• free(exceptSF);
• exit(EXIT_FAILURE);
• }
• exceptSF = exceptSF_temp;
• }
• exceptSF[except_i] = z;
• except_i++;
• }
• }

• if (except_i<4){
• random = randInt(0,3,exceptSF,except_i);

• moveOneField(agentWorld, random, field);


• free(exceptSF);
• return(1);
• }else{
• // If there are no neighbor fields SAFE, then we hunt for nearest safe field in the world
• free(exceptSF);
• int x,y,direction;
• struct coord nearestSafeFieldCoord = { -1, -1 };

• /* We go trough agentWorld in a search of a SAFE field nearest to our current position */


• for(x=0; x<NOROWS; x++){
• for(y=0; y<NOCOLS; y++){
• struct coord testSafeFieldCoord = { x, y };
• // Test is SAFE?
• if(testFlag(agentWorld, testSafeFieldCoord, SAFE)){
• // If this is first SAFE field, it is nearest
• if((nearestSafeFieldCoord.x == -1) && (nearestSafeFieldCoord.y == -1)){
• nearestSafeFieldCoord = testSafeFieldCoord;
• }else{
• // It this is not first SAFE field, we check is it nearest one
• if(calcDistance(agentWorld,field,testSafeFieldCoord) < calcDistance(agentWorld, field,nearestSafeFieldCoord)){
• nearestSafeFieldCoord = testSafeFieldCoord;
• }
• }
• }
• }
• }

• // If there are no SAFE fields left, return 0


• if((nearestSafeFieldCoord.x == -1) && (nearestSafeFieldCoord.y == -1)){
• return(0);
• } else{
• // Move in direction of the nearestSafeFieldCoord
• direction = calcDirrection(agentWorld,field,nearestSafeFieldCoord);
• moveOneField(agentWorld,direction,field);
• return(1);
• }

• }
• }

You might also like