PyTorch is an open-source machine learning library that turns mathematical ideas into executable Python programs. It supports tensor manipulation, linear algebra, probability distributions, neural networks, optimization, and convolution, with examples commonly run in Jupyter Notebook. section 2.2 section 5.0
Typical uses include:
- Representing vectors, matrices, tensors, and data batches for machine-learning computations. section 2.2
- Computing eigenvalues, eigenvectors, singular-value decompositions, PCA, and latent semantic analysis. section 2.15.1 section 4.5.7 section 4.6.3
- Building datasets, neural-network models, loss functions, optimizers, and training loops. section 9.2.3
- Applying fixed or learned one-dimensional and two-dimensional convolution kernels. section 10.1.4 section 10.3.3
Training a classifier
A custom Dataset exposes height, weight, and class-label records; DataLoader creates shuffled minibatches; a two-layer model produces raw scores; CrossEntropyLoss, backpropagation, and SGD update its parameters. section 9.2.3
Listing 14.1 PyTorch- PCA revisited
import torch
X = get_data() #1
X_mean = X.mean(axis=0) #2
X = X - X_mean #3
U, S, Vh = torch.linalg.svd(X, full_matrices=False) #4
V = Vh.T #5
V_trimmed = V[:, 0: 2] #6
X_proj = torch.matmul(X, V_trimmed) #7
X_proj = torch.cat([X_proj, #8
torch.zeros((X_proj.shape[0], 1))], axis=1)
X_recon = torch.matmul(X_proj, Vh) #9
X_recon = X_recon + X_mean #10
PCA dimensionality reduction centers data, computes an SVD, projects onto two components, and approximately reconstructs the original points. section 14.4.1










