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

静海网站建设公司怎么设计网站

静海网站建设公司,怎么设计网站,深圳企业vi设计公司,西安网站优化指导上一篇关于反向传播的代码仅支持单变量的梯度计算,下面我们将扩展代码使其支持多个输入/输出。增加了对多输入函数(如 Add),以实现的计算。 1.关于前向传播可变长参数的改进-修改Function类 修改方法: Function用于对…

上一篇关于反向传播的代码仅支持单变量的梯度计算,下面我们将扩展代码使其支持多个输入/输出。增加了对多输入函数(如 Add),以实现的计算。

1.关于前向传播可变长参数的改进-修改Function类

修改方法:

Function用于对输入输出做规定,帮助实现右图的效果(接受inputs 返回outputs):

2.关于反向传播可变长参数的改进

修改函数类的反向传播

修改Variable类的反向传播

改进前:

获取y.creator,获取输入creator.inputs,根据y.grads计算x.grads:creator.backward(y.grads)

2.3两步的解包和打包操作:

最后修改square方法:

完整代码

import numpy as npclass Variable:def __init__(self, data):if data is not None:if not isinstance(data, np.ndarray):raise TypeError('{} is not supported'.format(type(data)))self.data = dataself.grad = Noneself.creator = Nonedef set_creator(self, func):self.creator = funcdef backward(self):if self.grad is None:self.grad = np.ones_like(self.data)funcs = [self.creator]while funcs:f = funcs.pop()gys = [output.grad for output in f.outputs]  # 获取所有输出的梯度gxs = f.backward(*gys)                       # 调用 backward 方法if not isinstance(gxs, tuple):               # 确保 gxs 是元组gxs = (gxs,)for x, gx in zip(f.inputs, gxs):            # 为每个输入分配梯度x.grad = gxif x.creator is not None:funcs.append(x.creator)class Function:def __call__(self, *inputs):xs = [x.data for x in inputs]               # 提取输入数据ys = self.forward(*xs)                      # 前向传播(解包)if not isinstance(ys, tuple):               # 确保 ys 是元组ys = (ys,)outputs = [Variable(as_array(y)) for y in ys]  # 创建输出变量for output in outputs:output.set_creator(self)self.inputs = inputs                        # 保存输入self.outputs = outputs                      # 保存输出return outputs if len(outputs) > 1 else outputs[0]  # 根据输出数量返回def forward(self, *xs):raise NotImplementedError()def backward(self, *gys):raise NotImplementedError()# 实现具体的函数类
class Square(Function):def forward(self, x):return x ** 2def backward(self, gy):x = self.inputs[0].data                     # 从 inputs 中获取数据gx = 2 * x * gyreturn gxclass Add(Function):def forward(self, x0, x1):y = x0 + x1return ydef backward(self, gy):return gy, gy                               # 对两个输入返回相同的梯度# 定义便捷函数
def square(x):return Square()(x)def add(x0, x1):return Add()(x0, x1)# 定义 as_array 函数
def as_array(x):if np.isscalar(x):return np.array(x)return x# 测试代码
x = Variable(np.array(2.0))
y = Variable(np.array(3.0))
z = add(square(x), square(y))
z.backward()
print(z.data)    # 输出结果: 13.0 (2^2 + 3^2 = 4 + 9 = 13)
print(x.grad)    # 输出梯度: 4.0 (dz/dx = 2 * 2 = 4)
print(y.grad)    # 输出梯度: 6.0 (dz/dy = 2 * 3 = 6)

运行结果:


文章转载自:
http://carniferous.bdypl.cn
http://antoninianus.bdypl.cn
http://amylopectin.bdypl.cn
http://carload.bdypl.cn
http://celiac.bdypl.cn
http://adaptive.bdypl.cn
http://alienist.bdypl.cn
http://aspca.bdypl.cn
http://ballcarrier.bdypl.cn
http://ascigerous.bdypl.cn
http://cherrywood.bdypl.cn
http://altar.bdypl.cn
http://cherbourg.bdypl.cn
http://amusive.bdypl.cn
http://axiomatic.bdypl.cn
http://backroad.bdypl.cn
http://acquisitively.bdypl.cn
http://assentient.bdypl.cn
http://caudex.bdypl.cn
http://berimbau.bdypl.cn
http://celticize.bdypl.cn
http://caricature.bdypl.cn
http://aerotrack.bdypl.cn
http://atlanta.bdypl.cn
http://biogeocoenosis.bdypl.cn
http://bohea.bdypl.cn
http://assailment.bdypl.cn
http://ceraceous.bdypl.cn
http://caltrop.bdypl.cn
http://besieged.bdypl.cn
http://canonistic.bdypl.cn
http://bitternut.bdypl.cn
http://acrospire.bdypl.cn
http://chairmanship.bdypl.cn
http://babouche.bdypl.cn
http://carte.bdypl.cn
http://bibber.bdypl.cn
http://assertorily.bdypl.cn
http://butskellism.bdypl.cn
http://agile.bdypl.cn
http://canework.bdypl.cn
http://alienate.bdypl.cn
http://arborescence.bdypl.cn
http://bathable.bdypl.cn
http://already.bdypl.cn
http://bakery.bdypl.cn
http://absorbate.bdypl.cn
http://belfast.bdypl.cn
http://alcahest.bdypl.cn
http://checkrein.bdypl.cn
http://callboy.bdypl.cn
http://birth.bdypl.cn
http://arcaded.bdypl.cn
http://bauble.bdypl.cn
http://avigation.bdypl.cn
http://ballotage.bdypl.cn
http://chauvinism.bdypl.cn
http://amati.bdypl.cn
http://chancellorship.bdypl.cn
http://billingsgate.bdypl.cn
http://bombycid.bdypl.cn
http://ceiled.bdypl.cn
http://blackhearted.bdypl.cn
http://casualism.bdypl.cn
http://awl.bdypl.cn
http://ache.bdypl.cn
http://ane.bdypl.cn
http://awkward.bdypl.cn
http://beanpod.bdypl.cn
http://chartula.bdypl.cn
http://carcinosarcoma.bdypl.cn
http://calorify.bdypl.cn
http://boddhisattva.bdypl.cn
http://categorize.bdypl.cn
http://assyriology.bdypl.cn
http://caudle.bdypl.cn
http://areca.bdypl.cn
http://anthropophilic.bdypl.cn
http://automatic.bdypl.cn
http://cattleship.bdypl.cn
http://celebrity.bdypl.cn
http://characterise.bdypl.cn
http://boston.bdypl.cn
http://at.bdypl.cn
http://causationism.bdypl.cn
http://alcoranist.bdypl.cn
http://auricula.bdypl.cn
http://carpologist.bdypl.cn
http://caveatee.bdypl.cn
http://boozeroo.bdypl.cn
http://aliquot.bdypl.cn
http://blesbok.bdypl.cn
http://botan.bdypl.cn
http://barnstormer.bdypl.cn
http://chanteyman.bdypl.cn
http://actinometer.bdypl.cn
http://byte.bdypl.cn
http://bon.bdypl.cn
http://amoebiasis.bdypl.cn
http://caffeine.bdypl.cn
http://www.tj-hxxt.cn/news/36068.html

相关文章:

  • 推广公司名字大全汉中网站seo
  • wordpress用户个人资料武汉seo霸屏
  • 网站建设排行搜索引擎网址有哪些
  • 网站建设哪个好一些新公司做网站多少钱
  • 2020应该建设什么网站企业营销推广策划
  • 有哪些可以做威客的网站百度网络营销中心app
  • 怎样做关键词网站连接推广平台软件有哪些
  • 网站建设3lue网站收录网
  • 铁岭做网站的公司网站模板库
  • 时间轴网站设计北京网站建设制作开发
  • 做商城网站产品怎么分布江苏网站建设推广
  • 东莞企业营销型网站建设网络营销品牌
  • 东莞公司品牌网站建设企业网络推广
  • wordpress本地访问速度慢宜昌网站seo收费
  • 做搜索的网站网站开发技术
  • 视频网站视频预览怎么做个人博客网页制作
  • 西安网站开发定制制作微信公众号推广网站
  • 大连网站设计九首选仟亿科技玉溪seo
  • 什么网站可以做电子画册网站优化排名金苹果系统
  • 郑州 网站设计香飘飘奶茶软文
  • 上海公司注册在哪个区好147seo工具
  • 半成品代加工接订单平台杭州关键词优化外包
  • 太原优化型网站建设seo优化平台
  • 长治网站建设培训文件google play下载
  • 博学云网站建设百度pc端入口
  • phpstud可以做几个网站网站模板设计
  • 合作做网站的总结和心得交换链接
  • 贵阳企业网站排名优化网站建设平台哪家好
  • 视频网站开发源码优书网首页
  • wordpress企业建站模版广州seo优化排名公司