中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

常州網(wǎng)站制作公司多嗎寶雞網(wǎng)站開發(fā)公司

常州網(wǎng)站制作公司多嗎,寶雞網(wǎng)站開發(fā)公司,seo排名優(yōu)化推廣教程,網(wǎng)站開發(fā) 會員模塊注:書中對代碼的講解并不詳細,本文對很多細節(jié)做了詳細注釋。另外,書上的源代碼是在Jupyter Notebook上運行的,較為分散,本文將代碼集中起來,并加以完善,全部用vscode在python 3.9.18下測試通過?!?article class="baidu_pl">

注:書中對代碼的講解并不詳細,本文對很多細節(jié)做了詳細注釋。另外,書上的源代碼是在Jupyter Notebook上運行的,較為分散,本文將代碼集中起來,并加以完善,全部用vscode在python 3.9.18下測試通過。

Chapter3 Linear Neural Networks

3.3 Concise Implementations of Linear Regression

import numpy as np
import torch
from torch.utils import data
from d2l import torch as d2ltrue_w=torch.tensor([2,-3.4])
true_b=4.2
features,labels=d2l.synthetic_data(true_w,true_b,1000)#構(gòu)造一個pytorch數(shù)據(jù)迭代器
def load_array(data_arrays,batch_size,is_train=True): #@savedataset=data.TensorDataset(*data_arrays)#"TensorDataset" is a class provided by the torch.utils.data module which is a dataset wrapper that allows you to create a dataset from a sequence of tensors. #"*data_arrays" is used to unpack the tuple into individual tensors.#The '*' operator is used for iterable unpacking.#Here, data_arrays is expected to be a tuple containing the input features and corresponding labels. The "*data_arrays" syntax is used to unpack the elements of the tuple and pass them as separate arguments.return data.DataLoader(dataset,batch_size,shuffle=is_train)#Constructs a PyTorch DataLoader object which is an iterator that provides batches of data during training or testing.
batch_size=10
data_iter=load_array([features,labels],batch_size)
print(next(iter(data_iter)))#調(diào)用next()函數(shù)時會返回迭代器的下一個項目,并更新迭代器的內(nèi)部狀態(tài)以便下次調(diào)用#定義模型變量,nn是神經(jīng)網(wǎng)絡(luò)的縮寫
from torch import nn
net=nn.Sequential(nn.Linear(2,1))
#Creates a sequential neural network with one linear layer.
#Input size (in_features) is 2, indicating the network expects input with 2 features.
#Output size (out_features) is 1, indicating the network produces 1 output.#初始化模型參數(shù)
net[0].weight.data.normal_(0,0.01)#The underscore at the end (normal_) indicates that this operation is performed in-place, modifying the existing tensor in memory.
net[0].bias.data.fill_(0)#定義均方誤差損失函數(shù),也稱平方L2范數(shù),返回所有樣本損失的平均值
loss=nn.MSELoss()#MSE:mean squared error #定義優(yōu)化算法(仍是小批量隨機梯度下降)
#update the parameters of the neural network (net.parameters()) using gradients computed during backpropagation. 
trainer=torch.optim.SGD(net.parameters(),lr=0.03)#SGD:stochastic gradient descent(隨機梯度下降)#訓(xùn)練
num_epochs=3
for epoch in range(num_epochs):for X,y in data_iter:l=loss(net(X),y)trainer.zero_grad()l.backward()trainer.step()#Updates the model parameters using the computed gradients and the optimization algorithm.l=loss(net(features),labels)print(f'epoch {epoch+1},loss {l:.6f}')#{l:.f}表示將變量l格式化為小數(shù)點后有6位的浮點數(shù)。w=net[0].weight.data
print('w的估計誤差:',true_w-w.reshape(true_w.shape))
b=net[0].bias.data
print('b的估計誤差:',true_b-b)
http://www.risenshineclean.com/news/43042.html

相關(guān)文章:

  • 蜜蜂vp加速器七天試用杭州優(yōu)化公司在線留言
  • 環(huán)保業(yè)網(wǎng)站建設(shè)的策劃軟文是指什么
  • 百度網(wǎng)站建設(shè)要多少錢春哥seo博客
  • 容桂銷售型網(wǎng)站建設(shè)知乎關(guān)鍵詞排名
  • 使用wordpress的用戶有哪些電商seo優(yōu)化是什么意思
  • 怎么做淘寶聯(lián)盟網(wǎng)站寧波網(wǎng)站推廣制作
  • 大型網(wǎng)站系統(tǒng)圖seo外包軟件
  • 霸州網(wǎng)站建設(shè)廣州全網(wǎng)推廣
  • 唐山做網(wǎng)站公司網(wǎng)絡(luò)服務(wù)商主要包括
  • 360免費建站為什么注冊不了自己建網(wǎng)站流程
  • 長春網(wǎng)站免費制作百度搜索數(shù)據(jù)查詢
  • 什么網(wǎng)站可以設(shè)計接單做網(wǎng)站推廣seo方法
  • 手機網(wǎng)站建站教育模板下載國外網(wǎng)站seo免費
  • 網(wǎng)站排名標(biāo)準(zhǔn)怎么弄一個自己的網(wǎng)站
  • 不會寫代碼怎樣做網(wǎng)站開發(fā)一個平臺需要多少錢
  • 用凡科做的網(wǎng)站保存不了sem專員
  • 世界局勢最新消息馮耀宗seo博客
  • 360云盤做 網(wǎng)站圖片服務(wù)器濟南網(wǎng)站建設(shè)哪家便宜
  • 中國自適應(yīng)網(wǎng)站建設(shè)朝陽網(wǎng)站seo
  • 醫(yī)藥網(wǎng)站怎么做搜索引擎優(yōu)化是做什么的
  • 國務(wù)院政府網(wǎng)站集約化建設(shè)seo排名優(yōu)化工具
  • 求一個能用的網(wǎng)址網(wǎng)站搜索排名優(yōu)化價格
  • index 石家莊網(wǎng)站建設(shè)友鏈交易平臺源碼
  • 浙江龍游疫情最新消息搜索引擎排名優(yōu)化
  • 編寫 網(wǎng)站 語言海外免費網(wǎng)站推廣有哪些
  • 網(wǎng)站開發(fā)工作描述百度搜索引擎介紹
  • 商用自適應(yīng)網(wǎng)站建設(shè)智能搜索引擎
  • 自助建站廣告發(fā)布天津推廣的平臺
  • 自適應(yīng)營銷網(wǎng)站模板互聯(lián)網(wǎng)營銷培訓(xùn)班
  • 建立soho公司網(wǎng)站什么是搜索引擎優(yōu)化推廣