0% found this document useful (0 votes)
23 views11 pages

Part (A) - Differences Between Scalars, Vectors, Ma

Uploaded by

hijaw72603
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)
23 views11 pages

Part (A) - Differences Between Scalars, Vectors, Ma

Uploaded by

hijaw72603
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/ 11

Part (a): Differences Between Scalars, Vectors, Matrices, and Tensors

Aspect Scalar Vector Matrix Tensor

Dimensionality 0 1 2 ≥3

Single numerical Ordered array of Rectangular array Multidimensional


Representation
value values (rows × columns) array

Features, Tabular data, linear Complex data


Usage Basic quantities
observations transformations structures

5 (a number), [1] [2] [3] (list), [ [4] [1] , [5] [6] ] (2×2 3D image,
Examples temperature,
velocity, force matrix), image pixel sequence data
mass

Simple Higher-order tensor


Manipulation Linear algebra Matrix arithmetic
arithmetic arithmetic

Data
Real-world Statistics, model Data operations, Deep learning,
representations,
Application accuracy transformations image data
directions

Scalar: A single number, e.g., 7. Represents magnitude only.


Vector: A one-dimensional array, e.g.,. Represents magnitude and direction. [4] [5] [2]
Matrix: A two-dimensional array, e.g., [, ]. Used for 2D representation or transformations. [1]
[6] [7] [8]

Tensor: Generalization to higher dimensions, e.g., a 3-dimensional array. Used for


multidimensional data, such as colored images. [5] [4]

Part (b): Computations

Scalar (3) and Matrix ([, ]) [2] [9] [7] [3]


Addition:
Add scalar 3 to each element of the matrix:
$$

$$
Multiplication:
Multiply scalar 3 with each element of the matrix:

$$

$$

Vector-Matrix Multiplication (Dot Product)


Given matrices:

Matrix A: (size 3×3)

Vector B: (size 3×1)


Dot Product (Matrix × Vector):
$$

$$
Result: The dot product yields a vector:

Summary
Scalars are single values (0D).
Vectors are 1D arrays.
Matrices are 2D arrays.
Tensors are arrays with ≥3 dimensions.
Matrix operations (with scalars and vectors) involve elementwise or linear combinations
based on rules of algebra. [4] [5]
If you need further explanation on vector multiplication or other operations, let me know!

2. Select an appropriate dataset of your choice,
apply the concept of a linear classifier to classify
the data, and demonstrate how to compute the
hinge loss function for the model with suitable
examples
Let's choose the classic Iris dataset (specifically a binary subset, e.g., "setosa" vs "versicolor")
for clarity, and demonstrate a linear classifier and how to compute the hinge loss function with a
concrete example.

1. Dataset Selection & Linear Classifier Example


Dataset:
The Iris dataset consists of 4 features: sepal length, sepal width, petal length, petal width.
For simplicity, let's use only 2 features and classify between "setosa" (label +1) and
"versicolor" (label -1).
Sample Data Points:
Example 1: x₁ = [5.1, 3.5], label y₁=+1 (setosa)
Example 2: x₂ = [7.0, 3.2], label y₂=-1 (versicolor)
Linear Classifier Equation:

Let’s choose weights and bias for demonstration, say w = [1, -1], b = 0.1.

2. Hinge Loss Function


Hinge loss is used in Support Vector Machines (SVMs):

Example:
Let’s compute for both data points:

For Example 1:
x₁ = [5.1, 3.5], y₁=+1
Score: $ s = \mathbf{w}^T \mathbf{x}_1 + b = (1 \times 5.1) + (-1 \times 3.5) + 0.1 = 5.1 - 3.5
+ 0.1 = 1.7 $
Hinge loss: $ L_1 = \max(0, 1 - (+1 \times 1.7)) = \max(0, 1 - 1.7) = \max(0, -0.7) = 0 $
For Example 2:
x₂ = [7.0, 3.2], y₂=-1
Score: $ s = (1 \times 7.0) + (-1 \times 3.2) + 0.1 = 7.0 - 3.2 + 0.1 = 3.9 $
Hinge loss: $ L_2 = \max(0, 1 - (-1 \times 3.9)) = \max(0, 1 + 3.9) = \max(0, 4.9) = 4.9 $

3. Summary Table
Example Features Label (y) Score Hinge Loss

Example 1 [5.1, 3.5] +1 1.7 0

Example 2 [7.0, 3.2] -1 3.9 4.9

Interpretation: A hinge loss of 0 means correct classification with sufficient margin. Nonzero
hinge loss penalizes misclassifications or predictions within margin. [11] [12] [13]

Linear classifiers like SVM or logistic regression use hinge loss (for SVM) to optimize the
decision boundary during training. The hinge loss function penalizes outputs that are wrong or
“not confident enough”, encouraging the model to push correct results beyond the margin. [12]
[13] [11]

3. Compare the sigmoid, ReLU, and tanh activation


functions in terms of their mathematical formulas
and output ranges. Explain with any real-time
application
Here is a comparison of the Sigmoid, ReLU, and Tanh activation functions in terms of their
mathematical formulas, output ranges, and real-time applications:

Activation Output
Mathematical Formula Characteristics & Applications
Function Range

$ \sigma(x) = \frac{1}{1
Sigmoid (0, 1) - Smooth S-shaped curve.
+ e^{-x}} $

- Output squashed between 0 and 1.

- Not zero-centered (outputs > 0).

- Suffers from vanishing gradient problem.

- Common in binary classification output layers


where probabilities are needed. Example: logistic
regression, binary classifiers.

$ \tanh(x) = \frac{e^{x}
Tanh (-1, 1) - S-shaped curve like sigmoid but zero-centered.
- e{-x}}{e{x} + e^{-x}} $
Activation Output
Mathematical Formula Characteristics & Applications
Function Range

- Output between -1 and 1, which helps centering


data.

- Also suffers from vanishing gradients, but


gradients are stronger than sigmoid.

- Often used in hidden layers of shallow networks.

- Outputs zero for negative inputs, linear for


ReLU $ ReLU(x) = \max(0, x) $ [0, ∞)
positive.

- Computationally efficient, simple to compute.

- Avoids vanishing gradient problem in positive


domain.

- Can suffer from “dying ReLU” problem where


neurons get stuck at zero.

- Widely used in hidden layers of deep neural


networks, especially CNNs.

Real-Time Applications
Sigmoid: Best suited for the output layer in binary classification tasks where the output
represents a probability (e.g., spam detection, medical diagnosis).
Tanh: Used in hidden layers when zero-centered activations are desired for better gradient
flow; often in smaller or shallow neural networks.
ReLU: The default activation for most deep learning architectures including convolutional
neural networks (CNNs) for image recognition, natural language processing, and other
complex tasks because of its efficiency and performance.

Summary
Sigmoid maps input to (0, 1), good for binary probability outputs but can suffer from slow
learning due to vanishing gradients.
Tanh maps input to (-1, 1), is zero-centered, offering stronger gradients than sigmoid but still
can face vanishing gradient issues.
ReLU outputs 0 for negative inputs and linear for positive inputs, highly efficient and helps
deep networks train faster, though may cause dead neurons.
This combination makes ReLU the most popular choice for hidden layers, while sigmoid remains
common in the final output layer for classification tasks. [20] [21] [22]

Concept of Backpropagation and Its Importance in Training Multilayer Perceptrons
Backpropagation is an essential algorithm for training multilayer perceptrons (MLPs), i.e., deep
neural networks. It efficiently computes the gradient of the loss function with respect to each
weight in the network, enabling the use of gradient descent to update the weights and minimize
the error.

Importance in Training Multilayer Perceptrons


MLPs have multiple layers with many weights and biases.
Directly calculating the gradient of the output error w.r.t. each parameter is complex.
Backpropagation uses the chain rule of calculus to propagate the error backward through
the network.
This helps efficiently compute how much each parameter contributed to the error.
Gradients calculated by backpropagation guide the weight updates during training.
Without backpropagation, training deep networks would be computationally impractical.

Main Steps Involved in Backpropagation Algorithm


1. Forward Pass:
Input data is passed through the network layer by layer.
Each neuron computes a weighted sum of inputs plus bias.
Activations are produced via activation functions (e.g., sigmoid, ReLU).
Final output of the network is obtained.
Loss (error) is computed by comparing predicted output with the true label using a loss
function (e.g., mean squared error, cross-entropy).
2. Backward Pass (Backpropagation):
The derivative of the loss with respect to the network output is calculated.
This error derivative is propagated backward from the output layer to the input layer.
Using the chain rule, gradients of the loss w.r.t. each weight and bias are computed.
For each neuron, the error is attributed to its inputs based on their contribution
(weights).
Activation function derivatives are used to modulate this gradient during propagation.
3. Weight Update:
Gradients are used to adjust weights and biases to reduce the loss.
Typically done using an optimization algorithm like gradient descent:

where is the learning rate, and is the gradient.


4. Repeat for Multiple Epochs:
The forward and backward pass steps are repeated over many iterations (epochs) until
the model converges, i.e., the loss is minimized and the network generalizes well on new
data.

Summary
Backpropagation is the cornerstone training algorithm for multilayer perceptrons.
It combines forward propagation of inputs and backward propagation of errors using
calculus.
It enables efficient gradient computation for complex layered structures.
Without it, modern deep learning and training of neural networks wouldn't be feasible. [27]
[28] [29] [30]

If you'd like, I can also provide a simplified numerical example of backpropagation for clarity!

5 Construct and train a single artificial neuron


based on the given dataset, empirying the step
function as the activation function.
32
0
0
Target (10)
0
0
0
1
Table 1. Inputs
The node has three inputs x yv at shown in the table and the weights are wt r = - 0.5 x * 2 = 1 ,
w3-0.5, threshold -0.2 and learning rate q-0.1. Show how the wrights supdated for each
training(at least for one iterations),
Let's work through the training of a single artificial neuron (perceptron) with the given dataset
and parameters.

Given:
Inputs (x1, x2, x3):
x1 x2 x3 Target (t)

3 2 0 0
x1 x2 x3 Target (t)

0 0 1 0

0 0 0 1

Initial weights:
$ w_1 = -0.5, w_2 = 1, w_3 = -0.5 $
Threshold (bias):
Learning rate: $ \eta = 0.1 $
Activation function: Step function

Step 1: Calculate output for first training example


Input: $ \mathbf{x} = $ [34] [35]
Weighted sum:

Compare with threshold :

Target , output = 1 → Error:

Step 2: Update weights using learning rule

Calculate for each weight:

Step 3: Summary for first iteration on example 1


Weight Before Update Error Update $ \eta \times e \times x_i $ After Update

-0.5 -1 -0.8

1 -1 0.8

-0.5 -1 -0.5
If needed, similar calculations can be done for the second and third inputs to continue training.

Summary:
The neuron predicted 1, but the target was 0, so weights were adjusted downward
proportionally to the input values and error.
Weight updates move the neuron output closer to the target in subsequent iterations.
The step function dictates when the neuron fires based on weighted input sum vs.
threshold.
This is the basic working of a single artificial neuron training with the perceptron learning rule
using a step activation function. If you want, I can continue with weights update for further
iterations.

1. https://classic.d2l.ai/chapter_preliminaries/linear-algebra.html
2. https://www.quantstart.com/articles/scalars-vectors-matrices-and-tensors-linear-algebra-for-deep-lea
rning-part-1/
3. https://peerherholz.github.io/Cog_Com_Neuro_ML_DL/introduction/notebooks/linear_algebra/LinearAlge
bra.html
4. https://www.geeksforgeeks.org/machine-learning/difference-between-scalar-vector-matrix-and-tenso
r/
5. https://www.vedantu.com/maths/scalar-vector-matrix
6. https://www.reddit.com/r/explainlikeimfive/comments/1irl5m8/eli5_what_are_the_main_differences_bet
ween/
7. https://www.stephanosterburg.com/math_data_types
8. https://www.youtube.com/watch?v=wvW4fAFUUWE
9. https://uselessai.in/understanding-tensors-vectors-matrices-the-foundation-of-deep-learning-ai-cf9e5
8867b2f
10. https://www.machinelearningmastery.com/introduction-to-tensors-for-machine-learning/
11. https://dataaspirant.com/popular-linear-classifiers/
12. https://mlcourse.ai/book/topic04/topic4_linear_models_part2_logit_likelihood_learning.html
13. https://en.wikipedia.org/wiki/Linear_classifier
14. https://cse.poriyaan.in/topic/linear-classification-models-51007/
15. https://mylearningsinaiml.wordpress.com/linear-classification/
16. https://www.geeksforgeeks.org/machine-learning/getting-started-with-classification/
17. https://www.sciencedirect.com/topics/computer-science/linear-classifier
18. https://www.youtube.com/watch?v=WcaMiqJR09s
19. https://www.kaggle.com/code/kashnitsky/topic-4-linear-models-part-2-classification
20. https://www.aitude.com/comparison-of-sigmoid-tanh-and-relu-activation-functions/
21. https://www.geeksforgeeks.org/deep-learning/tanh-vs-sigmoid-vs-relu/
22. https://www.baeldung.com/cs/sigmoid-vs-tanh-functions
23. https://akanshasaxena.com/challenge/deep-learning/day-4/
24. https://www.ijspr.com/citations/v80n6/IJSPR_8006_31035.pdf
25. https://ml-cheatsheet.readthedocs.io/en/latest/activation_functions.html
26. https://www.v7labs.com/blog/neural-networks-activation-functions
27. https://www.geeksforgeeks.org/machine-learning/backpropagation-in-neural-network/
28. https://neptune.ai/blog/backpropagation-algorithm-in-neural-networks-guide
29. https://mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/
30. http://neuralnetworksanddeeplearning.com/chap2.html
31. https://datamapu.com/posts/deep_learning/backpropagation/
32. https://en.wikipedia.org/wiki/Backpropagation
33. https://hmkcode.com/ai/backpropagation-step-by-step/
34. https://ijritcc.org/index.php/ijritcc/article/download/1818/1818/1793
35. https://blog.nashtechglobal.com/complete-guide-to-single-layer-perceptron-with-implementation/
36. https://sebastianraschka.com/Articles/2015_singlelayer_neurons.html
37. https://en.wikipedia.org/wiki/Artificial_neuron
38. https://www.v7labs.com/blog/neural-networks-activation-functions
39. https://www.kaggle.com/code/ryanholbrook/a-single-neuron
40. https://www.geeksforgeeks.org/machine-learning/activation-functions-neural-networks/

You might also like