Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

INDIRA GANDHI DELHI TECHNICAL UNIVERSITY

FOR WOMEN

Name : Simone Singh


Batch : ECE-AI 1
Year : 2021-2025
Submitted to : Ms. Vidhi Vishnoi
Subject : Neural Networks and Artificial Intelligence
Experiment 1
Aim : Introduction to Artificial Intelligence and its applications.
THEORY

Artificial Intelligence is a way of making a computer, a computer-


controlled robot, or a software think intelligently, in the similar manner
the intelligent humans think.

AI is accomplished by studying how human brain thinks, and how


humans learn, decide, and work while trying to solve a problem, and then
using the outcomes of this study as a basis of developing intelligent
software and systems.

An AI system is composed of an agent and its environment. An


agent(e.g., human or robot) is anything that can perceive its environment
through sensors and acts upon that environment through effectors.
Intelligent agents must be able to set goals and achieve them. In classical
planning problems, the agent can assume that it is the only system acting
in the world, allowing the agent to be certain of the consequences of its
actions. However, if the agent is not the only actor, then it requires that
the agent can reason under uncertainty. This calls for an agent that cannot
only assess its environment and make predictions but also evaluate its
predictions and adapt based on its assessment. Natural language
processing gives machines the ability to read and understand human
language. Some straightforward applications of natural language
processing include information retrieval, text mining, question answering,
and machine translation. Machine perception is the ability to use input
from sensors (such as cameras, microphones, sensors, etc.) to deduce
aspects of the world. e.g., Computer Vision. Concepts such as game
theory, and decision theory, necessitate that an agent can detect and
model human emotions. 

Applications of AI

AI has been dominant in various fields such as −


Gaming − AI plays crucial role in strategic games such as chess, poker,
tic-tac-toe, etc., where machine can think of large number of possible
positions based on heuristic knowledge.

Natural Language Processing − It is possible to interact with the


computer that understands natural language spoken by humans.

Expert Systems − There are some applications which integrate machine,


software, and special information to impart reasoning and advising. They
provide explanation and advice to the users.

Vision Systems − These systems understand, interpret, and comprehend


visual input on the computer. For example,

A spying aeroplane takes photographs, which are used to figure out


spatial information or map of the areas.

Doctors use clinical expert system to diagnose the patient.

Police use computer software that can recognize the face of criminal with
the stored portrait made by forensic artist.

Speech Recognition − Some intelligent systems are capable of hearing


and comprehending the language in terms of sentences and their
meanings while a human talks to it. It can handle different accents, slang
words, noise in the background, change in human’s noise due to cold, etc.

Handwriting Recognition − The handwriting recognition software reads


the text written on paper by a pen or on screen by a stylus. It can
recognize the shapes of the letters and convert it into editable text.

Intelligent Robots − Robots are able to perform the tasks given by a


human. They have sensors to detect physical data from the real world
such as light, heat, temperature, movement, sound, bump, and pressure.
They have efficient processors, multiple sensors and huge memory, to
exhibit intelligence. In addition, they are capable of learning from their
mistakes and they can adapt to the new environment.
EXPERIMENT 2
AIM : Write a program to implement the Hill climbing techniques.
THEORY

Hill Climbing Algorithms in AI


Hill climbing algorithm is a local search algorithm which continuously moves
in the direction of increasing elevation/value to find the peak of the mountain or
best solution to the problem. It terminates when it reaches a peak value where
no neighbor has a higher value.
Hill climbing algorithm is a technique which is used for optimizing the
mathematical problems. One of the widely discussed examples of Hill climbing
algorithm is Traveling-salesman Problem in which we need to minimize the
distance traveled by the salesman.
It is also called greedy local search as it only looks to its good immediate
neighbor state and not beyond that.
A node of hill climbing algorithm has two components which are state and
value.
Hill Climbing is mostly used when a good heuristic is available.
In this algorithm, we don't need to maintain and handle the search tree or graph
as it only keeps a single current state.
Types of Hill Climbing Algorithm:
Simple hill Climbing:
Steepest-Ascent hill-climbing:
Stochastic hill Climbing:
1. Simple Hill Climbing:
Simple hill climbing is the simplest way to implement a hill climbing algorithm.
It only evaluates the neighbor node state at a time and selects the first one which
optimizes current cost and set it as a current state. It only checks it's one
successor state, and if it finds better than the current state, then move else be in
the same state. This algorithm has the following features:
Less time consuming
Less optimal solution and the solution is not guaranteed
Algorithm for Simple Hill Climbing:
Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Step 3: Select and apply an operator to the current state.
Step 4: Check new state:
If it is goal state, then return success and quit.
Else if it is better than the current state then assign new state as a current state.
Else if not better than the current state, then return to step2.
Step 5: Exit.
2. Steepest-Ascent hill climbing:
The steepest-Ascent algorithm is a variation of simple hill climbing algorithm.
This algorithm examines all the neighboring nodes of the current state and
selects one neighbor node which is closest to the goal state. This algorithm
consumes more time as it searches for multiple neighbors

Algorithm for Steepest-Ascent hill climbing:


Step 1: Evaluate the initial state, if it is goal state then return success and stop,
else make current state as initial state.
Step 2: Loop until a solution is found or the current state does not change.
Let SUCC be a state such that any successor of the current state will be better
than it.
For each operator that applies to the current state:
Apply the new operator and generate a new state.
Evaluate the new state.
If it is goal state, then return it and quit, else compare it to the SUCC.
If it is better than SUCC, then set new state as SUCC.
If the SUCC is better than the current state, then set current state to SUCC.
Step 5: Exit.
3. Stochastic hill climbing:
Stochastic hill climbing does not examine for all its neighbor before moving.
Rather, this search algorithm selects one neighbor node at random and decides
whether to choose it as a current state or examine another state.
3. Stochastic hill climbing:
Stochastic hill climbing does not examine for all its neighbor before moving.
Rather, this search algorithm selects one neighbor node at random and decides
whether to choose it as a current state or examine another state.
EXPERIMENT 3
AIM : Write a program to implement the BFS search method.
THEORY

BFS can be used to find the neighboring locations from a given source
location.In a peer-to-peer network, BFS algorithm can be used as a traversal
method to find all the neighboring nodes. Most torrent clients, such as
BitTorrent, uTorrent, etc. employ this process to find "seeds" and "peers" in
the network.

BFS can be used in web crawlers to create web page indexes. It is one of the
main algorithms that can be used to index web pages. It starts traversing
from the source page and follows the links associated with the page. Here,
every web page is considered as a node in the graph.BFS is used to
determine the shortest path and minimum spanning tree.BFS is also used in
Cheney's technique to duplicate the garbage collection.It can be used in ford-
Fulkerson method to compute the maximum flow in a flow network.

A standard BFS implementation puts each vertex of the graph into one of
two categories:

1. Visited
2. Not Visited

The purpose of the algorithm is to mark each vertex as visited while


avoiding cycles.

The algorithm works as follows:

1. Start by putting any one of the graph's vertices at the back of a queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in
the visited list to the back of the queue.
4. Keep repeating steps 2 and 3 until the queue is empty.
The graph might have two different disconnected parts so to make sure that
we cover
EXPERIMENT 4
AIM: Write a program to implement inform A* search method.
THEORY
A-star (also referred to as A*) is one of the most successful search
algorithms to find the shortest path between nodes or graphs. It is
an informed search algorithm, as it uses information about path cost
and also uses heuristics to find the solution.
Node (also called State) — All potential position or stops with
a unique identification
Transition — The act of moving between states or nodes.
Starting Node — Whereto start searching
Goal Node — The target to stop searching.
Search Space — A collection of nodes, like all board
positions of a board game
Cost — Numerical value (say distance, time, or financial
expense) for the path from a node to another node.
g(n) — this represents the exact cost of the path from the
starting node to any node n
h(n) — this represents the heuristic estimated cost from node
n to the goal node.
f(n) — lowest cost in the neighboring node n
Each time A* enters a node, it calculates the cost, f(n)(n being
the neighboring node), to travel to all of the neighboring
nodes, and then enters the node with the lowest value of f(n).

These values we calculate using the following formula:


f(n) = g(n) + h(n)

IMPLEMENTATION
OUTPUT
EXPERIMENT 5
AIM: Write a program to implement a Tic-Tac-Toe game.
THEORY
Tic Tac Toe is a very common two player mind game. It is liked by people of
all age groups. Its working is very simple. A play area of 3X3 boxes is defined.
The player who first marks any row or column or diagonal of three boxes with
his symbol(O or X) wins the game. It is not that difficult to code either. In this
post we will share Tic Tac Toe Python Code with you and explain the logic of
this code.

When the player clicks in a box, these things happen

 The point clicked in the window is recorded by using


getMouse method which returns a Point object. According
to current player X or 0 is drawn at that position. The
symbol is toggled to change to the turn of other player
 This point is checked against the corner values of the
boxes stored in two arrays arrf and arrt. According to the
position of the box, its index(1-9) is appended to the array
that stores the all the clicked boxes by current player. For
two players two such arrays are maintained p1 and p2.
 All possible winning combinations are generated using
combinations and permutations methods of combinations
and permutations modules.
 The array that stores the clicked box indices by player is
used to generate all the possible 3 digit combinations for
that player.
 Whenever a player has clicked more than 3 boxes it’s
possible permutations are generated. All these are checked
against all the possible winning combinations. If a
combination generated for a player matches a winning
combination, the winner is declared winner by drawing the
Text object at the bottom of the game board.
OUTPUT
EXPERIMENT 6
AIM : Write a program to show the back-propagation network for the X-OR
function.
THEORY
Implementing logic gates using neural networks help understand
the mathematical computation by which a neural network processes
its inputs to arrive at a certain output. This neural network will deal
with the XOR logic problem. An XOR (exclusive OR gate) is a digital
logic gate that gives a true output only when both its inputs differ
from each other. The truth table for an XOR gate is shown below:

The goal of the neural network is to classify the input patterns


according to the above truth table. If the input patterns are
plotted according to their outputs, it is seen that these points
are not linearly separable. Hence the neural network has to be
modeled to separate these input patterns using decision
planes.
EXPERIMENT 7
AIM :Write a program to implement an artificial neural network with
backpropagation
THEORY
Backpropagation, short for backward propagation of errors
, is a widely used method for calculating derivatives inside deep feedforward
neural networks . Backpropagation forms an important part of a number
of supervised learning algorithms for training feedforward neural networks,
stochastic gradient descend.
When training a neural network by gradient descent, a loss function is
calculated, which represents how far the network's predictions are from the true
labels. Backpropagation allows us to calculate the gradient of the loss function
with respect to each of the weights of the network. This enables every weight to
be updated individually to gradually reduce the loss function over many training
iterations.
IMPLEMENTATION
OUTPUT

You might also like