• No results found

Basics of Tensors and Simple Example

N/A
N/A
Protected

Academic year: 2022

Share "Basics of Tensors and Simple Example"

Copied!
26
0
0

Loading.... (view fulltext now)

Full text

(1)

Basics of Tensors and Simple Example

Dr. Konda Reddy Mopuri kmopuri@iittp.ac.in Dept. of CSE, IIT Tirupati

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 1

(2)

Tensor

1 Generalized matrix

2 Finite table of data

3 Indexed along discrete dimensions

(3)

Tensor

1 Generalized matrix

2 Finite table of data

3 Indexed along discrete dimensions

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 2

(4)

Tensor

1 Generalized matrix

2 Finite table of data

3 Indexed along discrete dimensions

(5)

Tensor

1 0D tensor - scalar

2 1D tensor - vector (e.g. sound sample)

3 2D tensor - matrix (e.g. gray-scale image)

4 3D tensor → vector of identically sized matrices (e.g. RGB image)

5 4D tensor → matrix of identically sized matrices or a sequence of 3D tensors (e.g. sequence of RGB images)

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 3

(6)

Tensor

1 0D tensor - scalar

2 1D tensor - vector (e.g. sound sample)

3 2D tensor - matrix (e.g. gray-scale image)

4 3D tensor → vector of identically sized matrices (e.g. RGB image)

5 4D tensor → matrix of identically sized matrices or a sequence of 3D tensors (e.g. sequence of RGB images)

(7)

Tensor

1 0D tensor - scalar

2 1D tensor - vector (e.g. sound sample)

3 2D tensor - matrix (e.g. gray-scale image)

4 3D tensor → vector of identically sized matrices (e.g. RGB image)

5 4D tensor → matrix of identically sized matrices or a sequence of 3D tensors (e.g. sequence of RGB images)

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 3

(8)

Tensor

1 0D tensor - scalar

2 1D tensor - vector (e.g. sound sample)

3 2D tensor - matrix (e.g. gray-scale image)

4 3D tensor → vector of identically sized matrices (e.g. RGB image)

5 4D tensor → matrix of identically sized matrices or a sequence of 3D tensors (e.g. sequence of RGB images)

(9)

Tensor

1 0D tensor - scalar

2 1D tensor - vector (e.g. sound sample)

3 2D tensor - matrix (e.g. gray-scale image)

4 3D tensor → vector of identically sized matrices (e.g. RGB image)

5 4D tensor → matrix of identically sized matrices or a sequence of 3D tensors (e.g. sequence of RGB images)

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 3

(10)

Tensor

Figure Credits: datacamp.com

(11)

Tensors are used to

1 Encoding signals (e.g. text, speech, image, etc.) Internal states and parameters of the model

2 Operating on data through this constrained structure allows CPUs and GPUs to operate at their near peak performance.

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 5

(12)

Tensors are used to

1 Encoding signals (e.g. text, speech, image, etc.) Internal states and parameters of the model

2 Operating on data through this constrained structure allows CPUs and GPUs to operate at their near peak performance.

(13)

PyTorch’s main features

1 Efficient tensor manipulations on CPU/GPU Standard LA and DL specific operations

2 Autograd: automatic on-the-fly differentiation

3 Optimizers

Variety of optimizers (e.g. SGD, Adam, etc.); Hassle-free to apply

4 Data i/o

Load a data sample or datasets, etc.

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 6

(14)

PyTorch’s main features

1 Efficient tensor manipulations on CPU/GPU Standard LA and DL specific operations

2 Autograd: automatic on-the-fly differentiation

3 Optimizers

Variety of optimizers (e.g. SGD, Adam, etc.); Hassle-free to apply

4 Data i/o

Load a data sample or datasets, etc.

(15)

PyTorch’s main features

1 Efficient tensor manipulations on CPU/GPU Standard LA and DL specific operations

2 Autograd: automatic on-the-fly differentiation

3 Optimizers

Variety of optimizers (e.g. SGD, Adam, etc.); Hassle-free to apply

4 Data i/o

Load a data sample or datasets, etc.

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 6

(16)

PyTorch’s main features

1 Efficient tensor manipulations on CPU/GPU Standard LA and DL specific operations

2 Autograd: automatic on-the-fly differentiation

3 Optimizers

Variety of optimizers (e.g. SGD, Adam, etc.); Hassle-free to apply

4 Data i/o

Load a data sample or datasets, etc.

(17)

Tensor Basics

Colab Notebook: Tensor basics

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 7

(18)

Example: Linear Regression

(19)

Linear Regression

1 Given a set of data points (xn, yn) ∈ R × R, n = 1, 2, . . . N

2 Finding the best line that fits the data, f (x; a, b) = ax + b

3 i.e., minimizes the mean squared error (MSE), argmin

a,b 1

NΣNi=1(axn+ b − yn)2

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 9

(20)

Linear Regression

1 Given a set of data points (xn, yn) ∈ R × R, n = 1, 2, . . . N

2 Finding the best line that fits the data, f (x; a, b) = ax + b

3 i.e., minimizes the mean squared error (MSE), argmin

a,b 1

NΣNi=1(axn+ b − yn)2

(21)

Linear Regression

1 Given a set of data points (xn, yn) ∈ R × R, n = 1, 2, . . . N

2 Finding the best line that fits the data, f (x; a, b) = ax + b

3 i.e., minimizes the mean squared error (MSE), argmin

a,b 1

NΣNi=1(axn+ b − yn)2

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 9

(22)

Linear Regression

1 a = ΣNi=1ΣN(xi−¯x)(yi−¯y) i=1(xi−¯x)2

2 b = ¯y − a¯x

(23)

Linear Regression

1 a = ΣNi=1ΣN(xi−¯x)(yi−¯y) i=1(xi−¯x)2

2 b = ¯y − a¯x

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 10

(24)

Linear Regression

Colab Notebook: Linear Regression

(25)

Tensors can be

torch.float16, torch.float32, torch.float64 torch.uint8

torch.int8, torch.int16, torch.int32, torch.int64

Dr. Konda Reddy Mopuri dlc-1.2/Basics of Tensors 12

(26)

Tensors can be

Located either in CPU or in GPU

Operations are performed only by that device in whose memory the tensor is stored

References

Related documents

approach is to recognize that evidence related to whether a victim had an STD or whether the defendant thought the victim had an STD at the time of an alleged sex crime is evidence

We prove that solutions to the fractional heat equation with homogeneous Neumann conditions have the following natural properties: conservation of mass inside Ω, decreas- ing

respiratory tract infections (reduction in the number of episodes of respiratory infec- tions and in duration of some of its symp- toms) of athletes following intake of probi-

Numbers of hides and skulls exported from Canada in 2013 and 2014 that came from bears killed in the 2012/13 hunting season; and the number of individual bears represented by

To study the effect of different insulin administration protocols, we performed three intravenous glucose tolerance tests in each of seven obese subjects (age, 20–41 yr; body

They model equilibrium real house prices as a function of the size of the metropolitan area (population level and real median income), the real construction costs, an expected

Another factor powering M&A activity is China, which is pursuing the development of its semiconductor industry through acquisitions; its government has announced plans to spend

According to the results of our survey study concerning the changes in the organizational structure National Education, the fact that it was found there is no significant difference