当前位置:网站首页>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 - 1670 conception de la file d'attente avant, moyenne et arrière (conception - deux files d'attente à double extrémité)
- [C question set] of Ⅵ
- About windows and layout
- 20220607其他:两整数之和
- CV learning notes - reasoning and training
- 20220531数学:快乐数
- 20220603数学:Pow(x,n)
- What can I do to exit the current operation and confirm it twice?
- Modelcheckpoint auto save model
- Step 1: teach you to trace the IP address of [phishing email]
猜你喜欢
Leetcode - 1172 plate stack (Design - list + small top pile + stack))
What did I read in order to understand the to do list
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
[LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression
LeetCode - 5 最长回文子串
Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
Opencv+dlib to change the face of Mona Lisa
Flutter 退出当前操作二次确认怎么做才更优雅?
CV learning notes ransca & image similarity comparison hash
3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation
随机推荐
Mise en œuvre d'OpenCV + dlib pour changer le visage de Mona Lisa
CV learning notes - BP neural network training example (including detailed calculation process and formula derivation)
Deep learning by Pytorch
Step 1: teach you to trace the IP address of [phishing email]
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow
LeetCode - 715. Range module (TreeSet)*****
20220608其他:逆波兰表达式求值
CV learning notes - clustering
[combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
Modelcheckpoint auto save model
Discrete-event system
Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
LeetCode - 715. Range 模块(TreeSet) *****
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
Opencv Harris corner detection
20220607 others: sum of two integers
Deep Reinforcement learning with PyTorch
What can I do to exit the current operation and confirm it twice?
20220604 Mathematics: square root of X