当前位置:网站首页>Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
2022-07-03 10:20:00 【Innocent^_^】
practice
- If we initialize the weight to zero , Will send ⽣ what . Is the algorithm still valid ?
\qquad Explain : whole 0 Initialization is also a common choice , Compared with normal distribution initialization, it may move towards different local optima , The algorithm is still effective .
- Suppose you are George · Simon · ohm , Try to build a relationship between voltage and current ⽴⼀ A model . You can make ⽤⾃ Dynamic differentiation to learn the parameters of the model ?
\qquad Explain : In the example, the current is regarded as features, Voltage as labels, After tracing points and drawing, it is found that there is a linear relationship between them , Just walk through the code in the book again .
- You can make... Based on Planck's law ⽤ Spectral energy density to determine the temperature of the object ?
\qquad Explain : Energy density spectrum u The function of wavelength is :

\qquad Write as a function of temperature as a function of energy density , namely :

- If you want to calculate ⼆ What problems may be encountered with the first derivative ? How would you solve these problems ?
\qquad Explain : The problem encountered should be that the calculation formula of first-order derivative function cannot be obtained directly . resolvent : Find the first derivative and save the calculation diagram . See the following code for the specific method .
- Why is it squared_loss Function needs to make ⽤reshape function ?
\qquad Explain : y ^ \hat{y} y^ Is a column vector , y y y It's a line vector
- Try to make ⽤ Different learning rates , Observe how fast the value of the loss function decreases .
\qquad Explain : There is no unified answer to this , When running the model, you can record the current learning rate and training time, and then compare them .
- If the number of samples cannot be batched ⼤ Small divisible ,data_iter Functional ⾏ For what will change ?
\qquad Explain : The number of samples left at the end of execution cannot be divided , Will report a mistake
Fourth, ask code learning , Reference resources pytorch autograd Calculate the second derivative of scalar function 
# The first 4 Ask for the second derivative :f(x)=x^2+sinx→f'(x)=2x+cosx→f''(x)=2-sinx
# Here take x=π/2,π
import math
import torch
import numpy as np
x = torch.tensor([math.pi/2,math.pi],requires_grad=True)
y = x**2 + torch.sin(x)
# Compare with the real value
true_dy = 2*x+torch.cos(x)# This result has two quantities , One is tensor, the other is gradient type
true_d2y = 2 - torch.sin(x)
# Find the first derivative , Save the calculation diagram and then find the second derivative
dy = torch.autograd.grad(y,x,
grad_outputs=torch.ones(x.shape),# This parameter should be manually specified
create_graph=True,
retain_graph=True# Save calculation diagram
)
# After the tensor, add .detach().numpy() Only tensor values can be output
print(" First derivative true value :{} \n First derivative calculation value :{}".format(true_dy.detach().numpy(),dy[0].detach().numpy()))
# Find the second derivative . above dy The first element of is the first derivative
d2y = torch.autograd.grad(dy[0],x,
grad_outputs=torch.ones(x.shape),
create_graph=False# No more calculation charts , Destroy the previous calculation diagram
)
print("\n Second order conduction true value :{} \n Second derivative calculation value :{}".format(true_d2y.detach().numpy(),d2y[0].detach().numpy()))
边栏推荐
- LeetCode - 703 数据流中的第 K 大元素(设计 - 优先队列)
- QT creator uses OpenCV Pro add
- Pycharm cannot import custom package
- 20220608 other: evaluation of inverse Polish expression
- CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
- 20220607其他:两整数之和
- [combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
- QT self drawing button with bubbles
- 20220610其他:任务调度器
- 1. Finite Markov Decision Process
猜你喜欢

CV learning notes - clustering

CV learning notes - feature extraction

CV learning notes - deep learning

Leetcode 300 最长上升子序列

CV learning notes - edge extraction

Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*

使用密钥对的形式连接阿里云服务器

Opencv note 21 frequency domain filtering

Leetcode - 933 number of recent requests

CV learning notes alexnet
随机推荐
20220603 Mathematics: pow (x, n)
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
20220608其他:逆波兰表达式求值
[C question set] of Ⅵ
Leetcode - 705 design hash set (Design)
What did I read in order to understand the to do list
Opencv image rotation
What useful materials have I learned from when installing QT
LeetCode - 715. Range module (TreeSet)*****
Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
Leetcode-513:找树的左下角值
CV learning notes - BP neural network training example (including detailed calculation process and formula derivation)
Leetcode-100: same tree
Leetcode - 5 longest palindrome substring
Basic use and actual combat sharing of crash tool
Leetcode bit operation
20220604数学:x的平方根
20220609其他:多数元素
Policy gradient Method of Deep Reinforcement learning (Part One)
20220606数学:分数到小数