当前位置:网站首页>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()))
边栏推荐
- 20220601 Mathematics: zero after factorial
- Powshell's set location: unable to find a solution to the problem of accepting actual parameters
- RESNET code details
- Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
- Leetcode - 705 design hash set (Design)
- Leetcode-112:路径总和
- Dynamic layout management
- On the problem of reference assignment to reference
- Tensorflow built-in evaluation
- LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
猜你喜欢
『快速入门electron』之实现窗口拖拽
Opencv gray histogram, histogram specification
Cases of OpenCV image enhancement
Opencv histogram equalization
Pycharm cannot import custom package
Label Semantic Aware Pre-training for Few-shot Text Classification
The underlying principle of vector
Discrete-event system
QT is a method of batch modifying the style of a certain type of control after naming the control
Opencv note 21 frequency domain filtering
随机推荐
Leetcode-404:左叶子之和
Mise en œuvre d'OpenCV + dlib pour changer le visage de Mona Lisa
Markdown latex full quantifier and existential quantifier (for all, existential)
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
Judging the connectivity of undirected graphs by the method of similar Union and set search
4.1 Temporal Differential of one step
20220531 Mathematics: Happy numbers
Leetcode - 705 design hash set (Design)
[LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression
使用密钥对的形式连接阿里云服务器
Opencv image rotation
LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
20220608 other: evaluation of inverse Polish expression
Leetcode-100: same tree
Opencv feature extraction - hog
Leetcode-106:根据中后序遍历序列构造二叉树
Leetcode-100:相同的树
When the reference is assigned to auto
3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation
QT setting suspension button