0% found this document useful (0 votes)
2 views77 pages

Unit 5 Machine Language

Machine learning is a subset of artificial intelligence that enables computers to learn from data and improve over time without explicit programming. It encompasses various applications, including supervised learning, unsupervised learning, and reinforcement learning, each with distinct methods and use cases. The document outlines the definitions, types, algorithms, and real-world applications of machine learning, highlighting its significance in fields such as computer vision, natural language processing, and medical diagnosis.

Uploaded by

Lok Regmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views77 pages

Unit 5 Machine Language

Machine learning is a subset of artificial intelligence that enables computers to learn from data and improve over time without explicit programming. It encompasses various applications, including supervised learning, unsupervised learning, and reinforcement learning, each with distinct methods and use cases. The document outlines the definitions, types, algorithms, and real-world applications of machine learning, highlighting its significance in fields such as computer vision, natural language processing, and medical diagnosis.

Uploaded by

Lok Regmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Introduction:

Machine learning is a sub field of Artificial Intelligence that provides computer the ability
to learn and improve its learning from experience without being written rules explicitly.
The machine start learning with observations or data, in order to look for patterns in data and
make better decisions in the future based on the examples that it has been provided.

Some of the successful application of machine learning are:

. Computer Vision processing


. Natural Language processing
. Forecasting
. Pattern recognition
. Games
. Expert systems and so on

Sandesh Shiwakoti-9815945474
Machine Learning and Artificial Intelligence

Artificial intelligence refers to a very large field of research that encompasses a number of
techniques aimed at developing computers that can learn and solve problems whereas machine
learning is the field of artificial intelligence concerned with learning from data on its own.

Artificial Intelligence

Machine Learning
Algorithms that can learn from data

Sandesh Shiwakoti-9815945474
Machine Learning Definition:

According to Tom Mitchell “ A computer program is set to learn from experience E with respect
to some class of tasks T and performance major P if its performance at tasks in T, as measured by
P improves with experience E.

Machine learning research is part of research on artificial intelligence seeking to provide


knowledge to computers through data, observations and interacting with the world. That
acquired knowledge allows computers to correctly generalize to new settings
(Yoshua Bengio, Turing Award Winner-2019)

Machine learning is the since of getting computers to act without being explicitly programmed,
but instead letting them learn a few tricks on their own(Danko Nikolic, Max-plank Institute)

Sandesh Shiwakoti-9815945474
The difference between traditional programming and machine learning

Sandesh Shiwakoti-9815945474
General Machine Learning agent framework or architecture

The following figure represents the general steps involved in machine learning agent. It learns
from Inputs and corrects its decision based on the feedback provided by critic.

Sandesh Shiwakoti-9815945474
It consists of the following components.
1. Learning element
2. Knowledge base
3. Performance element
4. Feedback element (critic)
5. Standard system
Learning element:
it receives and processes the input obtained from a person, from reference material like magazines,
journals etc. or from the environment at large.

Knowledge Base:
This is somewhat similar to the database. Initially it may contain some basic knowledge. Thereafter it
receives more knowledge which may be new and so be added as it is or it may place the existing knowledge.

Performance element:
It uses the updated knowledge base to perform some task or solves some problems and
produces the corresponding output.

Feedback element:
It receiving the two inputs, one from learning elements and one through standard system this is
to identify the differences between the two inputs. The feedback is used to determine what should be done in
Sandesh Shiwakoti-9815945474
order to produce the correct output.
Standard System:
It is a trained person or a computer program that is able to produce correct
output. In order to check whether the machine learning system has learned well, the same input
is given to the standard system. The output of a standard system and that of performance
element are given as input to the feedback element for the comparison. Standard system is also
called the idealized system.

Why Learning?

➢ To understand and improve efficiency of human learning.


➢ To discover new things or structure that is unknown to human.
Types of Machine Learning

The strategies for learning can be classified according to the amount of inference to the system has to perform on its
training data. In increasing order we have :
The 3 broad categories of machine learning algorithms are :
1. Supervised Learning
2. Unsupervised Learning
3. Reinforcement learning Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Supervised learning

• Supervised learning is where you have input variables (x) and an output variable (Y) and you
use an algorithm to learn the mapping function from the input to the output. Y = f(X)

• Learning stops when the algorithm achieves an acceptable level of performance.

• when you have new input data (x) that you can predict the output variables (Y) for that data.

• It is called supervised learning because the process of an algorithm learning from the
training dataset can be thought of as a teacher supervising the learning process.

• We know the correct answers, the algorithm iteratively makes predictions on the training
data and is corrected by the teacher.

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Classification

Classification algorithms are used to group data by predicting a categorical label


or output variable based on the input data. Classification is used when output
variables are categorical, meaning there are two or more classes.

One of the most common examples of classification algorithms in use is the


spam filter in your email inbox. Here, a supervised learning model is trained to
predict whether an email is spam or not with a dataset that contains labeled
examples of both spam and legitimate emails. The algorithm extracts information
about each email, including the sender, the subject line, body copy, and more. It
then uses these features and corresponding output labels to learn patterns and
assign a score that indicates whether an email is real or spam.

Sandesh Shiwakoti-9815945474
Regression

Regression algorithms are used to predict a real or continuous value,


where the algorithm detects a relationship between two or more
variables.

A common example of a regression task might be predicting a salary


based on work experience. For instance, a supervised learning algorithm
would be fed inputs related to work experience (e.g., length of time, the
industry or field, location, etc.) and the corresponding assigned salary
amount. After the model is trained, it could be used to predict the
average salary based on work experience.
Sandesh Shiwakoti-9815945474
Classification Algorithms:
These algorithms predict discrete labels or categories. Here are some examples:

Linear Classifiers: These separate data points using linear decision boundaries.
Support Vector Machines (SVM): Find the best hyperplane to separate classes.
Decision Trees: Hierarchical structures that split data based on features.
k-Nearest Neighbors (k-NN): Classify based on nearest neighbors.
Random Forests: Ensembles of decision trees.
Naïve bayes:
Regression Algorithms:
These predict continuous values. Key regression algorithms include:

Linear Regression: Fits a linear model to data points.


Logistic Regression: Used for binary classification.
Polynomial Regression: Extends linear models with polynomial terms.
Sandesh Shiwakoti-9815945474
Applications of Supervised learning
•Email Spam Detection:
•Problem: Classifying emails as "spam" or "not spam".
•Application: Email services use classification algorithms to filter out unwanted emails
and protect users from potential phishing and spam messages.

•Medical Diagnosis:
•Problem: Classifying medical images or patient data as "diseased" or "healthy".
•Application: Doctors and healthcare systems use machine learning to diagnose diseases
such as cancer, diabetes, and heart conditions from medical imaging or patient data.

•Image Recognition:
•Problem: Classifying images into different categories, such as "cat", "dog", "car",
"person", etc.
•Application: Used in various applications, including social media tagging, autonomous
vehicles, and security systems.
Sandesh Shiwakoti-9815945474
•Sentiment Analysis:

•Problem: Classifying text data as having "positive", "negative", or "neutral" sentiment.


•Application: Companies analyze customer reviews, social media posts, and feedback to
gauge public sentiment about products or services.

•Document Classification:

•Problem: Classifying documents into predefined categories (e.g., "legal", "financial",


"technical").
•Application: Used in information retrieval systems, digital libraries, and enterprise content
management systems to organize and retrieve documents efficiently.

•Disease Outbreak Prediction:


•Problem: Classifying regions or populations as "high risk" or "low risk" for disease
outbreaks.
•Application: Public health organizations use classification models to predict and respond
to potential disease outbreaks, improving
Sandeshpreventive
Shiwakoti-9815945474measures and resource allocation.
Unsupervised Learning
• Unsupervised learning is where you only have input data (X) and no corresponding
output variables(targets/ labels).

• The goal for unsupervised learning is to model the underlying structure or distribution in
the data in order to learn more about the data.

• These are called unsupervised learning because unlike supervised learning above there is
no correct answers and there is no teacher.

• Algorithms are left to their own devises to discover and present the interesting structure
in the data.

Sandesh Shiwakoti-9815945474
Unsupervised learning in artificial intelligence is a type of machine learning that learns from
data without human supervision. Unlike supervised learning, unsupervised machine learning
models are given unlabeled data and allowed to discover patterns and insights without any
explicit guidance or instruction.

As the name suggests, unsupervised learning uses self-learning algorithms—they learn without
any labels or prior training. Instead, the model is given raw, unlabeled data and has to infer its
own rules and structure the information based on similarities, differences, and patterns without
explicit instructions on how to work with each piece of data.
Unsupervised learning algorithms are better suited for more complex processing tasks, such as
organizing large datasets into clusters.
Imagine that you have a large dataset about weather. An unsupervised learning algorithm will go
through the data and identify patterns in the data points. For instance, it might group data by
temperature or similar weather patterns.

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Unsupervised machine learning methods
In general, there are three types of unsupervised learning tasks: clustering, association rules, and dimensionality
reduction.
Clustering
Clustering is a technique for exploring raw, unlabeled data and breaking it down into groups (or clusters) based on
similarities or differences. It is used in a variety of applications, including customer segmentation, fraud detection,
and image analysis. Clustering algorithms split data into natural groups by finding similar structures or patterns in
uncategorized data.

Association
Association rule mining is a rule-based approach to reveal interesting relationships between data points in large
datasets. Unsupervised learning algorithms search for frequent if-then associations—also called rules—to discover
correlations and co-occurrences within the data and the different connections between data objects.
It is most commonly used to analyze retail baskets or transactional datasets to represent how often certain items
are purchased together. These algorithms uncover customer purchasing patterns and previously hidden
relationships between products that help inform recommendation engines or other cross-selling opportunities. You
might be most familiar with these rules from the “Frequently bought together” and “People who bought this item
also bought” sections on your favorite online retail shop.
Association rules are also often used to organize medical datasets for clinical diagnoses. Using unsupervised
machine learning and association rules can help doctors identify the probability of a specific diagnosis by comparing
relationships between symptoms from past patient cases.
Sandesh Shiwakoti-9815945474
Real-world unsupervised learning examples
Now that you understand the basics of how unsupervised learning works, let’s look at the most
common use cases helping businesses explore large volumes of data quickly.

Here are some real-world unsupervised learning examples:


•Anomaly detection: Unsupervised clustering can process large datasets and discover data
points that are a typical in a dataset.
•Recommendation engines: Using association rules, unsupervised machine learning can help
explore transactional data to discover patterns or trends that can be used to drive personalized
recommendations for online retailers.
•Customer segmentation: Unsupervised learning is also commonly used to generate buyer
persona profiles by clustering customers’ common traits or purchasing behaviors. These profiles
can then be used to guide marketing and other business strategies.

Sandesh Shiwakoti-9815945474
•Fraud detection: Unsupervised learning is useful for anomaly detection, revealing
unusual data points in datasets. These insights can help uncover events or
behaviors that deviate from normal patterns in the data, revealing fraudulent
transactions or unusual behavior like bot activity.
•Natural language processing (NLP): Unsupervised learning is commonly used for
various NLP applications, such as categorizing articles in news sections, text
translation and classification, or speech recognition in conversational interfaces.
•Genetic research: Genetic clustering is another common unsupervised learning
example. Hierarchical clustering algorithms are often used to analyze DNA patterns
and reveal evolutionary relationships.
Unsupervised learning is well suited for tasks that require exploring large amounts
of unlabeled data. This approach makes it easier for businesses to gain insights
from data when no labels are present, helping them to understand the underlying
structure of a dataset and identify patterns and relationships between datasets
without the need for a human to teach them.
Sandesh Shiwakoti-9815945474
cheese
Bread Jam

Milk

Sugar

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Reinforcement learning
• Is learning behavior through trial-and-error interactions with a environment.

• Is learning about how to act in order to maximize a reward (Encouragements).

• Reinforcement learning emphasizes learning feedback that evaluates the learner's


performance without providing standards of correctness in the form of behavioral targets.

• Example: Bicycle learning, game playing, etc.

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Reinforcement learning (RL) is a machine learning (ML) technique that trains software to make
decisions to achieve the most optimal results. It mimics the trial-and-error learning process that
humans use to achieve their goals. Software actions that work towards your goal are reinforced,
while actions that detract from the goal are ignored.
benefits of reinforcement learning?
Excels in complex environments Optimizes for long-term goals Optimizes for long-term goals

Key concepts
In reinforcement learning, there are a few key concepts to familiarize yourself with:
•The agent is the ML algorithm (or the autonomous system)
•The environment is the adaptive problem space with attributes such as variables, boundary
values, rules, and valid actions
•The action is a step that the RL agent takes to navigate the environment
•The state is the environment at a given point in time
•The reward is the positive, negative, or zero value—in other words, the reward or
punishment—for taking an action
•The cumulative reward is the sum of allSandesh
rewards or the end value
Shiwakoti-9815945474
What are the types of reinforcement learning algorithms?
There are various algorithms used in reinforcement learning (RL)—such as Q-learning, policy gradient methods,
Monte Carlo methods, and temporal difference learning. Deep RL is the application of deep neural networks to
reinforcement learning. One example of a deep RL algorithm is Trust Region Policy Optimization (TRPO).
All these algorithms can be grouped into two broad categories.

Model-based RL
Model-based RL is typically used when environments are well-defined and unchanging and where real-world
environment testing is difficult.
The agent first builds an internal representation (model) of the environment. It uses this process to build this model:
1.It takes actions within the environment and notes the new state and reward value
2.It associates the action-state transition with the reward value.
Once the model is complete, the agent simulates action sequences based on the probability of optimal cumulative
rewards. It then further assigns values to the action sequences themselves. The agent thus develops different
strategies within the environment to achieve the desired end goal.

Example
Consider a robot learning to navigate a new building to reach a specific room. Initially, the robot explores freely and
builds an internal model (or map) of the building. For instance, it might learn that it encounters an elevator after
moving forward 10 meters from the main entrance. Once it builds the map, it can build a series of shortest-path
sequences between different locations it visits frequently in the building.
Sandesh Shiwakoti-9815945474
Model-free RL
Model-free RL is best to use when the environment is large, complex, and not easily describable.
It’s also ideal when the environment is unknown and changing, and environment-based testing
does not come with significant downsides.
The agent doesn’t build an internal model of the environment and its dynamics. Instead, it uses
a trial-and-error approach within the environment. It scores and notes state-action pairs—and
sequences of state-action pairs—to develop a policy.

Example
Consider a self-driving car that needs to navigate city traffic. Roads, traffic patterns, pedestrian
behavior, and countless other factors can make the environment highly dynamic and complex. AI
teams train the vehicle in a simulated environment in the initial stages. The vehicle takes actions
based on its current state and receives rewards or penalties.
Over time, by driving millions of miles in different virtual scenarios, the vehicle learns which
actions are best for each state without explicitly modeling the entire traffic dynamics. When
introduced in the real world, the vehicle uses the learned policy but continues to refine it with
new data. Sandesh Shiwakoti-9815945474
Different Approaches in Machine Learning

1. Supervised Learning:
•Definition: Learning from labeled data to make predictions or classify data.
•Examples: Linear regression, logistic regression, support vector machines (SVMs), neural
networks.

2. Unsupervised Learning:
•Definition: Learning from unlabeled data to find patterns or structure in the data.
•Examples: K-means clustering, principal component analysis (PCA), autoencoders, Hebbian
learning-based algorithms.

3. Reinforcement Learning:
•Definition: Learning by interacting with an environment to maximize cumulative reward.
•Examples: Q-learning, deep Q-networks (DQNs), policy gradient methods, genetic algorithms
for policy optimization.
Sandesh Shiwakoti-9815945474
Fundamental Concepts Used Across All Types of Learning

1. Statistical Models:
•Application in Supervised Learning: Used for making predictions and classifications (e.g., linear
regression, logistic regression).
•Application in Unsupervised Learning: Used for clustering and dimensionality reduction (e.g., K-
means, PCA).
•Application in Reinforcement Learning: Sometimes used for modeling environment dynamics
or value functions (e.g., Hidden Markov Models).

2. Neural Network Models:


•Application in Supervised Learning: Widely used for tasks requiring pattern recognition and
prediction (e.g., CNNs for image classification, RNNs for sequence prediction).
•Application in Unsupervised Learning: Used for learning representations and generative models
(e.g., autoencoders, GANs).
•Application in Reinforcement Learning: Used for approximating value functions and policies
(e.g., DQNs, policy gradient methods).
Sandesh Shiwakoti-9815945474
3. Hebbian Learning:
•Application in Supervised Learning: Less common, but principles can be adapted for certain
learning rules.
•Application in Unsupervised Learning: Directly applied for learning correlations and clustering
(e.g., self-organizing maps).
•Application in Reinforcement Learning: Can influence weight adjustment rules in some neural
network architectures.

4. Genetic Algorithms:
•Application in Supervised Learning: Used for optimizing model parameters and feature
selection.
•Application in Unsupervised Learning: Applied to clustering problems and evolving data
structures.
•Application in Reinforcement Learning: Used for evolving policies and strategies (e.g.,
neuroevolution).

Sandesh Shiwakoti-9815945474
Statistical-based learning: Naïve Bayes Model
Statistical learning isn't a separate category, but rather a fundamental approach that underpins
many machine learning algorithms, especially supervised learning. It focuses on using statistical
methods to build models that can learn from data,

statistical learning is like the toolbox that provides the tools and techniques for various machine
learning algorithms, particularly in supervised and unsupervised settings.

statistical machine learning involves using statistical techniques to develop models that can
learn from data and make predictions or decisions.
You might have heard technical terms such as supervised, unsupervised, and semi-supervised
learning– they all rely on a solid statistical foundation.
In essence, statistical machine learning merges the computational efficiency and adaptability of
machine learning algorithms with statistical inference and modeling capabilities.
By employing statistical methods, we can extract significant patterns, relationships, and insights
from intricate datasets, thereby promoting the effectiveness of machine learning algorithms.
Sandesh Shiwakoti-9815945474
Naive Bayes is a probabilistic machine learning algorithm based on the Bayes Theorem, used in a wide
variety of classification tasks.
The Naïve Bayes classifier is a supervised machine learning algorithm used for classification
tasks, such as text classification. Here’s how it works:
1.Bayesian Statistics: Naïve Bayes is based on Bayes’ Theorem, which allows us to “invert”
conditional probabilities. It deals with sequential events, where additional information
impacts the initial probability. For instance, consider medical testing: if someone tests positive
for a disease, the prior probability is updated based on this new information.
2.Assumption of Independence: Naïve Bayes assumes that predictors
(features) are conditionally independent given the class. This simplifies the model but may
not always hold in practice.
3.Generative Learning: Naïve Bayes is part of the generative learning algorithms family.
Unlike discriminative classifiers (e.g., logistic regression), it doesn’t learn which features are
most important for differentiation.
4.Applications: It’s commonly used for text classification, where discrete data (like word
counts) are relevant
How Naive Bayes Algorithm Works? (with example and
full code) | ML+ (machinelearningplus.com) Sandesh Shiwakoti-9815945474 https://youtu.be/O2L2Uv9pdDA
Sample Email

Sandesh Shiwakoti-9815945474
Spam Message : 4
Normal Message: 8
Key Words inside Spam Message
Key Words inside normal message
Dear = 2 , Friend = 1, Lunch = 0, Money = 4
Dear = 8, Friend=5, lunch=3, money=1 , Total = 7
Total= 17 Probability of each words from spam message:
p(Dear | Spam) = 2/7 = 0.29
Probability of each words: P(Friend | Spam) = 1/7 = 0.14
p(Dear|Normal) = 8/17 = 0.47 p(Lunch | Spam) = 0
p(Friend|Normal) = 5/17 = 0.29 p(Money | Spam) = 4/7 = 0.57
p(Lunch | Normal) = 3/17 = 0.18
p(money | Normal) = 1/17 = 0.06

P (N) = 8/12 = 0.67 [ since 8 out of 12 message are normal)

The initial guess that we observe a normal message is called a prior probability
P (S) = 4/12 = 0.33 Sandesh Shiwakoti-9815945474
.
Now we have got a message, which contains ‘Dear Friend’ . Let’s find whether the message
received is normal or spam.

Finding the probability of a normal message.


p(N) * p(Dear |N) * p(Friend|N)
0.67 * 0.47 * 0.29 = 0.09 p(N |Dear Friend) [It is proportional to the probability that
the message is normal, given that it says Dear Friend.]

Finding the probability of a spam message.


p(S) * p(Dear |S) * p (Friend |S)
0.33*0.29*0.14 = 0.01 p(S | Dear Friend) [It is proportional to the probability that the
message is normal, given that it says Dear Friend.]

P (N |Dear Friend) > P(S |Dear Friend)


It is normal message because we got greater score than spam for normal message.
Sandesh Shiwakoti-9815945474
Applications of Naive Bayes Algorithm
•Real-time Prediction.
•Multi-class Prediction.
•Text classification/ Spam Filtering/ Sentiment Analysis.
•Recommendation Systems.

Sandesh Shiwakoti-9815945474
Learning by genetic Algorithm: Genetic Algorithms (GA) were introduced by John Holland in 1975
You can simulate biological evolution process

A genetic algorithm is an adaptive heuristic search algorithm inspired by "Darwin's


theory of evolution in Nature." It is used to solve optimization problems in machine
learning. It is one of the important algorithms as it helps solve complex problems that
would take a long time to solve. Genetic Algorithms are being widely used in different
real-world applications, for example, Designing electronic circuits, code-breaking, image
processing, and artificial creativity.

There are 5 phases/components in genetic algorithm.


1. Initial population
2. Fitness Function
3. Selection
4. Crossover These 3 are also called genetic algorithm operator
5. Mutation

Sandesh Shiwakoti-9815945474
It mimics Real biological evolution.
Solve large or complex problem
Focus on optimization
It reflects the process of natural process selection where the fittest individuals are
selected for reproduction in order to produce offspring of next generation.

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Initial Population:-
The process begins with a set of individuals which is called a population. Each
individual is a solution to the problem you want to solve. An individual is characterized by a
set of parameters known as Genes. Genes are joined into a string to form a
chromosome(solution).

Fitness Function:-
The fitness function determines how fit an individual is ( the ability of an
individual to compete with other individuals). It gives a fitness score to each individual. The
probability that an individual will be selected for reproduction is based on its fitness socre.

Selection:-
This is a method providing the performance to the individuals with good fitness
score and allows them to pass their genes to the successive generation. The concept related
to genetic algorithms in computer science, where individuals with higher fitness scores (i.e.,
those who perform better in a given task or environment) are more likely to pass their genes
on to the next generation. Techniques like round wheel tournament selection and rank
selection are used to choose the parents forShiwakoti-9815945474
Sandesh the next generation.
Mutation:-
It’s defined as a small random tweak in the chromosome to get a new solution. The
purpose of mutation is to maintain and introduce diversity in the genetic population and to
explore new areas of the search space. The key idea is to insert random genes in offspring to
maintain the diversity in the population to avoide the premature convergence.
Ex: 0 0 1 1 0 1 0 0 1 0 0 1
Before mutation After mutation

Crossover:-
In genetic algorithms, crossover, also known as recombination, is a genetic operator used
to combine the genetic information of two parents to generate new offspring. It’s one way to
stochastically generate new solutions from an existing population.
Ex: consider the crossover point to be 3 as shown below.
A1 0 0 0 0 0 0
A2 1 1 1 1 1 1

The new offspring are added to the population


A3 1 1 1 0 0 0
A4 0 0
Sandesh Shiwakoti-9815945474 0 1 1 1
Sandesh Shiwakoti-9815945474
Genetic algorithm

Step-1: Start by creating an initial randomly generated population.


Step-2: Evaluate the fitness of each individual in the population.
Step-3: Select individuals to reproduce based on their fitness.
Step-4: Perform crossover (also known as reproduction) on the selected individuals to create
offspring for the next generation.
Step-5: Perform mutation on new population making small, random changes to the offspring to
create diversity in the population.
Step-6: Calculate fitness for new population
Step-7: Terminate if the population has converged.

[ The population has converge i.e., if there is not much diversity left in the population or if a
satisfactory fitness level has been reached.]

Sandesh Shiwakoti-9815945474
Maximize the function f(x) = x2

Where x can be between 0 to 31

Soln
1. Select encoding technique:-

Min value = 0 and Max value = 31,

Using 5 bit binary integers, numbers between 0 (00000) to 31 ( 11111) can be obtained.

2. Select initial solution:-


initial populations are random.
initial population size is 4 . Assumed random size. Better initial population gives us better result

Expected count: f(x)/av. Of f(x)


144/1155 %prob = 100 * prob
Sandesh Shiwakoti-9815945474
Actual count: Round up of Expected count,
String 1 once
String 2 twice
String 3 zero times Chosen string for next generation
String 4 once Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
You want to go ktm from btngr but you can carry only one hand baggage of 5 kg.

you have total 8 items with different weight. Now you want to choose maximum number of items withing 5 kg.
To solve this you have to make combination of items with different weight.

let’s say for three items, you would have total 7 combination, for 5 items total 32 combination= 0.000003
for 10 items total 1024 combination=0.000807, 20 items = 1048576 = 1 sec, 77 items = 5 billions years

Sandesh Shiwakoti-9815945474
Example problem and solution using Genetic Algorithms

Given a target string, the goal is to produce target string starting from a random string
of the same length. In the following implementation, following analogies are made –

•Characters A-Z, a-z, 0-9, and other special symbols are considered as genes

•A string generated by these characters is considered as


chromosome/solution/Individual

Application of Genetic Algorithm's

•Recurrent Neural Network


•Mutation testing
•Code breaking
•Image processing
•Vehicle routing problems
•Scheduling applications Sandesh Shiwakoti-9815945474
Learning with neural Network
Neural Networks are computational models that mimic the complex functions of the
human brain. The neural networks consist of interconnected nodes or neurons that
process and learn from data, enabling tasks such as pattern recognition and decision
making in machine learning.

Artificial Neural Network:-


Artificial neural network is nonlinear, parallel, distributed and highly
connected network having capability of adaptively, self organization, fault tolerance, evidential
response and very large scale integration implementation which closely resembles with physical
nervous system.
Neural networks are composed of simple elements operating in parallel. These elements are
inspired by biological nervous systems. As in nature, the network function is determined largely
by the connections between elements. We can train a neural network to perform a particular
function by adjusting the values of the connections between elements.
Sandesh Shiwakoti-9815945474
Biological / Physical Neural Network:-
Physical nervous system is highly paralleled distributed information processing system
having high degree of connectivity with capability of self learning human nervous
system contents about 10 billion neurons with 60 trillion of interconnection these
connections are modified based on experience. Typical physical neuron and artificial
neural network are shown in figure

Sandesh Shiwakoti-9815945474
•Dendrites − They are tree-like branches, responsible for receiving the
information from other neurons it is connected to. In other sense, we can
say that they are like the ears of neuron.
•Soma − It is the cell body of the neuron and is responsible for processing of
information, they have received from dendrites.
•Axon − It is just like a cable through which neurons send the information.
•Synapses − It is the connection between the axon and other neuron
dendrites.

Sandesh Shiwakoti-9815945474
Difference between Biological Neural Networks Vs Artificial Neural Networks (ANN)

Criteria BNN ANN


Structure Dendrite, synapse, Axon, cell body Input, weight, output, Hidden layer

Learning they can tolerate ambiguity very precise structures and formatted data

Expertise perceptual problems numerical and symbolic manipulations

Storage Stores the information in the synapsis Stores the information in continuous memory
102 to 104 nodes(mainly depends on type of
size Approx 1011 Neurons and 1015 interconnection
application and network design

Sandesh Shiwakoti-9815945474
Mathematical Model of AAN
Artificial Neural Networks (ANNs) are inspired by the structure and function of the brain.
They use a mathematical model to process information through interconnected nodes,
called artificial neurons.

•An artificial neuron receives input signals (x_1, x_2, ..., x_n) from other neurons.
•Each input is multiplied by a weight (w_1, w_2, ..., w_n) representing the connection strength.
•These weighted inputs are summed (Σ) along with a bias (b) term.
•An activation function (f) is applied to the summed value to introduce non-linearity and
determine the output (y) of the neuron.

Mathematical Notation:

y = f(Σ(w_i * x_i) + b)

f: Activation function (e.g., sigmoid, tanh, ReLU) w_i: Weights for each input x_i: Input signals
Σ: Summation function b: Bias term
Sandesh Shiwakoti-9815945474
y: Output of the neuron
Network Architecture

•Neurons are organized in layers: input layer, hidden layers, and output layer.
•The input layer receives raw data.
•Hidden layers process information through multiple activation functions.
•The output layer produces the final results.

Learning Process

•ANNs learn by adjusting the weights and biases during training.


•The network is presented with training data (inputs and desired outputs).
•The difference between the actual output and the desired output (error) is calculated.
•Backpropagation algorithms like gradient descent are used to iteratively adjust weights and
biases to minimize the error.

Overall, the mathematical model of an ANN represents a complex system of interconnected


functions that learns through adjustments based on training data.
Sandesh Shiwakoti-9815945474
Activation Function:-
Activation function typically falls into one of three categories:

> Linear > Threshold (Heaviside function) > Sigmoid

For linear activation functions, the output activity is proportional to the total weighted output.
g(x) = kx+c, Where k and x are constant

For threshold activation functions, the output are set at one of two levels, depending on whether
the total input is greater than or less than some threshold value.
g(x) = 1 if x>=k
= 0 if x<0

For sigmoid activation functions, the output varies continuously but not linearly as the input
changes. Sigmoid units bear a greater resemblance to real neurons than do linear or threshold
units. It has advantage of differentiable.
G(x) = 1/(1+e-x) Sandesh Shiwakoti-9815945474
Types of Artificial Neural Network:

Feed forward Networks:-


Feed forward artificial neural networks allow signals to travel one way
only; from input to output. There is no feedback(loops) i.e. the output of any layer does
not affect the same layer. Feed forward artificial neural networks tend to be
straightforward networks that associate inputs with Outputs. They are extremely used in
pattern recognition this type of organization is also referred to as bottom up or top down.

Sandesh Shiwakoti-9815945474
Feedback(Recurrent) Networks:-
Feedback networks can have signals traveling in both directions by introducing
loops in the network. Feedback networks are very powerful and can get extremely complicated.
Feedback networks are dynamic; their ‘state’ is changing continuously until they reach an
equilibrium point. They remain at the equilibrium point until the input changes and a new
equilibrium needs to be found. Feedback architectures are also referred to as interactive or
recurrent.

Sandesh Shiwakoti-9815945474
There are 2 types of feed forward neural networks:

Single-layer Neural Networks(perceptrons):-


A neural network in which all the inputs connected directly
to the outputs is called a single-layer neural network, or a perceptron network. Since each
output unit is independent of the others each weight affects only one of the outputs.

Multilayer neural networks(perceptrons):-


The neural network which contains input layers,
output layers and some hidden layers also is called multilayer neural network. The advantage of
adding hidden layers is that it enlarges the space of hypothesis. Layers of the network are
normally fully connected.

Sandesh Shiwakoti-9815945474
Application of Artificial Neural Network:-
•Facial Recognition: Recognizing and verifying individual faces for security and
authentication purposes.
•Speech Recognition: Converting spoken language into text (e.g., virtual assistants like Siri
and Alexa).
•Character Recognition: It can extract character form an image.
•Stock Market Prediction: Analyzing historical data to predict future stock prices.
. Recommendation Systems: Suggesting movies, music, and other content based on user
preferences (e.g., Netflix and Spotify recommendations).
Learning by Training ANN:-
In AI, learning by training refers specifically to how AI models improve their
abilities. It's essentially the process of an AI system "learning by doing" tasks with data, similar to
how a student learns through practice. Here's a breakdown:

Data Feeding: The core of training involves feeding the AI system massive amounts of data
relevant to the task it needs to learn. This data can be text, images, code, or any format that
holds information the AI can process. Sandesh Shiwakoti-9815945474
•Pattern Recognition: The AI system analyzes the data to identify patterns and relationships
within it. This is similar to how humans learn by observing and making connections between
things they experience. For example, an image recognition AI might analyze millions of labeled
images to understand the patterns that differentiate a cat from a dog.

•Model Adjustments: Based on the analysis of the data, the AI model itself is adjusted and
refined. This can be done through various algorithms, but the basic idea is that the AI "learns
from its mistakes" on the training data. It adjusts its internal parameters to improve its ability to
identify patterns and make accurate predictions on new, unseen data.
Training is an iterative process. The AI is fed data, analyzes it, adjusts its model, and then repeats
the process with potentially new data. The more data and the more iterations of this process, the
better the AI model becomes at the specific task it's trained for.
Here's an analogy: Imagine training a dog to fetch. You throw the ball repeatedly (data feeding),
the dog observes its throws and tries to catch it (pattern recognition), and you correct its
mistakes and praise its successes (model adjustments). Over time, through this "learning by
doing" with data, the dog becomes better at fetching.
AI training is crucial because it allows AI models to perform tasks that would be impossible for
them to do without prior exposure to vast amounts
Sandesh of data and the ability to learn from it.
Shiwakoti-9815945474
Neural Network Learning Rules

During ANN learning, to change the input/output behavior, we need to


adjust the weights. Hence, a method is required with the help of which the
weights can be modified. These methods are called Learning rules, which
are simply algorithms or equations.

Following are some learning rules for the neural network −

Hebbian Learning Rule


Perceptron Learning Rule
Back-propagation Learning Rule

Sandesh Shiwakoti-9815945474
Hebbian Learning:-
Hebbian learning is a general principle that states that the synaptic efficiency between two
neurons should increase if the 2 neurons are simultaneously active, and decrease if not.

In 1949 Donald Herb proposed one of the key ideas in biological learning commonly known as
Heb’s law states that if neurons i is near enough to excite neurons j and repeatedly participates in
its activation the synaptic connection between these two neurons is strengthened and neuron j
becomes more sensitive to stimuli from neurons i.

Hebb’s Law can be represented in the form of two rules:


1. If tow neurons on either side of a connection are activated synchronously, then the
weight of that connection is increased.

2. If two neurons on either side of a connection are activated asynchronously, then the
weight of that connection is decrease.

Hebb’s Law provides the basis of learning without a teacher. Learning here is a local
phenomenon occurring without feedback from
Sandesh the environment.
Shiwakoti-9815945474
Hebbian Learning Rule Algorithm :

1.Set all weights to zero, wi = 0 for i=1 to n, and bias to zero.


2.For each input vector, S(input vector) : t(target output pair), repeat steps 3-5.
3.Set activations for input units with the input vector Xi = Si for i = 1 to n.
4.Set the corresponding output value to the output neuron, i.e. y = t.
5.Update weight and bias by applying Hebb rule for all i = 1 to n:

Sandesh Shiwakoti-9815945474
Perceptron Learning :
It was originally developed by Frank Rosenblatt in the late 1950s. Training patterns
are presented to the network’s inputs; the output is computed. Then the connection weights wj
are modified by amount that is proportional to the product of the difference between the actual
output, y, and the desired output, d, and the input pattern, x. The summarized algorithm is give
below.

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Back-propagation Learning:-
It is a supervised learning Method, and is an implementation of the Delta rule. It
requires a teacher that knows, or can calculate, the desired output for any given input. It is most
useful for feed-forward networks. The term is an abbreviation for “backwards propagation of
errors”. Backpropagation requires that the activation function used by the artificial neurons is
differentiable.
Backpropagation networks are necessarily multiplayer perceptions (usually with one input, one
hidden, and one output layer) . In order for the hidden layer to serve any useful function,
multilayer networks must have non-linear activation functions for the multiple layers: a
multilayer network using only linear activation functions is equivalent to some single layer, linear
network.
Input: D training data set and their associated class label l= learning rate(normally 0.0-1.0)
Output: a trained neural network.
Method:
Step1: initialize all weights and bias in network.
Step2: while termination condition is not satisfied .
For each training tuple x in D
Sandesh Shiwakoti-9815945474
2.1 calculate output: For input layer For hidden layer and output layer

2.2 Calculate error: For output layer:

Sandesh Shiwakoti-9815945474
Sandesh Shiwakoti-9815945474
Deep Learning:

Deep learning is a subset of machine learning that uses multi-layered neural networks, called
deep neural networks, to simulate the complex decision-making power of the human brain.
Imagine teaching a computer to recognize cats: instead of telling it to look for whiskers, ears,
and a tail, you show it thousands of pictures of cats. The computer finds the common
patterns all by itself and learns how to identify a cat. This is the essence of deep learning.

In technical terms, deep learning uses something called "neural networks," which are
inspired by the human brain. These networks consist of layers of interconnected nodes that
process information. The more layers, the "deeper" the network, allowing it to learn more
complex features and perform more sophisticated tasks.

Important parts of Deep Learning :


Convolutional Neural Networks (CNNs):
Recurrent Neural Networks (RNNs):
Generative Adversarial Networks (GANs):
Sandesh Shiwakoti-9815945474
Convolutional neural networks

A CNN is a multilayer neural network that was biologically inspired by the animal
visual cortex. The architecture is particularly useful in image-processing applications.
The first CNN was created by Yann LeCun; at the time, the architecture focused on
handwritten character recognition, such as postal code interpretation. As a deep
network, early layers recognize features (such as edges), and later layers recombine
these features into higher-level attributes of the input.

Sandesh Shiwakoti-9815945474
CNN architecture

Convolutional Neural Network consists of multiple layers like the input layer,
Convolutional layer, Pooling layer, and fully connected layers.

The Convolutional layer applies filters to the input image to extract features, the
Pooling layer down samples the image to reduce computation, and the fully connected
layer makes the final prediction. The network learns the optimal filters through
backpropagation and gradient descent.

Recurrent Neural Networks(RNNs):-


A recurrent neural network (RNN) is a deep learning model that is trained to process and convert a
sequential data input into a specific sequential data output. Sequential data is data—such as words,
sentences, or time-series data—where sequential components interrelate based on complex semantics
and syntax rules. An RNN is a software system that consists of many interconnected components
mimicking how humans perform sequential data conversions, such as translating text from one language
to another. RNNs are largely being replaced by transformer-based artificial intelligence (AI) and large
language models (LLM), which are much more efficient
Sandesh in sequential data processing.
Shiwakoti-9815945474
Key Characteristics of RNNs:

1.Sequence Processing:
1. RNNs are particularly well-suited for tasks where the order of data is important, such as
time series analysis, natural language processing (NLP), and speech recognition.
2.Memory:
1. RNNs maintain a hidden state that acts as a memory of previous inputs, which is updated
as new inputs are received. This allows RNNs to retain information over time, making
them capable of understanding context and temporal dependencies.
3.Recurrent Connections:
1. The recurrent connections in an RNN allow the output from the previous step to be used
as an input to the current step, providing the network with a form of memory.
Applications:
•Natural Language Processing (NLP): Text generation, language modeling, machine
translation, sentiment analysis.
•Time Series Prediction: Stock market prediction, weather forecasting.
•Speech Recognition: Transcribing spoken words into text.
•Video Analysis: Activity recognition inSandesh
videos.Shiwakoti-9815945474
Generative Adversarial Networks (GANs):

GANs are the creative minds of deep learning. They specialize in generating new data, like
images, videos, or even text. Here's the twist: GANs involve two neural networks locked in an
adversarial competition. One network (the generator) tries to create new, realistic data, while
the other network (the discriminator) tries to distinguish the generated data from real data. This
competition pushes both networks to improve, ultimately leading to the generation of highly
realistic and creative outputs. Imagine a GAN as a team of rival artists, constantly pushing each
other to create better and more innovative works.

Architecture of GANs

A Generative Adversarial Network (GAN) is composed of two primary parts,


which are the Generator and the Discriminator.

Sandesh Shiwakoti-9815945474
Generator Model:-
A key element responsible for creating fresh, accurate data in a Generative
Adversarial Network (GAN) is the generator model. The generator takes random noise
as input and converts it into complex data samples, such text or images. It is commonly
depicted as a deep neural network.
The generator’s ability to generate high-quality, varied samples that can fool the
discriminator is what makes it successful.

Discriminator Model:-
An artificial neural network called a discriminator model is used in
Generative Adversarial Networks (GANs) to differentiate between generated and actual
input. By evaluating input samples and allocating probability of authenticity, the
discriminator functions as a binary classifier.
Over time, the discriminator learns to differentiate between genuine data from the
dataset and artificial samples created by the generator. This allows it to progressively
hone its parameters and increase its level of proficiency.
Sandesh Shiwakoti-9815945474

You might also like