当前位置: 首页 > news >正文

建设一个怎样的自己的网站网站开发的内容

建设一个怎样的自己的网站,网站开发的内容,知乎app开发公司,做门户网站需要什么注#xff1a;书中对代码的讲解并不详细#xff0c;本文对很多细节做了详细注释。另外#xff0c;书上的源代码是在Jupyter Notebook上运行的#xff0c;较为分散#xff0c;本文将代码集中起来#xff0c;并加以完善#xff0c;全部用vscode在python 3.9.18下测试通过。…注书中对代码的讲解并不详细本文对很多细节做了详细注释。另外书上的源代码是在Jupyter Notebook上运行的较为分散本文将代码集中起来并加以完善全部用vscode在python 3.9.18下测试通过。 Chapter3 Linear Neural Networks 3.2 Implementations of Linear Regression from Scratch import numpy as np import matplotlib.pyplot as plt import pandas as pd import random import torch from d2l import torch as d2ldef synthetic_data(w, b, num_examples): #saveGenerate y Xw b noise.#generates a random matrix X with dimensions (num_examples, len(w)) using a normal distribution with a mean of 0 and standard deviation of 1.X torch.normal(0, 1, (num_examples, len(w)),dtypetorch.float32) #calculates the target values y by multiplying the input matrix X with the weight vector w and adding the bias term b. y torch.matmul(X, w) b #And then adds some random noise to the target values y. The noise is generated from a normal distribution with mean 0 and standard deviation 0.01. y torch.normal(0, 0.01, y.shape) return X, y.reshape((-1, 1)) #The -1 in the first dimension means that PyTorch should automatically infer the size of that dimension based on the total number of elements. In other words, it is used to ensure that the reshaped tensor has the same total number of elements as the original tensor.true_wtorch.tensor([2,-3.4],dtypetorch.float32) true_b4.2 features,labelssynthetic_data(true_w,true_b,1000) print(features:,features[0],\nlabel:,labels[0])d2l.set_figsize() d2l.plt.scatter(features[:,(1)].detach().numpy(),labels.detach().numpy(),1) #plt.show()#显示散点图 #features[:, 1] selects the second column of the features tensor. #The detach() method is used to create a new tensor that shares no memory with the original tensor, and numpy() is then called to convert it to a NumPy array. #1 is the size of the markers in the scatter plot.def data_iter(batch_size,features,labels):num_exampleslen(features)indiceslist(range(num_examples))#随机读取文本random.shuffle(indices)#Shuffle the indices意为打乱索引 for i in range(0,num_examples,batch_size):batch_indicestorch.tensor(indices[i:min(ibatch_size,num_examples)])#min(i batch_size, num_examples) is used to handle the last batch, which might have fewer examples than batch_size.yield features[batch_indices],labels[batch_indices]#初始化参数。从均值为0标准差为0.01的正态分布中抽取随机数来初始化权重并将偏置量置为0 wtorch.normal(0,0.01,size(2,1),requires_gradTrue) btorch.zeros(1,requires_gradTrue)#定义线性回归模型 def linreg(X,w,b): #savereturn torch.matmul(X,w)b #广播机制用一个向量加一个标量时标量会加到向量的每一个分量上#定义均方损失函数 def squared_loss(y_hat,y): #savereturn (y_hat-y.reshape(y_hat.shape))**2/2#定义优化算法小批量随机梯度下降 def sgd(params,lr,batch_size): #savewith torch.no_grad():for param in params:param-lr*param.grad/batch_sizeparam.grad.zero_()#轮数num_epochs和学习率lr都是超参数先分别设为3和0.03具体方法后续讲解 lr0.03 num_epochs3 batch_size10for epoch in range(num_epochs):for X,y in data_iter(batch_size,features,labels):lsquared_loss(linreg(X,w,b),y)l.sum().backward()#因为l是一个向量而不是标量因此需要把l的所有元素加到一起来计算关于(w,b)的梯度sgd([w,b],lr,batch_size)with torch.no_grad():train_lsquared_loss(linreg(features,w,b),labels)print(fepoch {epoch1}:squared_loss {float(train_l.mean()):f}) print(fw的估计误差:{true_w-w.reshape(true_w.shape)}) #结果中的grad_fnSubBackward0表示这个tensor是由一个正向减法操作生成的 print(fb的估计误差:{true_b-b})#RsubBackward1表示由一个反向减法操作生成
http://www.w-s-a.com/news/664673/

相关文章:

  • 重庆网站商城宁波网络公司联系方式
  • 个人网站建设实验心得seo课程简介
  • 免费自助建站系统下载推广app网站
  • 用scala做的网站标题关键词优化技巧
  • 百度网站评级wordpress忘记admin
  • 建筑标准下载网站263企业邮箱 登陆
  • 旅游房地产网站建设德保网站建设
  • 网站高端建设wordpress订单系统
  • 建设网站成本增加网站备案
  • 行业网站建设方案百度云图片转wordpress
  • 如何建设网站推广平台营销客户管理软件
  • 网站制作南宁如何撰写一个网站规划建设方案
  • 建站网站和维护需要会什么杭州人防质监站网址
  • 唐山免费做网站莱芜吧贴吧最新消息
  • 韶关市建设工程造价网站网络营销的平台有哪些
  • 网站建设费大概多少钱成都网站建设低价
  • 做表格的网站东莞常平房价
  • 国家级建设网站高密做网站哪家强价位
  • 江西省新的建设厅三类人员网站做标记网站
  • 做最精彩绳艺网站产品设计培训
  • 营销型网站建设品牌深圳网络推广最新招聘
  • 单位网站等级保护必须做吗广州app软件开发公司
  • 免费flash网站模板怎么仿网站链接
  • 泉州网站建设哪家好平面设计转行做什么比较好
  • 忘记网站备案账号设计一个网站
  • 国内购物网站哪个最好海珠营销网站建设报价
  • 小型网站搭建logo免费制作
  • dede 网站模板哈尔滨房产信息网官方网站
  • 设计师个人作品集模板班级优化大师网页版登录
  • 高端网站建设教学网站开发前期准备工作