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

ES Notes

Uploaded by

Tirth Narwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

ES Notes

Uploaded by

Tirth Narwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

★ Artificial Intelligence | An Introduction

Intelligence: The ability to learn and solve problems.

Artificial Intelligence: to make computers intelligent so that they can act


intelligently!

Artificial Intelligence (AI) refers to the simulation of human intelligence in


machines that are programmed to think and act like humans. It involves the
development of algorithms and computer programs that can perform tasks that
typically require human intelligence such as visual perception, speech
recognition, decision-making, and language translation. AI has the potential to
revolutionize many industries and has a wide range of applications, from
virtual personal assistants to self-driving cars.
Languages used in Artificial Intelligence
Artificial Intelligence has become an important part of human life as we are
now highly dependent on machines. Artificial Intelligence is a very
important technology to develop and build new computer programs and
systems, which can be used to simulate various intelligence processes like
learning, reasoning, etc.

● Python
● R
● Lisp
● Java
● C++
● Julia
● Prolog
1. Python
Python is one of the most powerful and easy programming languages that
anyone can start to learn. Python is initially developed in the early stage of
1991. Most of the developers and programmers choose Python as their
favourite programming language for developing Artificial Intelligence
solutions. Python is worldwide popular among all developers and experts
because it has more career opportunities than any other programming
language.

Python also comes with some default sets of standards libraries and also
provides better community support to its users. Further, Python is a
platform-independent language and also provides an extensive framework for
Deep Learning, Machine Learning, and Artificial Intelligence.

Python is also a portable language as it is used on various platforms such as


Linux, Windows, Mac OS, and UNIX.

Features of Python
● It is easy to learn than any other programming language.
● It is also a dynamically-typed language.
● Python is an Object-oriented language.
● It provides extensive community support and a framework for ML and
DL.
● Open-source.
● Large standard sets of libraries.
● Interpreted language.

Python is an ideal programming language used for Machine Language, Natural


Processing Language (NLP), and Neural networks, etc. Due to the flexible
nature of Python, it can be used for AI development. It contains various
pre-existing libraries such as Pandas, SciPy and nltk, etc. Further, Python
also contains simple syntax and easy coding, which makes Python the first
choice of AI developers and programmers.

There are some standard Libraries in Python used for Artificial


Intelligence as follows:

1. Tensor Flow Python

2. Keras Python

3. Theano Python

4. Scikit-Learn Python

5. PyTorch Python

6. NumPy Python

7. Python Pandas

8. Seaborn Python

2. Java
Java is also the most widely used programming language by all developers and
programmers to develop machine learning solutions and enterprise
development. Similar to Python, Java is also a platform-independent language
as it can also be easily implemented on various platforms. Further, Java is an
object-oriented and scalable programming language. Java allows virtual
machine technology that helps to create a single version of the app and
provides support to your business. The best thing about Java is once it is
written and compiled on one platform, then you do not need to compile it again
and again. This is known as WORA (Once Written Read/Run Anywhere)
principle.

Features of Java

Java has so many features which make Java best in industry and to develop
artificial intelligence applications:

● Portability
● Cross-platform.
● Easy to learn and use.
● Easy-to-code Algorithms.
● Built-in garbage collector.
● Swing and Standard Widget Toolkit.
● Simplified work with large-scale projects.
● Better user interaction.
● Easy to debug.

3. Prolog
Prolog is one of the oldest programming languages used for Artificial
Intelligence solutions. Prolog stands for "Programming in Logic", which was
developed by French scientist Alain Colmerauer in 1970.

For AI programming in Prolog, developers need to define the rules, facts, and
the end goal. After defining these three, the prolog tries to discover the
connection between them. Programming in AI using Prolog is different and has
several advantages and disadvantages.
It may seem like a bizarre language to learn for those programmers who are
from a C++ background.

Prolog may not be a great programming language to build something big, but
it's a great language to study and think about problems in more logical ways
rather than procedural.

Features of Prolog

Supports basic mechanisms such as

● Pattern Matching,
● Tree-based data structuring, and
● Automatic backtracking.
● Prolog is a declarative language rather than imperative.

4. Lisp
Lisp has been around for a very long time and has been widely used for
scientific research in the fields of natural languages, theorem proofs, and to
solve artificial intelligence problems. Lisp was originally created as a practical
mathematical notation for programs but eventually became a top choice of
developers in the field of AI.

Although Lisp programming language is the second oldest language after


Fortran, it is still being used because of its crucial features. The inventor of
LISP programming was John McCarthy, who coined the term Artificial
Intelligence.

Features of LISP
● The program can be easily modified, similar to data.
● Make use of recursion for control structure rather than iteration.
● Garbage Collection is necessary.
● We can easily execute data structures as programs.
● An object can be created dynamically.

5. R
R is one of the great languages for statistical processing in programming.
However, R supports free, open-source programming language for data
analysis purposes. It may not be the perfect language for AI, but it provides
great performance while dealing with large numbers.

Some inbuilt features such as built-in functional programming,


object-oriented nature, and vectorial computation make it a worthwhile
programming language for AI.

R contains several packages that are specially designed for AI, which are:

● gmodels - This package provides different tools for the model fitting task.
● TM - It is a great framework that is used for text mining applications.
● RODBC - It is an ODBC interface.
● OneR - This package is used to implement the One Rule Machine
Learning classification algorithm.

Features of R programming
● R is an open-source programming language, which is free of cost, and
also you can add packages for other functionalities.
● R provides strong & interactive graphics capability to users.
● It enables you to perform complex statistical calculations.
● It is widely used in machine learning and AI due to its high-performance
capabilities.

6. Julia
Julia is one of the newer languages on the list and was created to focus on
performance computing in scientific and technical fields. Julia includes several
features that directly apply to AI programming.

Julia is a comparatively new language, which is mainly suited for numerical


analysis and computational science. It contains several features that can be
very helpful in AI programming.

Features of Julia
● Common numeric data types.
● Arbitrary precision values.
● Robust mathematical functions.
● Tuples, dictionaries, and code introspection.
● Built-in package manager.
● Dynamic type system.
● Ability to work for both parallel and distributed computing.
● Support for multiple dispatches.
● Support for C functions.

7. C++
C++ language has been present for so long around, but still being a top and
popular programming language among developers. It provides better handling
for AI models while developing.

Although C++ may not be the first choice of developers for AI programming,
various machine learning and deep learning libraries are written in the C++
language.

Features of C++
● C++ is one of the fastest languages, and it can be used in statistical
techniques.
● It can be used with ML algorithms for fast execution.
● Most of the libraries and packages available for Machine learning and AI
are written in C++.
● It is a user friendly and simple language.

★ BFS, DFS

In Artificial Intelligence, Search techniques are universal problem-solving


methods. Rational agents or Problem-solving agents in AI mostly used these
search strategies or algorithms to solve a specific problem and provide the best
result. Problem-solving agents are the goal-based agents and use atomic
representation.

Types of search algorithms:

Based on the search problems we can classify the search algorithms into
uninformed (Blind search) search and informed search (Heuristic search)
algorithms.
Based on the search problems we can classify the search algorithms into
uninformed (Blind search) search and informed search (Heuristic search)
algorithms.

Uninformed search algorithms do not have additional information about state


or search space other than how to traverse the tree, so it is also called blind
search.

BFS for Graph and Tree traversal:


To avoid processing a node more than once, we divide the vertices into two
categories:
● Visited and
● Not visited.

A boolean visited array is used to mark the visited vertices. For simplicity, it is
assumed that all vertices are reachable from the starting vertex. BFS uses a
queue data structure for traversal.
How does BFS work?
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 every vertex, we can also run the BFS algorithm on every node

Undirected graph with 5 vertices

We start from vertex 0, the BFS algorithm starts by putting it in the Visited list
and putting all its adjacent vertices in the stack.
Visit start
vertex and add its adjacent vertices to queue

Next, we visit the element at the front of queue i.e. 1 and go to its adjacent
nodes. Since 0 has already been visited, we visit 2 instead.

Visit the
first neighbour of start node 0, which is 1

Vertex 2 has an unvisited adjacent vertex in 4, so we add that to the back of the
queue and visit 3, which is at the front of the queue.
Visit 2
which was added to queue earlier to add its neighbours

4 remains
in the queue
Only 4 remains in the queue since the only adjacent node of 3 i.e. 0 is already
visited. We visit it.

Visit last
remaining item in the queue to check if it has unvisited neighbors
Since the queue is empty, we have completed the Breadth First Traversal of the
graph.

Depth First Search or DFS for a Graph


Depth first Search or Depth first traversal is a recursive algorithm for
searching all the vertices of a graph or tree data structure. Traversal means
visiting all the nodes of a graph.
The DFS algorithm works as follows:

1. Start by putting any one of the graph's vertices on top of a stack.


2. Take the top item of the stack 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 top of the stack.
4. Keep repeating steps 2 and 3 until the stack is empty.

Undirected graph with 5 vertices


We start from vertex 0, the DFS algorithm starts by putting it in the Visited list
and putting all its adjacent vertices in the stack.
Visit the
element and put it in the visited list
Next, we visit the element at the top of stack i.e. 1 and go to its adjacent nodes.
Since 0 has already been visited, we visit 2 instead.

Visit the
element at the top of stack
Vertex 2 has an unvisited adjacent vertex in 4, so we add that to the top of the
stack and visit it.

Vertex 2
has an unvisited adjacent vertex in 4, so we add that to the top of the stack and
visit it.
Vertex 2 has an unvisited adjacent vertex in 4, so we add that to the top of the
stack and visit it.
After we visit the last element 3, it doesn't have any unvisited adjacent nodes,
so we have completed the Depth First Traversal of the graph.

After we
visit the last element 3, it doesn't have any unvisited adjacent nodes, so we
have completed the Depth First Traversal of the graph.

Heuristics?

Heuristics are used in situations in which there is the requirement of a


short-term solution. On facing complex situations with limited resources and
time, Heuristics can help the companies to make quick decisions by shortcuts
and approximated calculations. Most of the heuristic methods involve mental
shortcuts to make decisions on past experiences.

We can perform the Heuristic techniques into two categories:


Direct Heuristic Search techniques in AI

It includes Blind Search, Uninformed Search, and Blind control strategy. These
search techniques are not always possible as they require much memory and
time. These techniques search the complete space for a solution and use the
arbitrary ordering of operations.

The examples of Direct Heuristic search techniques include Breadth-First


Search (BFS) and Depth First Search (DFS).

Weak Heuristic Search techniques in AI

It includes Informed Search, Heuristic Search, and Heuristic control strategy.


These techniques are helpful when they are applied properly to the right types
of tasks. They usually require domain-specific information.

The examples of Weak Heuristic search techniques include Best First Search
(BFS) and A*, Hill Climbing

Hill Climbing Algorithm


Hill climbing is a simple optimization algorithm used in Artificial Intelligence
(AI) to find the best possible solution for a given problem. It belongs to the
family of local search algorithms and is often used in optimization problems
where the goal is to find the best solution from a set of possible solutions.
In Hill Climbing, the algorithm starts with an initial solution and then
iteratively makes small changes to it in order to improve the solution. These
changes are based on a heuristic function that evaluates the quality of the
solution. The algorithm continues to make these small changes until it reaches
a local maximum, meaning that no further improvement can be made with the
current set of moves.
○ 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.

Features of Hill Climbing:

Following are some main features of Hill Climbing Algorithm:

○ Generate and Test variant: Hill Climbing is the variant of Generate and
Test method. The Generate and Test method produce feedback which
helps to decide which direction to move in the search space.
○ Greedy approach: Hill-climbing algorithm search moves in the direction
which optimizes the cost.

○ No backtracking: It does not backtrack the search space, as it does not


remember the previous states.

Advantages of Hill Climbing algorithm:

1. Hill Climbing is a simple and intuitive algorithm that is easy to


understand and implement.
2. It can be used in a wide variety of optimization problems, including
those with a large search space and complex constraints.
3. Hill Climbing is often very efficient in finding local optima, making it
a good choice for problems where a good solution is needed quickly.
4. The algorithm can be easily modified and extended to include
additional heuristics or constraints.

Disadvantages of Hill Climbing algorithm:

1. Hill Climbing can get stuck in local optima, meaning that it may not
find the global optimum of the problem.
2. The algorithm is sensitive to the choice of initial solution, and a poor
initial solution may result in a poor final solution.
3. Hill Climbing does not explore the search space very thoroughly,
which can limit its ability to find better solutions.
4. It may be less effective than other optimization algorithms, such as
genetic algorithms or simulated annealing, for certain types of
problems.

Types of Hill Climbing


○ 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 sets it as a current state. It
only checks its 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:

a. If it is goal state, then return success and quit.

b. Else if it is better than the current state then assign new state as a
current state.
c. 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.

a. Let SUCC be a state such that any successor of the current state will
be better than it.

b. For each operator that applies to the current state:

a. Apply the new operator and generate a new state.

b. Evaluate the new state.

c. If it is goal state, then return it and quit, else compare it to the


SUCC.

d. If it is better than SUCC, then set new state as SUCC.


e. 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.

Problems with Hill Climbing in AI

We usually run into one of three issues-

● Local Maximum- All neighboring states have values worse than the
current. The greedy approach means we won’t be moving to a worse
state. This terminates the process even though there may have been a
better solution. As a workaround, we use backtracking.
● Plateau- All neighbors to it have the same value. This makes it
impossible to choose a direction. To avoid this, we randomly make a
big jump.
● Ridge- At a ridge, movement in all possible directions is downward.
This makes it look like a peak and terminates the process. To avoid
this, we may use two or more rules before testing.

Best first search (BFS)

This algorithm always chooses the path which appears best at that moment. It
is the combination of depth-first search and breadth-first search algorithms. It
lets us to take the benefit of both algorithms. It uses the heuristic function and
search. With the help of the best-first search, at each step, we can choose the
most promising node.

Best first search algorithm:

Step 1: Place the starting node into the OPEN list.

Step 2: If the OPEN list is empty, Stop and return failure.

Step 3: Remove the node n from the OPEN list, which has the lowest value of
h(n), and places it in the CLOSED list.

Step 4: Expand the node n, and generate the successors of node n.

Step 5: Check each successor of node n, and find whether any node is a goal
node or not. If any successor node is the goal node, then return success and
stop the search, else continue to next step.

Step 6: For each successor node, the algorithm checks for evaluation function
f(n) and then check if the node has been in either OPEN or CLOSED list. If the
node has not been in both lists, then add it to the OPEN list.

Step 7: Return to Step 2.

Advantages:

○ Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.

○ This algorithm is more efficient than BFS and DFS algorithms.

Disadvantages:

○ It can behave as an unguided depth-first search in the worst case scenario.

○ It can get stuck in a loop as DFS.


○ This algorithm is not optimal.

A* Search Algorithm

A* search is the most commonly known form of best-first search. It uses the
heuristic function h(n) and cost to reach the node n from the start state g(n). It
has combined features of UCS and greedy best-first search, by which it solve
the problem efficiently.

It finds the shortest path through the search space using the heuristic function.
This search algorithm expands fewer search tree and gives optimal results
faster.

Algorithm of A* search:

Step 1: Place the starting node in the OPEN list.

Step 2: Check if the OPEN list is empty or not. If the list is empty, then return
failure and stops.

Step 3: Select the node from the OPEN list which has the smallest value of the
evaluation function (g+h). If node n is the goal node, then return success and
stop, otherwise.

Step 4: Expand node n and generate all of its successors, and put n into the
closed list. For each successor n', check whether n' is already in the OPEN or
CLOSED list. If not, then compute the evaluation function for n' and place it
into the Open list.

Step 5: Else, if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.

Step 6: Return to Step 2.

You might also like