University Labs

Hands-On Experience at ISTIC Semester 5 Edition

View on GitHub

AI Fundamentals - My Notes

Machine Learning is a small scope of the HUGE Artificial Intelligence.

Logial Representation

It is a language with some concrete rules that deals with propositions and havs no ambiguity in representation.

Consist of:

Logical Representation is

1- Proposional Logic

Propositinal logic cannot predicate or assmue, it can say either true or false.

Connectivity


Truth Table


Examples

A- It is HOT
B- It is humid
C- It is rainning

Conditions:
1- If it is humid, then it is hot
2- if it is hot and humid then it is not raining

Conditions Proposition Logic
Condition 1 B=>A
Condition 2 A+B => C

Limitation Of PL

2- First Order predicat logic

First order logic is another way of knowlege representation in A.I. It is an extension to PL (propostional Logic)

As a natural language, First order logic has two main parts
a- syntax

b- semantics

### Semantic of FOL: Basic Elements

Elements Syntax
Constant 1,2 A, Hiehaaa
Variables x,y,z,a,b,c,d
Predicats Brother, Father, >, <
Functions Sqrt, etc
Connectives No, apply, and, or, <=> (AI syntax pls)
Equality =
Quantifiers ∀, ∃

### Atomic Sentences

Example1: Yaya and Soso are brothers.
Terms: Yahya, Soso
Predicate: Brothers
Result: Brothers( Yaya, Soso)

Example2: Tommy is a dog
Terms: Tommy
Predicate: Dog
Result: Dog(Tommy)

### Complex Sentences

Real meaning: Predicate1(Term1, Term2, TermN..) “Connectivity” Predicate2(Term1, Term2, TermN..)

#### First Order Logic Statements divided into 2 parts.

Example:
State: “X is an integer”

First part; X is a subject of the statement
Second part, is an integer is known as predicate


### Quantifiers

There are two type of quantifier:
#### a- Universal Quantifier ( for all, everyone, everything) – range in math “∀” It is a symbol of logical representation which specifies that the statement within its range is true for everything or every instance of particular thing

if x is a varibale, the ∀soit X is read as:
for all x
for each x
for every x

Example: All men drink coffee
let x is variable
x1 drink coffee, Vma9louba(and) x2 drink coffee and xn drinkcoffee.

So we can write it as ∀x man(x) –> drink (x, cofee)

if i’m not using the conectivity “->” than u could call it an atomic sentence ;)

There are all x where x is a man who drink coffe
You say also, there is x where is is men who drink coffe!! smart me!!


All birds fly, predicate is fly(bird)
∀x bird(x) -> fly(x)
Every man respects his parent, predicate is respect (x,y) where x=man, y=parent
∀x man(x) -> respects (x, parent)

##### b- Existential quantifier ( for some, atleast one) –scope in math “∃” It is the type of quantifier which express that the start within its score is true for atleast one instance of something
here we always use, and or conjuction symbol Vma9louba

if x is a variable then existential quantifier will be
∃ (X) is read as:
there exists a x
for some “x”
for atleast an “x”


Some more examples
Some boys are intelligent.
x1 is intelli or x2 is intelligent or xn is intelligent
∃x:boy(x) and intelligent (x)

note: IMPORTANTTTTTT

Inference

Inference in FOL is used to dedce new facts sentences from, existing sentences. Before understanding First Logic Inference suite, let’s understand some basic teminologies used in FOL.

1- Substitution
It is a fundamentals operation performed on termas and forumas It occurs in all inference sys in FOL: F[a/x] F[b/x]
substitute a constant “a” in the place of variable.

2- Equality
FOL logic does not only use predicate and terms for making atomic sentence but also uses another way, whch is equality in FOL.
eq, brother (John)= smoth
here the obj reffered by brother (john) is smiliar to obj refered by smoth. The equality symbol can also be used with negation to represent that two terms are notn the same objects.
eq, no(x=y) equivalent to x<>y

FOL Inference rules for quantifiers

=> Pl, we also have inference rules for FOL.

Universal generalization: ∀

It 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 concusions ∀x p(x) r It can be respresented as, P(c)/∀x P(x)
Example: Let’s present , P(C): “ a byte contains 8 bits”
so for ∀xp(x), “ all bytes contain 8 bits” it will also be true

Universal instantiation (eliminiation): ∀

It can be appiled multipl times to add new sentences. The rule says that we can infer any sentence that is premisses of p(c) by substituting a ground term c ( constant within domain x) for ∀x p(x) for any object in the universe of course we have
∀x p(x)/p(c)
Example: Every person like ice-cream => ∀xp(x) we can infer that “ John like ice cream” => P(c).

existential instantiation:(eliminiation) ∃

which is a valid reference rule in FOL. It can only applied only once to replace the existential sentence.
this rule states that one can infer p(c) per the foruma given in the form il existe x p(x) for a new constant syn’c’a
∃xP(x)/P(c)

existential Introductions: ∃

It is also called as existential generalization, this rule states that if there is some element c in the unverise of discourse which has a proerty P, then we can infer that there exists something in the unversie which has property P.
P(c)/il ∃xP(x)
Pinky(c) got good markes in math, therefore someone, got good marks in math, ∃ means(someone)

Unification

It is all about making the expression look identical. So, far the given expressions to make them look idenntical we need to do substitution.
Eg: P(x, F(y)), p(a, F(g(z)), i can say these are identical why ?
Because x=a, y= g(z)
Unification gives, [a/x, g((z)/y]
Because xin place of a, y in place of g(z)

Unifcation Conditions

Unification Algo

=> algorithm, unify (l1, l2)

STEP1

STEP2

If the initial predicate sumbol in l1&l2 are not identical, then return FAIL.

STEP3

If l1&l2 have different number of arguments, then return fail.

STEP4

Set SUBST to nil

STEP5

Loop:
for in<-1 to no f argments in l1:
a) call the unify with the ith argument of l1 and the ith argument of l2 putting result in s
b) if s=FAIL then return FAIL
if s is not equal to NIL Then
(i) apply s to the remaind of both l1&l2«br>(ii) subs= append (s1,subst)

STEP6

return SUBST

Algo Implementation

Step1; Initialize the substituion set be empty

Step2; recursively unify atomic sentences
a) check for identical expression match
b)if one expression a variable and other is a term which does not contain variable vi then:
->substitue ti/vi
-> add ti/vi to the substitution settlist
->if both the expressions are functions, then functions must be similar & number of arguments must be same in both expressions.
eg: p(x,f(y)) and p(a,f(z) ===> f must stay f!!!

Resolution

Resolution is a theorem proving technique that proof by contradictions.
It is used, if there are various stunts are fiven & need to prove a conclusion of those stunt.
Unification is key concept in proofs by resolutionsresolutions is a single reference rule which can efficiently operate on conjunctive normal form or clausal form.

clause: dijunction of literals is called clause.

conjunctive NF: a sentence represented as a conjunction of clauses said to CNF.

Steps for resolution

1- conversion of facts into FOL
2- conver FOL stunt into CNF
3- negate the stunt which eed to prove by contradiction
4- draw resoution graph (unification)

Examples: a- John likes all kind of food
b- apple and vegetable are food
c- anything anoyone eat and not killed is food
d- anil eats peanuts and still alive.
e- henry eats everything that hanry eats
h- prove by resolution that John likes peanuts

Step 1 conversion of facts into FOL

a- ∀x: food(x) -> likes (John, X)
b- food (apple) and food (vegetablees)
c- ∀x∀y: eats(x,y) and not killed(x) -> food(y)
d- eats(anit, peantu)and alive(anil)
e- ∀x: eats (anil,x) -> eats(hanry, x)
f- ∀x: not killed(x) -> alive
g- ∀x:alive(x)->killed(x)
BOTH ARE ADDED PREDICATES
h- likes(John, Peanuts)

Step2: conversion of FOL int CNF

This makes it easier for resulution proofs

### 1- Eliminiate all implications -> & rewrite

a- ∀x: Not food(x) OR likes (John, X)
b- food (apple) and food (vegetablees)
c- ∀x∀y: not[ eats(x,y) and not killed(x)] OR food(y)
d- eats(anit, peantu)and alive(anil)
e- ∀x: noteats (anil,x) or eats(hanry, x)
f- ∀x: not [not killed(x)] or alive
g- ∀x:not[alive(x)] or killed(x) h- likes(John, Peanuts)

### 2- Move negation (not) inwords (inside) “oncher el no” a- ∀x: Not food(x) OR likes (John, X)
b- food (apple) and food (vegetablees)
c- ∀x∀y: not eats(x,y) or killed(x)] and food(y)
//change d- eats(anit, peantu) and alive(anil)
e- ∀x: noteats (anil,x) or eats(hanry, x)
f- ∀x: not [not killed(x)] or alive(x)
g- ∀x:not[alive(x)] or not killed(x) //changes dunno h- likes(John, Peanuts)

### 3- Rename variables or standardize variables

a- ∀x: Not food(x) OR likes (John, X)
b- food (apple) and food (vegetablees)
c- ∀y∀z: not eats(y,z) or killed(y)] and food(z)
//change d- eats(anit, peantu) and alive(anil)
e- ∀x: noteats (anil,x) or eats(hanry, x)
f- ∀g: not killed(g)] or alive(g)
g- ∀k:not[alive(k)] or not killed(k) //changes dunno h- likes(John, Peanuts)

### 4- Eliminate existential instantioation quantifier by eliminiation But in our case there is no existential stuff, so all remain same

5- drop universal quantifiers: (qlqsoit x,y or ilexiste etc)

a- Not food(x) OR likes (John, X)
b- food (apple) and food (vegetablees)
c- not eats(y,z) or killed(y)] and food(z)
//change d- eats(anit, peantu) and alive(anil)
e- noteats (anil,x) or eats(hanry, x)
f- not killed(g)] or alive(g)
g- not[alive(k)] or not killed(k) //changes dunno h- likes(John, Peanuts)

Step3: Negate the statement to be proved

On this stunt, we will apply negation to the conclusion stunt, which will written as (not likes(job, peanuts)

Step4: Draw resolution Graph

Now, in this step, we will solve the problem by resolution tree using substitution, for the above problem it wll be given as

{} Hence Proved (empty)

Examples of Resolution

Structue:Stp1:step2

Forward chaining/Reasoning

It is a form of reasoning which starts with atomic sentences in the knowledge base and applies inference rules in the gorward direction to extract more ddata until a goal is reached.

Properties

Example1

Rule1: if A and C hen F: a&c->f
Rule2: if a and e then a: A&E->A
Rule3: if b then E: B->E
Rule4: if a then d: C->D

**Database: AB
Problem: Proove if a and B true, then d is true: meaning i have to prove A&B->D

## Example2

oal state: Z
Termination condition; Stop if z is derived or no further rule can be applied.


facts: a e b c
rules: f&b->z
c&d->f
a->d

backward chaining

A backward chaining algorithm is a form of reasoning which starts with the goal and works backward, chaining through rules to find know facs to support the goal.

Properties of backward chaining

## EXAMPLE1

## Compare Forward and backwward

AI Techniques

This technique provides a way of solving problems far no more direct approach is available as well as a framwework into which any direct techniques that are can be embedded.

Use of Knowledge

This technique provides a way solving complex problem by explointing the structures of the object that are involved.

Abstraction

This technique provides a ay of separating important features and variations from the many unimportant ones , it hides the details of something.

Eg; if we wan to compute the square root of a no: then simply we call the fun tion sort in c. we do not need to know the implementation details of tis function.
eg, #include; math.h etc.

Conclusion

AI technique is a method that exploits knowledge that should be represented in:


Scopes of Artificial Intelligence

Game Playing | Scope of AI

Game playing is a search problem designed by,


A game must feel Natural

The Game AI is about the illusion of human behavior

Game AI needs various computer science disciplines:

Computer Games Type

1- Strategy Games

Natural Language Processing NLP | Scope of AI

We use the englsh lang to communcate between an intelligent system and NLP. Processing of NL plays an important role in various systems.

Example:

### Components of NLP #### 1- Natural language understanding

#### 2- Natural language generation NGL We have to produce meaningfu phraes and sentences that is in the form of Natural language from internal representation

### Difficulties of NL unit

1- Lexical ambiguity

It is a predefined at a very primitive level such as world-level

2- Sytax level

It this, we can define a sentence in a parsed way or in a different way

3- Refrential ambiguity

It says that we have to refer ti something using pronouns

Step in NLP

1- Lexical analysis

we have to analyze the structure of the words. the collection of words and phrases in lang is lexicon of a lang.

2- Syntactic analysis (Parsing)

we use parsing to the analysis of the word. Although, have to arrange words in an particular manner to show the relationship between the words.

3- Semantic analysis

it describes a dicitonnary meaning which is leaning in the last domain. mapping syntatic structrure and objects

4- Discourse Integration

It this step, the meaning of any sentence depends upon the meaning of the previous sentence. In addion, it brings the meaning to immedaiattlt succeeding sentence

5- Programtic Analysis

In this step data is interpreted on what is actually meant. although we have to derive aspects of the language which reqiuires real world knowledge.


Expert Systems | Scope of AI

The expert systems are the computer applications developed to solve complex problems in a particular domain, at the level of extraordinary human intelligence and expertise.

Characterestics of Expert Systems

Characterestics of Expert Systems

Capable of

INCapable of

Components of Expert Systems

1- Knowledge base

2- Inference Engine

It is the brain of the epert system. It contains rules to solve a specific problem. It selects facts and rules to apply when trying to answer the user query. It provies reasoning about the information in the knowledge base. Inference enginer helps in deducing th problem to find the solution. This comonent is also helpful for formatiting conclusions.

3- User Interface

The process of building an Expert Systems

Expert Systems Applications

Good