ES Notes
ES Notes
● 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.
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.
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
● 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.
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.
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.
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
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.
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.
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
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.
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?
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 Weak Heuristic search techniques include Best First Search
(BFS) and A*, Hill Climbing
○ 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.
○ In this algorithm, we don't need to maintain and handle the search tree or
graph as it only keeps a single current state.
○ 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.
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.
○ Steepest-Ascent hill-climbing:
○ Step 1: Evaluate the initial state, if it is goal state then return success and
Stop.
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.
○ 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.
○ Step 5: Exit.
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.
● 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.
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.
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 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.
Advantages:
○ Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.
Disadvantages:
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 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.