Ai (Unit 2)
Ai (Unit 2)
Ans = Humans are best at understanding, reasoning, and interpreting knowledge. Human
knows things, which is knowledge and as per their knowledge they perform various actions in
the real world. But how machines do all these things comes under knowledge
representation and reasoning. Hence we can describe Knowledge representation as
following:
What to Represent:
Object: All the facts about objects in our world domain. E.g., Guitars contains strings,
trumpets are brass instruments.
Events: Events are the actions which occur in our world.
Performance: It describe behavior which involves knowledge about how to do
things.
Meta-knowledge: It is knowledge about what we know.
Facts: Facts are the truths about the real world and what we represent.
Knowledge-Base: The central component of the knowledge-based agents is the
knowledge base. It is represented as KB. The Knowledgebase is a group of the
Sentences (Here, sentences are used as a technical term and not identical with the
English language).
Types of knowledge
2. Procedural Knowledge
3. Meta-knowledge:
4. Heuristic knowledge:
5. Structural knowledge:
Structural knowledge is basic knowledge to problem-solving.
It describes relationships between various concepts such as kind of, part of, and
grouping of something.
It describes the relationship that exists between concepts or objects.
Scalability: As knowledge bases grow in size and complexity, managing and retrieving
information in a scalable way becomes a challenge. Efficiently handling vast amounts of
data while maintaining quick access times is a critical issue.
Ans = Description- Knowledge about which paths are most likely to lead quickly to a goal
state is often called search control knowledge.
There are a number of AI systems that represent their control knowledge with rules.
Example SOAR, PRODIG. SOAR is a general architecture for building intelligent systems.
3. Explain Matching.
Ans = MATCHING: So far, we have seen the process of using search to solve problems as
the application of appropriate rules to individual problem states to generate new states to
which the rules can then be applied, and so forth, until a solution is found. Clever search
involves choosing from among the rules that can be applied at a particular point, the ones that
are most likely to lead to a solution. We need to extract from the entire collection of rules,
those that can be applied at a given point. To do so requires some kind of matching between
the current state and the preconditions of the rules.
One way to select applicable rules is to do a simple search through all the rules comparing
one’s preconditions to the current state and extracting all the ones that match . this requires
indexing of all the rules. But there are two problems with this simple solutions:
A. It requires the use of a large number of rules. Scanning through all of them would be
hopelessly inefficeint.
Sometimes , instead of searching through the rules, we can use the current state as an index
into the rules and select the matching ones immediately. In spite of limitations, indexing in
some form is very important in the efficient operation of rules based systems.
A more complex matching is required when the preconditions of rule specify required
properties that are not stated explicitly in the description of the current state. In this case, a
separate set of rules must be used to describe how some properties can be inferred from
others. An even more complex matching process is required if rules should be applied and if
their pre condition approximately match the current situation. This is often the case in
situations involving physical descriptions of the world.
4. Explain Resolution.
Resolution
Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e.,
proofs by contradictions. It was invented by a Mathematician John Alan Robinson in the year
1965.
Resolution is used, if there are various statements are given, and we need to prove a
conclusion of those statements. Unification is a key concept in proofs by resolutions.
Resolution is a single inference rule which can efficiently operate on the conjunctive normal
form or clausal form.
Clause: Disjunction of literals (an atomic sentence) is called a clause. It is also known as a
unit clause.
Note: To better understand this topic, firstly learns the FOL in AI.
The resolution rule for first-order logic is simply a lifted version of the propositional rule.
Resolution can resolve two clauses if they contain complementary literals, which are assumed
to be standardized apart so that they share no variables.
Where li and mj are complementary literals.
This rule is also called the binary resolution rule because it only resolves exactly two
literals.
Example:
Where two complimentary literals are: Loves (f(x), x) and ¬ Loves (a, b)
These literals can be unified with unifier θ= [a/f(x), and b/x] , and it will generate a resolvent
clause:
To better understand all the above steps, we will take an example in which we will apply
resolution.
Example:
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes
easier for resolution proofs.
a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
g. ∀x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).
a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀x ∀y ¬ eats(x, y) V killed(x) V food(y)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
f. ∀x ¬killed(x) ] V alive(x)
g. ∀x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).
a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
f. ∀g ¬killed(g) ] V alive(g)
g. ∀k ¬ alive(k) V ¬ killed(k)
h. likes(John, Peanuts).
a. ¬ food(x) V likes(John, x)
b. food(Apple)
c. food(vegetables)
f. alive(Anil)
g. ¬ eats(Anil, w) V eats(Harry, w)
h. killed(g) V alive(g)
i. ¬ alive(k) V ¬ killed(k)
j. likes(John, Peanuts).
In this statement, we will apply negation to the conclusion statements, which will be written
as ¬likes(John, Peanuts)
Now in this step, we will solve the problem by resolution tree using substitution. For the
above problem, it will be given as follows:
Hence the negation of the conclusion has been proved as a complete contradiction with the
given set of statements.
o In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get
resolved(canceled) by substitution of {Peanuts/x}, and we are left with ¬
food(Peanuts)
o In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get resolved
(canceled) by substitution of { Peanuts/z}, and we are left with ¬ eats(y, Peanuts) V
killed(y) .
o In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil,
Peanuts) get resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
o In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve by
substitution {Anil/k}, and we are left with ¬ alive(Anil) .
o In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.
Forward reasoning is a process in artificial intelligence that finds all the possible solutions
of a problem based on the initial data and facts. Thus, the forward reasoning is a data-driven
task as it begins with new data. The main objective of the forward reasoning in AI is to find a
conclusion that would follow. It uses an opportunistic type of approach.
Forward reasoning flows from incipient to the consequence. The inference engine searches
the knowledge base with the given information depending on the constraints. The precedence
of these constraints have to match the current state.
In forward reasoning, the first step is that the system is given one or more constraints. The
rules are then searched for in the knowledge base for every constraint. The rule that fulfils the
condition is selected. Also, every rule can generate a new condition from the conclusion
which is obtained from the invoked one. This new conditions can be added and are processed
again.
The step ends if no new conditions exist. Hence, we can conclude that forward reasoning
follows the top-down approach.
Backward reasoning is the reverse process of the forward reasoning in which a goal or
hypothesis is selected and it is analyzed to find the initial data, facts, and rules. Therefore, the
backward reasoning is a goal driven task as it begins with conclusions or goals that are
uncertain. The main objective of the backward reasoning is to find the facts that support the
conclusions.
Backward reasoning uses a conservative type of approach and flows from consequence to the
incipient. The system helps to choose a goal state and reasons in a backward direction. The
first step in the backward reasoning is that the goal state and rules are selected. Then, sub-
goals are made from the selected rule, which need to be satisfied for the goal state to be true.
The initial conditions are set such that they satisfy all the sub-goals. Also, the established
states are matched to the initial state provided. If the condition is fulfilled, the goal is the
solution, otherwise the goal is rejected. Therefore, backward reasoning follows bottom-up
technique.
Backward reasoning is also known as a decision-driven or goal-driven inference technique
because the system selects a goal state and reasons in the backward direction.
The following are the important differences between Forward and Backward Reasoning in AI
−
2. It begins with new data. It begins with conclusions that are uncertain.
The objective is to find a conclusion that would The objective is to find the facts that support
3.
follow. the conclusions.
5. It flows from incipient to the consequence. It flows from consequence to the incipient.
Forward reasoning begins with the initial facts. Backward reasoning begins with some goal
6.
(hypothesis).
7. Forward reasoning tests all the rules. Backward reasons tests some rules.
Forward reasoning can produce an infinite number Backward reasoning produces a finite number
9.
of conclusion. of conclusions.
In the forward reasoning, all the data is available. In the backward reasoning, the data is acquired
10.
on demand.
Forward reasoning has a small number of initial Backward reasoning has a smaller number of
11.
states but a large number of conclusions. goals and a larger number of rules.
For starting logic programming in Python, we need to install the following two packages −
Kanren : It provides us a way to simplify the way we made code for business logic. It lets us
express the logic in terms of rules and facts. The following command will help you install
kanren −
Actually we can find the unknown values by using logic programming in a very effective
way. The following Python code will help you match a mathematical expression −
add = 'add'
mul = 'mul'
Both addition and multiplication are communicative processes. Hence, we need to specify it
and this can be done as follows −
fact(commutative, mul)
fact(commutative, add)
fact(associative, mul)
fact(associative, add)
It is compulsory to define variables; this can be done as follows −
a, b = var('a'), var('b')
We need to match the expression with the original pattern. We have the following original
pattern, which is basically (5+a)*b −
((3,2))
()
The first output represents the values for a and b. The first expression matched the original
pattern and returned the values for a and b but the second expression did not match the
original pattern hence nothing has been returned.
Checking for Prime Numbers
With the help of logic programming, we can find the prime numbers from a list of numbers
and can also generate prime numbers. The Python code given below will find the prime
number from a list of numbers and will also generate the first 10 prime numbers.
def prime_check(x):
if isvar(x):
return condeseq([(eq,x,p)] for p in map(prime, it.count(1)))
else:
return success if isprime(x) else fail
Now, we need to declare a variable which will be used −
x = var()
print((set(run(0,x,(membero,x,(12,14,15,19,20,21,22,23,29,30,41,44,52,62,65,85)),
(prime_check,x)))))
print((run(10,x,prime_check(x))))
The output of the above code will be as follows −
Logic programming can be used to solve many problems like 8-puzzles, Zebra puzzle,
Sudoku, N-queen, etc. Here we are taking an example of a variant of Zebra puzzle which is as
follows −
We are solving it for the question who owns zebra with the help of Python.
Now, we need to define two functions − left() and next() to check whose house is left or next
to who’s house −
houses = var()
We need to define the rules with the help of lall package as follows.
rules_zebraproblem = lall(
(eq, (var(), var(), var(), var(), var()), houses),
With the help of the following code, we can extract the output from the solver −
Instance Relationship:
An instance is a specific occurrence or realization of a class. If you have a class "Car," a
specific car, say a "Toyota Camry," is an instance of the "Car" class.
plaintext
Copy code
Car
|
Toyota Camry (Instance of Car)
vbnet
Copy code
Instances are concrete objects that belong to a specific class. In AI, instances are used to
represent individual entities in the world.
In AI, you might use various methods to represent these relationships, depending on the
specific application. Some common approaches include:
1. **Graph-based Representation:**
- Representing classes as nodes and relationships as edges in a graph. In the example
above, you'd have nodes for "Animal," "Mammal," and edges indicating the ISA
relationship.
2. **Semantic Networks:**
- Using semantic networks to represent entities and their relationships. Each class or
instance is a node, and relationships are represented by labeled links between nodes.
3. **Class Hierarchies:**
- In object-oriented programming, you might represent classes and their relationships
using class hierarchies. Each class represents a type, and the ISA relationship is
expressed through inheritance.
4. **Ontologies:**
- Using ontologies to formally represent knowledge, where classes, instances, and
relationships are defined in a structured and standardized way.
```plaintext
Animal
|
Mammal
|
Dog (Instance of Mammal)
In summary, the representation of ISA and instance relationships in AI often involves
hierarchical structures and various knowledge representation techniques, such as
graphs, ontologies, and semantic networks. The choice of representation depends on the
specific requirements of the AI system being developed.
In the context of AI, natural deduction is often employed in automated theorem proving
and reasoning systems. Here are the key components and concepts associated with
natural deduction:
Inference Rules: Natural deduction uses a set of inference rules that define how
conclusions can be drawn from premises. These rules are typically expressed in the
form of "if-then" statements and dictate how reasoning steps can be made.
Proof Trees: Arguments in natural deduction are often represented using proof trees. A
proof tree shows the structure of an argument, with branches representing different
assumptions and sub-arguments leading to the final conclusion.
Universal and Existential Quantifiers: Natural deduction handles quantifiers like "for
all" (∀) and "there exists" (∃), allowing reasoning about statements that involve
variables and quantified expressions.
Here's a simple example using the implication (→) and AND (∧) connectives:
Premises:
Q∧R
P→Q
Conclusion:
R
Proof:
Q ∧ R (premise)
Q (modus ponens: 1, 2)
R (conjunction elimination: 4)
P → R (implication introduction: 1-5)
In this example, the proof starts with the assumption of P and uses inference rules to
derive the conclusion R. The structure of the proof reflects the logical relationships
between the premises and the conclusion.
9. Explain Predicate ?
Ans = Consider the statement, “x is greater than 3″. It has two parts. The first part, the
variable , is the subject of the statement. The second part, “is greater than 3”, is
the predicate. It refers to a property that the subject of the statement can have.
The statement “x is greater than 3″ can be denoted by P(x) where x denotes the predicate
“is greater than 3” and is the variable.
2)The predicate P can be considered as a function. It tells the truth value of the
statement P(x) at x. Once a value has been assigned to the variable x, the
statement P(x) becomes a proposition and has a truth or false(tf) value.
In general, a statement involving n variables x1, x2, x3…….xn can be denoted
by P(x1,x2,x3,……..xn). Here P is also referred to as n-place predicate or a n-ary
predicate.
Example 1: Let P(x) denote the statement “x > 10″. What are the truth values of
The idea of computable functions is closely related to the broader field of computability
theory, which explores the limits and capabilities of computation. Alan Turing, one of the
pioneers of computer science, introduced the concept of a Turing machine, a theoretical
model of computation that can simulate any algorithm. Turing machines are used to define
what it means for a function to be computable.
In the context of AI, the concept of computable functions is fundamental because it sets the
theoretical foundation for what can be achieved algorithmically. Many AI algorithms and
models are based on the idea of manipulating and processing data through well-defined
procedures, which aligns with the concept of computable functions.
It's worth noting that not all functions are computable. There are functions that are
undecidable or incomputable, meaning that there is no algorithm that can compute their
values for all possible inputs. The study of these limits and the nature of computation is an
essential aspect of theoretical computer science.
Computable Problems –
You are familiar with many problems (or functions) that are computable (or decidable),
meaning there exists some algorithm that computes an answer (or output) to any instance of
the problem (or for any input to the function) in a finite number of simple steps. A simple
example is the integer increment operation:
f(x) = x + 1
It should be intuitive that given any integer x, we can compute x + 1 in a finite number of
steps. Since x is finite, it may be represented by a finite string of digits. Using the addition
method (or algorithm) we all learned in school, we can clearly compute another string of
digits representing the integer equivalent to x + 1. Yet there are also problems and functions
that are non-computable (or undecidable or uncomputable), meaning that there exists no
algorithm that can compute an answer or output for all inputs in a finite number of simple
steps. (Undecidable simply means non-computable in the context of a decision problem,
whose answer (or output) is either “true” or “false”).
Ans = In the context of artificial intelligence (AI), representation and mapping are
fundamental concepts that play a crucial role in how machines understand and process
information.
Representation:
Definition: Representation refers to the way information is encoded and presented in a form
that can be processed by a system. In AI, this often involves transforming real-world objects,
concepts, or phenomena into a format that can be understood and manipulated by a computer.
Importance: The choice of representation significantly impacts the efficiency and
effectiveness of AI systems. A well-chosen representation can simplify complex problems,
making them more tractable for computational solutions.
Mapping:
Examples:
1. Natural Language Processing (NLP): Representation: In NLP, words and sentences need
to be represented in a way that a machine can understand. This could involve techniques like
word embeddings, where words are mapped to high-dimensional vectors.
Mapping: The mapping process involves connecting these word embeddings to convey the
meaning of a sentence or document, enabling tasks like sentiment analysis or language
translation.
2.Computer Vision: Representation: Images are often represented as pixel values, but this
raw representation may be too complex for certain tasks. Feature extraction techniques are
employed to represent images in a more meaningful way, such as through the identification of
edges, shapes, or textures.
Mapping: Mapping, in this case, involves connecting these extracted features to specific
objects or concepts, enabling object recognition or image classification.
Machine Learning:
3.Representation: In machine learning, data needs to be represented in a format suitable for
training models. Features are extracted or engineered to create a representation that captures
relevant information for the learning task.
Mapping: The mapping process involves establishing the relationship between input features
and the target variable, allowing the model to generalize and make predictions on new,
unseen data.
In summary, representation involves encoding information in a machine-readable format,
while mapping involves establishing connections between different representations to enable
intelligent processing and decision-making in AI systems. The effectiveness of these
processes is crucial for the success of various AI applications.