0% found this document useful (0 votes)
87 views

Module 3

This document discusses knowledge representation and logic programming concepts. It covers: - Knowledge representation techniques in AI like propositional logic, first-order logic, rule-based systems, semantic networks, and frames. - Core concepts of logic programming including facts, rules, queries, unification, and forward and backward chaining. - Knowledge representation allows AI systems to understand and model knowledge to solve complex problems. Logic programming uses relations expressed as facts and rules to apply logic.

Uploaded by

aryan bhujbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Module 3

This document discusses knowledge representation and logic programming concepts. It covers: - Knowledge representation techniques in AI like propositional logic, first-order logic, rule-based systems, semantic networks, and frames. - Core concepts of logic programming including facts, rules, queries, unification, and forward and backward chaining. - Knowledge representation allows AI systems to understand and model knowledge to solve complex problems. Logic programming uses relations expressed as facts and rules to apply logic.

Uploaded by

aryan bhujbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Module no 3

First Order Predicate


• UNIT III KNOWLEDGE REPRESENTATION

Logic – Prolog Programming – Unification


•Forward Chaining-Backward Chaining –
Resolution – Knowledge
•Representation - Ontological
Engineering-Categories and Objects –Events -
Mental Events and Mental Objects - Reasoning
Systems for Categories - Reasoning with Default
Information
• .
Prolog
• Prolog is a logic programming language. It has important role in
artificial intelligence. Unlike many other programming languages,
Prolog is intended primarily as a declarative programming language.
In prolog, logic is expressed as relations (called as Facts and Rules).
Core heart of prolog lies at the logic being applied. Formulation or
Computation is carried out by running a query over these relations.
• Relationship is one of the main features that we have to
properly mention in Prolog. These relationships can be
expressed as facts and rules
• Fact/Relationship
Facts, Rules and Queries
Predicate
English PROLOG
Calculus
and ^ ,

or v ;

if --> :-

not ~ not
• Variables and Names
• Variables begin with an uppercase letter. Predicate names, function
names, and the names for objects must begin with a lowercase letter.
Rules for forming names are the same as for predicate calculus.
• mother_of
• male
• female
• greater_than
• socrates
A fact is a predicate expression that makes a declarative statement about the problem domain.
Whenever a variable occurs in a Prolog expression, it is assumed to be universally quantified. Note
that all Prolog sentences must end with a period.
• likes(john, susie). /* John likes Susie */
• likes(X, susie). /* Everyone likes Susie */
• likes(john, Y). /* John likes everybody */
• likes(john, Y), likes(Y, john). /* John likes everybody and everybody
likes John */
• likes(john, susie); likes(john,mary). /* John likes Susie or John likes Mary
*/
• not(likes(john,pizza)). /* John does not like pizza */
• likes(john,susie) :- likes(john,mary). /* John likes Susie if John likes Mary.
• Rules
• A rule is a predicate expression that uses logical implication (:-) to
describe a relationship among facts. Thus a Prolog rule takes the form
• left_hand_side :- right_hand_side
• This sentence is interpreted as: left_hand_side if right_hand_side
• This notation is known as a Horn clause
• In Horn clause logic, the left hand side of the clause is the conclusion,
and must be a single positive literal. The right hand side contains the
premises. The Horn clause calculus is equivalent to the first-order
predicate calculus.
• The left_hand_side is restricted to a single, positive, literal, which
means it must consist of a positive atomic expression. It cannot be
negated and it cannot contain logical connectives.
valid rules:

• friends(X,Y) :- likes(X,Y),likes(Y,X). /* X and Y are friends if they like each other */

• hates(X,Y) :- not(likes(X,Y)). /* X hates Y if X does not like Y. */

• enemies(X,Y) :- not(likes(X,Y)),not(likes(Y,X)). /* X and Y are enemies if they don't like each


other */
• Examples of invalid rules:

• left_of(X,Y) :- right_of(Y,X) /* Missing a period */


• likes(X,Y),likes(Y,X) :- friends(X,Y). /* LHS is not a single literal */
• not(likes(X,Y)) :- hates(X,Y). /* LHS cannot be negated */
Queries
• The Prolog interpreter responds to queries about the facts and rules represented in its database. The
database is assumed to represent what is true about a particular problem domain. In making a query
you are asking Prolog whether it can prove that your query is true. If so, it answers "yes" and
displays any variable bindings that it made in coming up with the answer. If it fails to prove the
query true, it answers "No".
• father_of(joe,paul).
• father_of(joe,mary).
• mother_of(jane,paul).
• mother_of(jane,mary).
• male(paul).
• male(joe).
• female(mary).
• female(jane).

The database consists of the following facts about


a fictitious family.////
• Closed World Assumption. The Prolog interpreter assumes that the
database is a closed world -- that is, if it cannot prove something is
true, it assumes that it is false. This is also known as negation as
failure -- that is, something is false if PROLOG cannot prove it true
given the facts and rules in its database. In this case, in may well be (in
the real world), that Paul is the father of Mary, but since this cannot be
proved given the current family database
• Prolog concludes that it is false. So PROLOG assumes that its
database contains complete knowledge of the domain it is being asked
about.
Knowledge representation in AI
• Human beings are good at understanding, reasoning, and
interpreting knowledge. And using this knowledge, they are
able to perform various actions in the real world.
• Knowledge Representation in AI describes the representation of
knowledge. Basically, it is a study of how the beliefs, intentions, and
judgments of an intelligent agent can be expressed suitably for
automated reasoning.
• One of the primary purposes of Knowledge Representation includes
modeling intelligent behavior for an agent.
• Knowledge Representation and Reasoning (KR, KRR)
represents information from the real world for a computer
to understand and then utilize this knowledge to
solve complex real-life problems like communicating with
human beings in natural language.
• The different kinds of knowledge that need to be
represented in AI include:
• Objects
• Events
• Performance
• Facts
• Meta-Knowledge
• Knowledge-base
Different Types of Knowledge
• Declarative Knowledge – It includes concepts, facts, and
objects and expressed in a declarative sentence.
• Structural Knowledge – It is a basic problem-solving
knowledge that describes the relationship between concepts
and objects.
• Procedural Knowledge – This is responsible for knowing
how to do something and includes rules, strategies,
procedures, etc.
• Meta Knowledge – Meta Knowledge defines knowledge
about other types of Knowledge.
• Heuristic Knowledge – This represents some expert
knowledge in the field or subject.
Cycle of Knowledge Representation in AI

diagram shows the


interaction of an AI
system with the real
world and
the components inv
olved in showing
intelligence
Techniques of Knowledge Representation in AI
Knowledge representation in AI
• THERE are five ways
• Propositional logic
• First-order logic (FOL)
• Rule-based system
• Semantic Network
• Frames
Logic
Unification
• Unification is a process of making two different logical
atomic expressions identical by finding a substitution.
Unification depends on the substitution process.
• It takes two literals as input and makes them identical using
substitution.
• Let's say there are two different expressions, P(x, y), and
P(a, f(z)).
• P(x,y).........(i)
P(a, f(z))......... (ii)
• Substitute x with a, and y with f(z) in the first expression,
and it will be represented as a/x and f(z)/y.
• With both substitutions, the first expression will be identical
to the second expression and the substitution set will
be: [a/x, f(z)/y].
Conditions for Unification:
• Predicate symbols must be the same, atoms or expressions
with different predicate symbols can never be unified.
• Number of Arguments in both expressions must be
identical.
• Unification will fail if two similar variables are present in the
same expression.
• Forward Chaining and Backward Chaining are the two most
important strategies in the field of Artificial Intelligence and lie in the
Expert System Domain of AI.
• Forward and Backward chaining is the strategies used by the
Inference Engine in making the deductions.
• Inference Engine:
• Inference Engine is a component of the expert system that applies
logical rules to the knowledge base to deduce new information. It
interprets and evaluates the facts in the knowledge base in order to
provide an answer.
• A knowledge base is a structured collection of facts about the
system’s domain.
Forward Chaining:
• Forward Chaining the Inference Engine goes through all the facts,
conditions, and derivations before deducing the outcome i.e When based
on available data a decision is taken then the process is called Forwarding
chaining, It works from an initial state and reaches the goal(final decision).
• Example:
•A
• A -> B
•B
• —————————–
• He is running.
• If he is running, he sweats.
• He is sweating.
• Backward Chaining:
• In this, the inference system knows the final decision or goal, this
system starts from the goal and works backward to determine what
facts must be asserted so that the goal can be achieved, i.e it works
from the goal(final decision) and reaches the initial state.
• Example:
•B
• A -> B
•A
• —————————–
• He is sweating.
• If he is running, he sweats.
• He is running.
Forward chaining is known as data-driven Backward chaining is known as
technique because we reaches to the goal goal-driven technique because we start
using the available data. from the goal and reaches the initial state
in order to extract the facts
It is a bottom-up approach. It is a top-down approach.
Its goal is to get the conclusion Its goal is to get the possible facts or the
required data.
Forward chaining is used for the planning, It is used in automated inference engines,
monitoring, control, and interpretation theorem proofs, proof assistants and
application. other artificial intelligence applications.
When based on available data a decision Backward chaining starts from the goal
is taken then the process is called as and works backward to determine what
Forward chaining. facts must be asserted so that the goal
can be achieved.
Propositional logic
• A proposition is the basic building block of logic. It is defined as a
declarative sentence that is either True or False, but not both. The
Truth Value of a proposition is True(denoted as T) if it is a true
statement, and False(denoted as F) if it is a false statement
• The sun rises in the East and sets in the West.
•1 + 1 = 2
• 'b' is a vowel.
• What time is it?
• Go out and play.
• x + 1 = 2.
• area of logic that deals with propositions is called propositional
calculus or propositional logic. It also includes producing new
propositions using existing ones.
• Propositions constructed using one or more propositions are called
compound propositions.
• The propositions are combined together using Logical Connectives or
Logical Operators.

Negation, Conjunction, Disjunction


Exclusive Or: which means “either p or q but not both”
p\oplus q is “Either today is Friday or it is raining
today, but not both

Today is Friday”p and q – “It is


raining today”
Implication: if then

You might wonder that why is p\rightarrow q true


when p is false. This is because the implication
guarantees that when p and q are true then the
implication is true. But the implication does not
guarantee anything when the premise p is false. There
is no way of knowing whether or not the implication is
false since p did not happen
De Morgan’s Law :
• What is first-order logic (FOL)?
1. FOL is a mode of representation in
Artificial Intelligence. It is an
extension of PL.
2. FOL represents natural language
statements in a concise way.
3. FOL is also called predicate logic. It
is a powerful language used to
develop information about an
object and express the
relationship between objects.
4. FOL not only assumes that does the
world contains facts (like PL does),
but it also assumes the following:
1. Objects: A, B, people, numbers, colors,
Steps for Resolution:
1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF
3. Negate the statement which needs to prove (proof by
contradiction)
4. Draw resolution graph (unification).
1. John likes all kind of food.
2. Apple and vegetable are food
3. Anything anyone eats and not killed is food.
4. Anil eats peanuts and still alive
5. Harry eats everything that Anil eats.
Prove by resolution that:
6. John likes peanuts.
Resolution graph
Translating English Sentences :
• Natural Languages such as English are ambiguous i.e. a statement
may have multiple interpretations. Therefore it is important to
convert these sentences into mathematical expressions involving
propositional variables and logical connectives.
• The above conversion process may take certain reasonable
assumptions about the sentence's intended meaning. Once the
sentences are translated into logical expressions they can be analyzed
further to determine their truth values. Rules of Inference can then
further be used to reason about the expressions.
Ontology : a set of concepts and categories in a subject area or
domain that shows their properties and the relations between
them.
• Ontology engineering is a subfield of artificial intelligence. It
involves of a set of activities that concerns about the
methodologies, tools, and languages to develop and reuse
ontology. Ontology is considered as a knowledge
representation technique that enables the modeling of the
major types of knowledge: the simple relational knowledge,
the inheritable knowledge, the inferential knowledge and the
procedural knowledge.
• Individuals –
• Individuals are also known as instances of objects or concept s.It may
or may not be present in an ontology.It represents the atomic level of
an ontology.
• For example, in the above ontologmoviesmovie, individuals can be a
film (Titanic), a director (James Cameror on), an actor (Leonardo
DiCaprio).
• Classes –
• Sets of collections of various objects are termes classes.
• For example, in the above ontology representing a movie, movie
genre (e.g. Thriller, Drama), types of person (Actor or Director) are
classes.
• Attributes –
• Properties that objects may possess.
• For example, a movie is described by the set of ‘parts’ it contains like
Script, Director, Actors.
• Relations –
• Ways in which concepts are related to one another.
• For example, as shown above in the diagram a movie has to have a
script and actors in it.
• Different Ontology Languages:
• CycL – It was developed for the Cyc project and is based on First Order
Predicate Calculus.
• Rule Interchange Format (RIF) – It is the language used for combining
ontologies and rules.
• Open Biomedical Ontologies (OBO) – It is used for various biological
and biomedical ontologies.
• Web Ontology Language (OWL) – It is developed for using ontologies
over the World Wide Web (WWW).
• There are two main approaches to supporting Artificial Intelligence (AI).
On the one hand, through machine learning where AI systems learn from
examples.
• Another approach to supporting AI is ontology. Ontology is a set of
subject or domain concepts and categories that show their properties and
the relationships between them.
• Ontology real-world example
• Ontologies can be applied to situations that evaluate customer behavior.
The Cleveland Museum of Art wanted to understand the patterns of
visitor preferences and interactions with the museum’s collections. To do
this, they had to identify the characteristics of the collection, their
themes, locations, and specific points of interaction for the visitor. The
term for the location was developed because it was needed to establish a
correlation between the visitor’s reaction and the exhibit. Visitors agreed
that the museum would record what they said. Ontologies were developed
to connect geospatial data with behavioral analytics based on highly
specific content. The museum was able to better understand the tastes of
Ontology and digital transformation
• Hundreds or thousands of AI projects are required to achieve
complete digital transformation, so it’s important to set the
stage for scaling up. Instead of having a series of separate
projects, you need to develop an inerrable framework.
• In addition, existing ontology allows you to make changes to
your data in one place and propagate them through existing
relationships. For example, if the price of service changes, the
system does not need to be recoded in multiple applications.
Data can be modified once and transferred to al
Web based AI ONTOLOGY
Semantic networks are alternatives of predicate logic for knowledge representation. In Semantic
networks, we can represent our knowledge in the form of graphical networks. This network
consists of nodes representing objects and arcs which describe the relationship between those
objects. Semantic networks can categorize object in different forms and can also link those
objects. Semantic networks are easy to understand and can be easily extended.
1. Jerry is a cat.
2. Jerry is a mammal
3. Jerry is owned by Priya.
4. Jerry is WHITE colored.
5. All Mammals are animals.
• Advantages of Semantic network:
1. Semantic network are a natural representation of
knowledge.
2. Semantic networks convey meaning in a transparent
manner.
3. These networks are simple and easily understandable.
Drawbacks in Semantic representation
• Semantic networks do not have any standard definition for
the link names.
• Semantic networks take more computational time at
runtime as we need to traverse the complete network tree
to answer some questions. It might be possible in the
worst-case scenario that after traversing the entire tree, we
find that the solution does not exist in this network.
• Semantic networks try to model human-like memory (Which
has 1015 neurons and links) to store the information, but in
Frame Representation
• A frame is a record-like structure that consists of a
collection of attributes and their values to describe an
entity in the world. Frames are the AI data structure that
divides knowledge into substructures by representing
stereotypical situations. It consists of a collection of slots
and slot values. These slots may be of any type and size.
Slots have names and values which are called facets.
• Facets: The various aspects of a slot are known as Facets.
Facets are features of frames that enable us to put
constraints on the frames
Let's suppose we are taking an entity, Peter. Peter is an
engineer as a profession, and his age is 25, he lives in city
London, and the country is England. So following is the frame
representation for this:

Slots Filters
Slots Filter
Title Artificial
Name Peter Intelligence
Profession Doctor Genre Computer
Age 25 Science

Marital Single Author Peter Norvig


status Edition Third Edition
Weight 78 Year 1996
Page 1152
example of a frame for a book
important topics
• Predicate logic
• Unification
• First-order logic
• Normal forms
• Resolution proof
• Knowledge representation techniques
• Ontology
Predicate logic
Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: ⇒ cat (Chinky).

onstant 1, 2, A, John, Mumbai, cat,....


Variables x, y, z, a, b,....
Predicates Brother, Father, >,....
Function sqrt, LeftLegOf, ....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
In the universal quantifier, ∀x∀y is similar to ∀y∀x.
In the Existential quantifier, ∃x∃y is similar to ∃y∃x.
∃x∀y is not similar to ∀y∃x.
• All birds fly.
• ∀x bird(x) →fly(x).
• Every man respects his parent.
• ∀x man(x) → respects (x, parent).
• Some boys play cricket.
• ∃x boys(x) → play(x, cricket)
• 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)].
• Only one student failed in Mathematics.
• ∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x, Mathematics)].
• Free and Bound Variables:
• ∀x ∃(y)[P (x, y, z)], where z is a free variable.
• ∀x [A (x) B( y)], here x and y are the bound variables.

unification
• Unification is a process of making two different logical
atomic expressions identical by finding a substitution.
Unification depends on the substitution process.
• It takes two literals as input and makes them identical using
substitution.
• Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier
such that, Ψ1𝜎 = Ψ2𝜎, then it can be expressed as UNIFY(Ψ1,
Ψ2).
Prolog basic
• Knowledge Base − This is one of the fundamental parts of Logic
Programming. We will see in detail about the Knowledge Base, and
how it helps in logic programming.
• Facts, Rules and Queries − These are the building blocks of logic
programming. We will get some detailed knowledge about facts and
rules, and also see some kind of queries that will be used in logic
programming.
• https://www.tutorialspoint.com/prolog/prolog_basics.ht
m
• https://www.youtube.com/watch?v=XXSn_9E-DBE&list
=PLEJXowNB4kPy3_qhGksOO8ch_Di7T8_9E&index=2
• Filename.pl then compile buffer .
facts •Names of properties/relationships begin with lower
• Tom is a cat case letters.
•The relationship name appears as the first term.
• Kunal loves to eat Pasta •Objects appear as comma-separated arguments within
• Hair is black parentheses.
• Nawaz loves to play games •A period "." must end a fact.
•Objects also begin with lower case letters. They also
• Pratyusha is lazy. can begin with digits (like 1234), and can be strings of
characters enclosed in quotes e.g. color(penink, ‘red’).
•phoneno(agnibha, 1122334455). is also called a
Relation(object1,object2...). predicate or clause.

cat(tom).
loves_to_eat(kunal,pasta).
of_color(hair,black).
loves_to_play_games(nawaz).
lazy(pratyusha).
• Rules:
• Lili is happy if she dances.
• Tom is hungry if he is searching for food.
• Jack and Bili are friends if both of them love to play cricket.
• will go to play if school is closed, and he is free.
• symbol ( :- ) will be pronounced as “If”, or “is implied by”
• rule_name(object1, object2, ...) :- fact/rule(object1, object2, ...)
• happy(lili) :- dances(lili).
• hungry(tom) :- search_for_food(tom).
• friends(jack, bili) :- lovesCricket(jack), lovesCricket(bili).
• goToPlay(ryan) :- isClosed(school), free(ryan).
• Queries: Queries are some questions on the relationships between
objects and object properties
• Is tom a cat?
• Does Kunal love to eat pasta?
• Is Lili happy?
• Will Ryan go to play?
• So according to these queries, Logic programming language can find
the answer and return them.
Knowledge Base in Logic Programming
• three main components in logic programming − Facts,
Rules and Queries.
• Among these three if we collect the facts and rules as a
whole then that forms a Knowledge Base. So we can
say that the knowledge base is a collection of facts
and rules.
• KB1:girl(priya).
• girl(tiyasha).
• girl(jaya).
• can_cook(priya).
ACTIVITY
• Perform 5 experiments each one.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy