0% found this document useful (0 votes)
3 views98 pages

Learning Agents in AI: Key Concepts

The document discusses the principles of artificial intelligence with a focus on learning agents, their components, and various forms of learning such as supervised, unsupervised, semi-supervised, and reinforcement learning. It explains the importance of learning in AI, the methods used for learning (like decision trees and neural networks), and provides examples of how agents can improve their performance through experience. Additionally, it covers the decision tree algorithm, including its construction, application, and the concept of information gain in determining the best attributes for classification.

Uploaded by

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

Learning Agents in AI: Key Concepts

The document discusses the principles of artificial intelligence with a focus on learning agents, their components, and various forms of learning such as supervised, unsupervised, semi-supervised, and reinforcement learning. It explains the importance of learning in AI, the methods used for learning (like decision trees and neural networks), and provides examples of how agents can improve their performance through experience. Additionally, it covers the decision tree algorithm, including its construction, application, and the concept of information gain in determining the best attributes for classification.

Uploaded by

Assassin Hackers
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Principles of Artificial Intelligence

UNIT-4
Learning

Lecture By:
Dr. Saurav Verma
Assistant Professor,
Dept. of IT, MPSTME,
NMIMS University, Mumbai
Components of an agent

Learning agent
Learning agent
•Learn -> improve performance on future task, after
making observations of the world
•One type of learning
• Determine the function that links inputs to an output
• This function is “learnt” and used to predict an output
when some input is encountered
Why learn? ..1
•Why not write a program that has the “knowledge” to do
the required task?
• Why not program the “improvements” in the agent?

•Reason 1: Designers cannot anticipate all possible situations


•E.g.1 agent designed to grip a glass of steel at a certain
pressure
•What if the weight of the glass changes? Will the earlier
pressure level (friction level) be sufficient?
•The agent may need to “learn” what is the “result” of
different pressures
Why learn? .. 2
•Reason 2: Designers cannot anticipate all changes over time
•E.g. 1: Weather may not have a standard time series
behaviour; sudden changes in various environmental factors
may result in a cyclone

•E.g. 2: Stock market may get affected due to political


factors, etc.
Why learn? .. 3
•Reason 3: (I don’t know)
• The designer does not know how to program a solution – even the
best programmers

•E.g. 1: (Almost?) impossible to program a computer to


recognize a face
• Take the image of a face and tell who it is :S
• Take 10000 images and tell who is each one D:
Ok, how to learn?
•Decision trees
•Linear / non-linear models (neural networks)
•Support vector machines
Forms of learning
Any component of an agent can be improved by learning;
Techniques to learn and improve depend on 4 factors
•Which component to be improved
•What prior knowledge the agent already has.
•What representation is used for the data and the component.
•What feedback is available to learn from
Learning for a taxi-driver agent:
component improvement
•for example, an agent training to become a taxi driver.
•Every time the instructor shouts “Brake!” the agent might learn a
condition– action rule for when to brake (component 1) – current state
to action
•the agent also learns every time the instructor does not shout. By
seeing many camera images that it is told contain buses, it can learn to
recognize them (2) – relevant properties of the world based on percepts
(or percept sequence)
•By trying actions and observing the results—for example, braking hard
on a wet road—it can learn the effects of its actions (3) – information
about how the world evolves
•Then, when it receives no tip from passengers who have been
thoroughly shaken up during the trip, it can learn a useful component of
its overall utility function (4). – utility information about desired stae
Forms of learning:
Representation and prior
knowledge
•Factored representation
• Other methods are propositional
• and first-order logic

•“Vector” of “attribute” values


•“Output” – continuous value or discrete

•Inductive learning
• Specific input data – expected output pairs (e.g. (x1, y1) – x is input, y is expected
output)

•Analytical or deductive learning


• Create a new rule based on a general rule
[Link]
0f58782504a4
Forms of learning:
Feedback types
Supervised Learning
•Agent observes input-output pairs
• Learns function that maps input to output

•E.g. for taxi agent inputs could be percepts about situation


on the road, training output could be instruction to brake
(for a given set of inputs)
•E.g. for taxi agent, inputs could be images of vehicles on the
road
• Training output could be classification of some image as a “car” or
“bus” etc.
Forms of learning: Feedback
types
Unsupervised learning
•Agent learns patterns in the input, even though no explicit
feedback about the pattern is given
• E.g. Given a set of customers, group customers as per their
preferences (seen in recommendation systems); no data of
who should belong to which group
• Most common – clustering
Forms of learning:
Feedback types
Semi-supervised learning
•Few of the training samples may not have the correct output
value Or output value may be missing
Forms of learning:
Feedback types
Reinforcement learning
• Agent learns from rewards or punishment

•E.g. lack of a tip at end of journey gives taxi agent indication


that it did something wrong
•E.g. two points for win at end of chess game tells agent it
did something right
•Agent decides which of the actions were most appropriate;
based on what it wants to achieve
Reinforcement learning
Supervised Learning
•Given a training set of N example input–output pairs
(x1, y1), (x2, y2), . . . (xN, yN)
where each yj was generated by an unknown function y = f(x),
discover a function h that approximates the true function f.
•x and y can be any value; they need not be numbers. The
function h is a hypothesis
•Learning means trying to find the best h
• Best => accurate on training data and also accurate for test data
(unseen values i.e. values not seen during training)
Supervised Learning: Learning
problem Regression vs
classification
Regression: If the output value to be predicted is a continuous value
◦ E.g. speed of the cyclone
◦ E.g. rate of spread of the virus

Classification: If the output value to be predicted is categorical


◦ e.g. “Cat”, “Dog”, “Car”
◦ E.g. Covid +ve or Covid –ve
Learning Decision Trees
Determine a tree such that
at each node in the tree a
check is done on the x value
(<= or >)
x y
x
<=
<=3 >3
2 1 3
3
5
1
2 y=1 y=2
6 2
7 2
Learning Decision Trees
Determine a tree such that at each node in the tree a check
is done on the x1 value (<= or >)
x1
x1 x2 y <=3 >3
x2 x2
2 4 1 >4 <3 >=3
3 5 1 y=1 y=2 y=1

5 1 2
6 2 2
7 3 1
Learning Decision Trees
(same question… Using x2)
Determine a tree such that at each node in the tree a check
is done on the x value (<= or >)

x1 x2 y x2
<3 >= 3
2 4 1
y=2 y=1
3 5 1
5 1 2
6 2 2
7 3 1
Decision tree
In Decision tree approach, a tree is constructed to model
the classification process.
Once the tree is built, it is applied to each tuple in the
database and results in a classification for that tuple.
There are two basic steps in the technique:
◦ building the tree
◦ and applying the tree to the database.

Most research has focused on how to build effective trees


as the application process is straightforward.
Decision Tree
cal cal u s
r i r i uo
o o n
teg teg nti
ass Splitting Attributes
ca ca co cl
Home Marital Annual Defaulted
ID
Owner Status Income Borrower
Home
1 Yes Single 125K No Owner
2 No Married 100K No Yes No
3 No Single 70K No
NO MarSt
4 Yes Married 120K No
Single, Divorced Married
5 No Divorced 95K Yes
6 No Married 60K No Income NO
7 Yes Divorced 220K No < 80K > 80K
8 No Single 85K Yes
NO YES
9 No Married 75K No
10 No Single 90K Yes
10

Training Data Model: Decision Tree


Apply Model to Test Data
Start from the root of tree. Test Data
Home Marital Annual Defaulted
Home Owner Status Income Borrower
Yes Owner No No Married 80K ?
10

NO MarSt
Single, Divorced Married

Income NO
< 80K > 80K

NO YES
Parts of a Decision Tree
Decision Tree based
Algorithms
Solving the classification problem using decision
trees is a two-step process:
◦ Decision tree induction: Construct a DT using training data.
◦ For each tiεD, apply the DT to determine its class.

DT approaches differ in how the tree is built.

Algorithms: ID3, C4.5, CART


DT Induction
DT Induction
The recursive algorithm builds the tree in a top-down fashion.
Using the initial training data, the "best" splitting attribute is
chosen first. [Algorithms differ in how they determine the "best attribute"
and its "best predicates" to use for splitting. ]
Once this has been determined, the node and its arcs are
created and added to the created tree.
The algorithm continues recursively by adding new subtrees to
each branching arc.
The algorithm terminates when some "stopping criteria" is
reached. [Again, each algorithm determines when to stop the tree
differently. One simple approach would be to stop when the tuples in the
reduced training set all belong to the same class. This class is then used to
label the leaf node created.]
Choosing Splitting
Attributes
Name Gender Height Output1(Correct) Output2(Actual
Assignment)
Kristina F 1.6m medium Medium
Jim M 2m Tall Short
Maggie F 1.9m Medium Short
Martha F 1.88m Short medium
Stephanie F 1.7m Medium Tall
Bob M 1.85m Medium Medium
Kathy F 1.6m Short Short
Dave M 1.7m Short Medium
Worth M 2.2m Tall Tall
Steven M 2.1m Tall Short
Debbie F 1.8m Tall Medium
Todd M 1.95m Medium Tall
Kim F 1.9m Short Tall
Amy F 1.8m Medium Medium
Wynette F 1.75m Medium Short
ID3
ID3 stands for Iterative Dichotomiser 3
Creates tree using information theory concepts and tries to
reduce expected number of comparison.
ID3 chooses split attribute with the highest information
gain:
Information gain=(Entropy of distribution before the split)–
(entropy of distribution after it)
Which attribute to pick
first? (Reduce entropy)
Pick attribute that reduces ambiguity of the final answer
◦ i.e. splits yes and no into clear groups

Entropy is a measure of the uncertainty of a random variable


A coin that always shows heads has no uncertainty
◦ i.e. entropy = 0
◦ When all data belongs to a single class, entropy is zero as there is no
uncertainty.
◦ An equally divided sample as an entropy of 1
Entropy
The Mathematical formula for Entropy is -

Where ‘Pi’ is the probability of an element/class ‘i’ in our data.


Most important
attribute
“most important attribute,” one that makes most difference
to classification of an example
◦ (Recall x1, x2 in the small example. x2 was better)

This will help to make the tree “shorter” (shallow)


Case 1:

Coffee flavor Quantity of Pouches Probability


Caramel Latte 7 0.7
Cappuccino 3 0.3
Total 10 1

H(X) = – [(0.70 * log2 (0.70)) + (0.30 * log2 (0.30))] =


0.88129089

This value 0.88129089 is the measurement of uncertainty when


given the box full of coffee pouches and asked to pull out one of the
pouches when there are seven pouches of caramel latte flavor and
three pouches of cappuccino flavor.
Case 2: Case 3:

Quantity Quantity
Coffee flavor of Probability Coffee flavor of Probability
Pouches Pouches
Caramel
Caramel Latte 5 0.5 Latte 10 1

Cappuccino 5 0.5 Cappuccino 0 0


Total 10 1 Total 10 1

H(X) = – [(0.50 * log (0.50))


2
+ (0.50 * H(X) = – [(1.0 * log2 (1.0) + (0 * log2 (0)]
log (0.50))] = 1
2 ~= 0

In scenarios 2 and 3, can see that the entropy is 1 and 0, respectively. In scenario
3, when we have only one flavor of the coffee pouch, caramel latte, and have
removed all the pouches of cappuccino flavor, then the uncertainty or the surprise
is also completely removed and the aforementioned entropy is zero. We can then
conclude that the information is 100% present.
Information Gain
Gain is defined as the difference between how
much information is needed to make a correct
classification before the split versus how much
information is needed after the split.
Information Gain Example
Information Gain
Example

Let S=14 examples, 9 positive 5 negative


Entropy(S) = - (9/14) Log2 (9/14) - (5/14) Log2 (5/14) = 0.940
The attribute is Wind. Values of wind are Weak and Strong
8 occurrences of weak winds ; 6 occurrences of strong winds
For the weak winds, 6 are positive and 2 are negative
For the strong winds, 3 are positive and 3 are negative
Gain(S,Wind) =
Entropy(S) - (8/14)*Entropy (Weak) -(6/14)*Entropy (Strong)
Entropy(Weak) = - (6/8)*log2(6/8) - (2/8)*log2(2/8) = 0.811
Entropy(Strong) = - (3/6)*log2(3/6) - (3/6)*log2(3/6) = 1.00
So… 0.940 - (8/14)*0.811 - (6/14)*1.00 = 0.048
Temperature
Information Gain = 0.029
Windy
Information Gain = 0.048
Outlook
Information Gain = 0.246
Humidity
Information Gain = 0.152
Information gain is most for Outlook. So, we choose first decision maker
as Outlook.
Advantages of ID3
Understandable prediction rules are created from the training data.
Builds the fastest tree.
Builds a short tree.
Only need to test enough attributes until all data is classified.
Finding leaf nodes enables test data to be pruned, reducing number of
tests.
Disadvantages of ID3
Data may be over-fitted or over classified, if a small sample is tested.
Only one attribute at a time is tested for making a decision.
Classifying continuous data may be computationally expensive, as many
trees must be generated to see where to break the continuum.
What is Gini Index?
Gini Index or Gini impurity measures the degree or probability of
a particular variable being wrongly classified when it is randomly
chosen.
But what is actually meant by ‘impurity’?
If all the elements belong to a single class, then it can be called
pure. The degree of Gini Index varies between 0 and 1,
where,
'0' denotes that all elements belong to a certain class or there
exists only one class (pure), and
'1' denotes that the elements are randomly distributed across
various classes (impure).
A Gini Index of '0.5 'denotes equally distributed elements into
some classes.
Formula of Gini Index
The formula of the Gini Index is as follows:

where, ‘pi’ is the probability of an object being classified to


a particular class.
While building the decision tree, we would prefer to choose
the attribute/feature with the least Gini Index as the root
node.
Example
Past Trend Open Interest Trading Volume Return
Positive Low High Up
Negative High Low Down
Positive Low High Up
Positive High High Up
Negative Low High Down
Positive Low Low Down
Negative High High Down
Negative Low High Down
Positive Low Low Down
Positive High High Up
Past Open Trading Return
Trend Interest Volume
Positive Low High Up
Negative High Low Down
Positive Low High Up
Positive High High Up
Negative Low High Down
Calculating the Gini Index for past trend Positive Low Low Down
Negative High High Down
Negative Low High Down
• P(Past Trend=Positive): 6/10 Positive Low Low Down
Positive High High Up
• P(Past Trend=Negative): 4/10
• If (Past Trend = Positive & Return = Up), probability = 4/6
• If (Past Trend = Positive & Return = Down), probability = 2/6
• Gini Index = 1 - ((4/6)^2 + (2/6)^2) = 0.45
• If (Past Trend = Negative & Return = Up), probability = 0
• If (Past Trend = Negative & Return = Down), probability = 4/4
• Gini Index = 1 - ((0)^2 + (4/4)^2) = 0
• Weighted sum of the Gini Indices can be calculated as follows:
• Gini Index for Past Trend = (6/10)0.45 + (4/10)0 = 0.27
Past Open Trading Return
Trend Interest Volume
Positive Low High Up
Calculating the Gini Index for open interest Negative High Low Down
Positive Low High Up
Positive High High Up
• P(Open Interest=High): 4/10 Negative Low High Down

• P(Open Interest=Low): 6/10 Positive Low Low Down


Negative High High Down
• If (Open Interest = High & Return = Up), probability =
Negative 2/4
Low High Down

• If (Open Interest = High & Return = Down), probability


Positive =Low2/4 Low Down
Positive High High Up
• Gini Index = 1 - ((2/4)^2 + (2/4)^2) = 0.5
• If (Open Interest = Low & Return = Up), probability = 2/6
• If (Open Interest = Low & Return = Down), probability = 4/6
• Gini Index = 1 - ((2/6)^2 + (4/6)^2) = 0.45
• Weighted sum of the Gini Indices can be calculated as follows:
• Gini Index for Open Interest = (4/10)0.5 + (6/10)0.45 = 0.47
Past Open Trading
Return
Trend Interest Volume
Positive Low High Up
Negative High Low Down
Positive Low High Up
Positive High High Up
Negative Low High Down
Calculating the Gini Index for trading volume Positive Low Low Down
Negative High High Down
Negative Low High Down
• P(Trading Volume=High): 7/10 Positive Low Low Down
• P(Trading Volume=Low): 3/10 Positive High High Up

• If (Trading Volume = High & Return = Up), probability = 4/7


• If (Trading Volume = High & Return = Down), probability = 3/7
• Gini Index = 1 - ((4/7)^2 + (3/7)^2) = 0.49
• If (Trading Volume = Low & Return = Up), probability = 0
• If (Trading Volume = Low & Return = Down), probability = 3/3
• Gini Index = 1 - ((0)^2 + (1)^2) = 0
• Weighted sum of the Gini Indices can be calculated as follows:
• Gini Index for Trading Volume = (7/10)0.49 + (3/10)0 = 0.34
Gini Index attributes or features

Attributes/Features Gini Index


Past Trend 0.27
Open Interest 0.47
Trading Volume 0.34

From the above table, we observe that ‘past trend’ has


the lowest Gini Index and hence, it will be chosen as the
root node.
Determining the sub nodes or
the branches (features going
down) of the decision tree
We will repeat the same procedure to determine the sub-
nodes or branches of the decision tree.
We will calculate the Gini Index for the ‘positive’ branch of
past trend as follows:
Past Trend Open Interest Trading Volume Return
Positive Low High Up
Positive Low High Up
Positive High High Up
Positive Low Low Down
Positive Low Low Down
Positive High High Up
Past Open Trading
Return
Trend Interest Volume
Positive Low High Up
Positive Low High Up
Positive High High Up
Positive Low Low Down
Positive Low Low Down
Calculating Gini Index of open interest for positive
Positive past
High High Up
trend

• P(Open Interest=High): 2/6


• P(Open Interest=Low): 4/6
• If (Open Interest = High & Return = Up), probability = 2/2
• If (Open Interest = High & Return = Down), probability = 0
• Gini Index = 1 - (sq(2/2) + sq(0)) = 0
• If (Open Interest = Low & Return = Up), probability = 2/4
• If (Open Interest = Low & Return = Down), probability = 2/4
• Gini Index = 1 - (sq(0) + sq(2/4)) = 0.50
• Weighted sum of the Gini Indices can be calculated as follows:
• Gini Index for Open Interest = (2/6)0 + (4/6)0.50 = 0.33
Past Open Trading
Return
Trend Interest Volume
Positive Low High Up
Positive Low High Up
Positive High High Up
Positive Low Low Down
Positive Low Low Down
Calculating Gini Index for trading volume Positive High High Up

• P(Trading Volume=High): 4/6


• P(Trading Volume=Low): 2/6
• If (Trading Volume = High & Return = Up), probability = 4/4
• If (Trading Volume = High & Return = Down), probability = 0
• Gini Index = 1 - (sq(4/4) + sq(0)) = 0
• If (Trading Volume = Low & Return = Up), probability = 0
• If (Trading Volume = Low & Return = Down), probability = 2/2
• Gini Index = 1 - (sq(0) + sq(2/2)) = 0
• Weighted sum of the Gini Indices can be calculated as follows:
• Gini Index for Trading Volume = (4/6)0 + (2/6)0 = 0
Gini Index attributes or features

Attributes/Features Gini Index


Open interest 0.33
Trading volume 0

We will split the node further using the ‘Trading Volume’


feature, as it has the minimum Gini Index.
Neural
Networks
Artificial Neural Networks
An Artificial Neural Network (ANN) or simply a Neural
Network(NN) is interconnected layers of small units called
nodes that perform mathematical operations to detect
patterns in data. NN algorithms are built in a way that
mimics how human neurons work.
Recognizing handwritten digits
Artificial
Neural
Networks
ANN is a computational
model that is inspired by
the way biological
neural networks in the
human brain process
information.
Dendrites from
Biological Neural
Network represent
inputs,
cell nucleus represents
Nodes,
synapse represents
Weights, and
Axon represents Output.
ANN vs BNN

Biological Neural
Artificial Neural Network (ANN)
Network (BNN)
Soma/Cell Nucleus) Node
Dendrites Input
Synapse Weights or Interconnections
Axon Output
Definitions
Neuron — This is a basic building block of a NN. It takes weighted values,
performs mathematical calculation and produce output. It is also called a
unit, node or perceptron.
Input — This is the data/values passed to the neurons.
Deep Neural Network (DNN) — This is an ANN with many hidden layers
(layers between the input (first) layer and the output (last) layer).
Weights — These values explain the strength (degree of importance) of the
connection between any two neurons.
Bias — is a constant value added to the sum of the product between input
values and respective weights. It is used to accelerate or delay the
activation of a given node.
Activation function — is a function used to introduce the non-linearity
phenomenon into the NN system. This property will allow the network to
learn more complex patterns.
Neural networks -
Perceptron
A perceptron takes several binary inputs, and
produces a single binary output; Rosenblatt proposed
a simple rule to compute the output
◦ introduced weights, w1,w2,..., real numbers
expressing the importance of the respective inputs
to the output
◦ In a way, perceptron makes decisions by weighing
up evidence
neuron's output, 0 or 1, is determined by whether the
weighted sum is less than or greater than some
threshold value
◦ A human neuron fires if the inputs are above a
threshold
◦ the threshold is a real number which is a
parameter of the neuron
Neural networks –
Perceptron decision
Example to decide whether to go to a festival or not, you want to
consider the following points
◦ Is the weather good? x1 = 1 (yes) or 0 (no)
◦ Will a friend accompany you? x2 = 1 (yes) or 0 (no)
◦ Is the festival near a public transport location? x3 = 1 (yes) or 0 (no)

Suppose weather is the most important for you and least important is the
public transport issue
◦ Weights could be assigned to each of the inputs above
◦ Example: w1=6, w2=3, w3=2 i.e. w=(6,3,2)

If the threshold for the perceptron is kept as 5


◦ If the weather is good (x1=1) and the rest are all a NO, i.e. x=(1,0,0) the output
from the perceptron will be
◦ i.e. go to the festival
Neural networks –
Perceptron decision
If the threshold is changed to 3,
◦ If weather is not good (x1=0), but friend accompanying is YES, public transport
is YES,, the output from the perceptron will be
◦ i.e. go to the festival

The threshold and weights can be adjusted to change the decision


If no threshold (i.e. = 0), then if any of the issues is satisfied, the decision
to go is YES.
Perceptron represents a simplistic model of one node making a decision
Artificial
Neural
Networks
ANN are multi-layer
fully-connected neural
nets
Input layer — initial
data for the neural
network.
Hidden layers —
intermediate layer
between input and
output layer and place
where all the
computation is done.
Output layer —
produce the result for
given inputs.
Artificial Neuron
Mathematical Operation on one
Neuron
• Basic unit of computation, often called
a node or unit.
• It receives input from some other nodes,
or from an external source and computes
an output.
• Each input has an associated weight (w),
which is assigned on the basis of its
relative importance to other inputs.
• The node applies a function f (defined
below) to the weighted sum of its inputs.
Example
• Suppose we have a perceptron with two inputs, each with weight −2, and an
overall bias of 3.
• Then we see that input 0 0 produces output 1, since (−2)∗0+(−2) ∗0+3=3 is
positive.
• Similar calculations show that the inputs 0 1 and 1 0 produce output 1.
• But the input 1 1 produces output 0, since (−2)∗1+(−2)∗1+3=−1 is negative.
• And so our perceptron implements a NAND gate!
How do artificial neural
networks work?

• Initialize weight values


and bias
• Forward Propagate
• Check the error
• Backpropagate and
Adjust weights and bias
• Repeat for all training
examples
Training ANN
Solving a classification problem using NNs involves several steps:
◦ Determine the number of input nodes (attributes) as well as output nodes.
◦ The number of hidden layers (between the source and the sink nodes) also
must be decided. This step is performed by a domain expert.
◦ Determine weights (labels) and functions to be used for the graph.
◦ For every training example, perform a forward pass using the current
weights, and calculate the output of each node going from left to right. The
final output is the value of the last node.
◦ Compare the final output with the actual target in the training data, and
measure the error using a loss function.
◦ Perform a backwards pass from right to left and propagate the error to
every individual node using backpropagation. Calculate each weight’s
contribution to the error, and adjust the weights accordingly using gradient
descent. Propagate the error gradients back starting from the last layer.
AND
gate
What are the weights and bias for the AND perceptron?
Row 1
From w1*x1+w2*x2+b, initializing w1, w2, as 1 and b as –1, we get; The model to achieve
Passing (x1=0, x2=0), we get; 0+0–1 = –1 an AND gate, using the
Perceptron algorithm is;
From the Perceptron rule, if Wx+b≤0, then y`=0. Therefore, this row x1+x2–1
is correct, and no need for Backpropagation.
Row 2
Passing (x1=0 and x2=1), we get; 0+1–1 = 0, so y`=0; Correct
Row 3
Passing (x1=1 and x2=0), we get; 1+0–1 = 0, so y`=0; Correct
Row 4
Passing (x1=1 and x2=1), we get; 1+1–1=1, so y`=1; Correct

[Link]
b0275375fea1
OR gate
What are the weights and bias for the OR perceptron?
Row 1
From w1*x1+w2*x2+b, initializing w1, w2, as 1 and b as –1, we get;
Passing (x1=0, x2=0), we get; 0+0–1 = –1; Correct
From the Perceptron rule, if Wx+b≤0, then y`=0.
Row 2
Passing (x1=0 and x2=1), we get; 0+1–1 = 0, so y`=0; Incorrect
So we want values that will make inputs x1=0 and x2=1 give y` a value of 1. If we
change w2 to 2, we have;
0+2–1 = 1
From the Perceptron rule, this is correct for both the row 1 and 2.
OR gate
Row 3
Passing (x1=1 and x2=0), we get; 1+0–1 = 0, so y`=0; Incorrect
Since it is similar to that of row 2, we can just change w1 to 2, The model to achieve
we have; an OR gate, using the
Perceptron algorithm is;
2+0–1 = 1 2x1+2x2–1

From the Perceptron rule, this is correct for both the row 1, 2
and 3.
Row 4
Passing (x1=1 and x2=1), we get; 2+2–1=3, so y`=1; Correct
Key terms
[Link] — This is a basic building block of a NN. It takes weighted values,
performs mathematical calculation and produce output. It is also called a
unit, node or perceptron.
[Link] — This is the data/values passed to the neurons.
[Link] Neural Network (DNN) — This is an ANN with many hidden layers
(layers between the input (first) layer and the output (last) layer).
[Link] — These values explain the strength (degree of importance) of
the connection between any two neurons.
[Link] — is a constant value added to the sum of the product between
input values and respective weights. It is used to accelerate or delay the
activation of a given node.
[Link] function — is a function used to introduce the non-linearity
phenomenon into the NN system. This property will allow the network to
learn more complex patterns.
Processing of ANN
Processing of ANN depends upon the following three
building blocks −
◦ Network Topology
◦ Feedforward and feedback networks
◦ Adjustments of Weights or Learning
◦ Supervised learning
◦ Unsupervised learning
◦ Activation Functions
Activation functions
Neural network – Perceptrons – Sigmoid
neurons
• How to enable learning?
• Suppose we have a network of
perceptrons
• inputs to the network might be the
raw pixel data from a scanned,
handwritten image of a digit
• network learns weights and
biases; output from the network
correctly classifies the digit
• For a small change in the weight,
we want to see a small change in
output
Neural network – Perceptrons – Sigmoid
neurons
• If change can lead to change
• Adapt the weights to get the desired
output
• However, in case of perceptron
• small change can cause output to
change from 0 to 1 (or reverse); once
the threshold is crossed (or reverse)
• Sigmoid neurons
• Small changes in weights lead to
small changes in output; not a step /
jump as in the case of perceptrons
Neural network – Sigmoid neurons

• Sigmoid neuron, similar to a perceptron


• But output can take any value between and including 0 to 1 (i.e. [0,1])
• just like a perceptron, the sigmoid neuron has weights for each input,
w1,w2,…, and an overall bias, b
• Perceptron output is

• Sigmoid neuron output uses the sigmoid function


Bias b is usually shown as an
additional input to the neuron (not
shown here)
Neural network – Sigmoid neurons

• Output of the sigmoid neuron

• Can be written as

•  is called the sigmoid function (sometimes also called the logistic function)
• Sometimes the neurons are called logistic neurons
Neural network – Sigmoid neurons

• If z is a large +ve number

Smoothed out version


of step function
• If z is a large negative number

• Thus, sigmoid neuron output is


similar to perceptron at the
extreme values
• However, between 0 and 1, the
change is gradual
Neural network – Sigmoid neurons

• If  is a step-function
• Sigmoid neuron = perceptron
• Since then it behaves like a perceptron
• smoothness of σ is crucial
Smoothed out version
• small changes Δwj in weights and Δb in the bias
produce small change Δoutput in output from neuron;
of step function
for j inputs to a neuron

• means partial derivative


• If output is dependent on both w and b
• If one is kept constant (e.g. b), then what is the change
in output if w changes; similarly for the other variable
• Consider it to be the slope of output with each
variable
Perceptron example
Write the equation for the output for the given perceptro
Check whether the equation is correct using the dataset
Perceptron example

Why is the y here have a ^


above
What is the difference between
y in the left diagram, and in
the equation?
Perceptron activation
function - “sign”
Multilayer ANN
Give examples of ANN
and decision tree
applications
Which technique is better? Why?
When?
DT can handle only tabular data
ANN can be used for image recognition
DT if small is easy to interpret
◦ Easier in general

NN is not human interpretable


DT no prior “model”
◦ Pick an attribute at a time and proceed

NN requires layers and nodes to be defined in advance


Multilayer ANN application
example – Autonomous vehicle
1996
ANN application for
object detection
ANN for optical char
recognition (OCR)
ANN for OCR
Perceptron Learning
For any input x1, there is a weight w1
Similarly for x2, there is w2
And for x3, there is w3… and so on
Output of a perceptron is 0,1 (some also mention -1, 1)
◦ We will consider 0, 1

Assume,
Perceptron Learning
Assume initial weights are 1,0.6, 0.7,
assume bias is 0.8
◦ Usually random weights are assigned to
begin with
◦ For bias an additional input x4=1 is assumed

Lets check the predicted output for 1st row


◦ 1*1 + 0*.6 + 0*.7 + 1*0.8 = 3.1
◦ Expected output = -1

Difference Expected – Predicted


◦ -1 – 3.1 = -4.1

Adjust the weights


◦ Difference must be 0
◦ Large –ve difference
◦ We want to reduce the predicted value
(move 3.1 towards -1)
Perceptron Learning
Adjust the weights
Oldweight + adjustment
New-weight = Oldweight + error * learning-rate*input
New-w1 = 1 + (-4.1)*0.1*1
◦ Assumed learning-rate = 0.1
◦ New-w1 = 1 – 0.41 = 0.59

New-w2 = 0.6 + (-4.1)*0.1*0 = 0.6


New-w3 = 0.7 + (-4.1)*0.1*0 = 0.7
New-bias = 0.8 + (-4.1)*0.1*1 = 0.39
Perceptron Learning
Predict new value with new row
1*0.59 + 0*0.6 + 1*0.7 + 1*0.39 =
Error = 1 – 1.68 = - 0.68
◦ Notice the reduction in error

New weights
w1 = 0.59 - 0.68*0.1*1 = 0.522
w2 = 0.6 - 0.68*0.1*0 = 0.6
w3 = 0.7 - 0.68*0.1*1 = 0.632
b = 0.39 – 0.68*0.1*1 = 0.039
Notice how the values are getting
adjusted to the final expected values
Perceptron model -
learning
w-new = w-old + learning-rate *error *input value (x)
E.g.
w1-new = w1-old + λ * (correct y – predicted y) * x1

What is the effect of λ?


ANN training – Back-propagation
using gradient descent
Logic similar to perceptron training
Total sum ( Error2 ) is considered
◦ Sum of (y actual – y predicted)2 over all the output nodes (if there are more
than one output nodes)

Adjusting the weights is done using gradient descent


◦ Error will start decreasing (descent) along a gradient (slope) as the weights
are adjusted

Back-propagation
◦ In the forward pass inputs->activation->outputs
◦ In the backward pass output->Error->weight adjustment (one layer at a
time), going back one layer at a time
Types of ANN – Feed-
forward, Recurrent
Design issues in ANN
Number of input nodes
◦ Typically one input node for each numerical, binary, or categorical variable
(categorical means a set of values having no particular order e.g red, blue,
green)

Number of output nodes


◦ If binary, then one output node
◦ If more than 2 classes (more than just 0,1 or yes, no) then one node per
output (recall autonomous vehicle)

Network topology
◦ Determine number of hidden layers and nodes
◦ Decide on architecture – FF or RNN
◦ Start with large number of nodes, then reduce if required
Design issues in ANN
Weights and biases
◦ Start with random initial weights

Training example problems


◦ Examples having values missing should be removed from training
◦ Or values must be replaced with most probable values

You might also like