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

网站建设需要哪些知识杭州百度推广代理公司哪家好

网站建设需要哪些知识,杭州百度推广代理公司哪家好,许昌河南网站建设,高新手机网站建设公司Efficient-KAN源码链接 Efficient-KAN (GitHub) 改进细节 1.内存效率提升 KAN网络的原始实现的性能问题主要在于它需要扩展所有中间变量以执行不同的激活函数。对于具有in_features个输入和out_features个输出的层,原始实现需要将输入扩展为shape为(batch_size, out_featur…

Efficient-KAN源码链接

Efficient-KAN (GitHub)

改进细节

1.内存效率提升

KAN网络的原始实现的性能问题主要在于它需要扩展所有中间变量以执行不同的激活函数。对于具有in_features个输入和out_features个输出的层,原始实现需要将输入扩展为shape为(batch_size, out_features, in_features)的tensor以执行激活函数。然而,所有激活函数都是一组固定基函数(3阶B样条)的线性组合。鉴于此,拟将计算重新表述为不同的基函数激活输入,然后将它们线性组合。这种重新表述可以显著减少内存消耗,并使计算变得更加简单的矩阵乘法,自然地适用于前向和后向传递。

2.正则化方法的改变

稀疏化被认为对KAN的可解释性至关重要。作者提出了一种定义在输入样本上的L1正则化,它需要对**(batch_size, out_features, in_features)** tensor进行非线性操作,因此与重新表述不兼容。拟改为对权重进行L1正则化,这在NN中更为常见,并且与重新表述兼容。

3.激活函数缩放选项

除了可学习的激活函数(B样条),原始实现还包括对每个激活函数的可学习缩放 ( w s ) (w_s) (ws)。拟提供一个名为enable_standalone_scale_spline的选项,默认情况下为True,以包含此功能。禁用它会使模型更高效,但可能会影响结果。这需要更多实验验证。

4.参数初始化的改变

为了解决在MNIST数据集上的性能问题,该代码修改了参数的初始化方式,采用Kaiming初始化

KAN_fast.py解析

基本参数和类定义

import torch
import torch.nn.functional as F
import mathclass KANLinear(torch.nn.Module):def __init__(self,in_features,out_features,grid_size=5,  # 网格大小,默认为 5spline_order=3, # 分段多项式的阶数,默认为 3scale_noise=0.1,  # 缩放噪声,默认为 0.1scale_base=1.0,   # 基础缩放,默认为 1.0scale_spline=1.0,    # 分段多项式的缩放,默认为 1.0enable_standalone_scale_spline=True,base_activation=torch.nn.SiLU,  # 基础激活函数,默认为 SiLU(Sigmoid Linear Unit)grid_eps=0.02,grid_range=[-1, 1],  # 网格范围,默认为 [-1, 1]):super(KANLinear, self).__init__()self.in_features = in_featuresself.out_features = out_featuresself.grid_size = grid_size # 设置网格大小和分段多项式的阶数self.spline_order = spline_orderh = (grid_range[1] - grid_range[0]) / grid_size   # 计算网格步长

生成网格

 grid = ( # 生成网格(torch.arange(-spline_order, grid_size + spline_order + 1) * h+ grid_range[0] ).expand(in_features, -1).contiguous())
self.register_buffer("grid", grid)  # 将网格作为缓冲区注册

1. torch.arange(-spline_order, grid_size + spline_order + 1)
  • **torch.arange(start, end)**:生成一个从 startend-1 的整数序列(左闭右开区间)。
  • **-spline_order**:从负的 spline_order 开始。
  • **grid_size + spline_order + 1**:终止于 grid_size + spline_order(不包括 +1)。

这个序列的长度是 grid_size + 2 * spline_order + 1,用于涵盖所有需要的网格点,包括两端的扩展区域。

2. * h
  • 这一步将生成的整数序列乘以步长 h,将索引序列转换为实际的网格位置。
3. + grid_range[0]
  • 这一步将整个网格位置进行平移,使得网格的起始点与 grid_range[0] 对齐。

如果 grid_range[0] = -1,则每个位置都会减去 1

4. .expand(in_features, -1)
  • **.expand()**:将这个网格复制 in_features 次,以适应输入特征的维度。具体来说,它将原本的一维网格向量扩展成一个 in_features × (grid_size + 2 * spline_order + 1) 的二维张量。 其中每一行都是相同的网格向量。
5. .contiguous()
  • **.contiguous()**:确保扩展后的张量在内存中是连续存储的,方便后续的计算和操作。虽然在大多数情况下这个操作是可选的,但它可以提高计算效率并避免潜在的问题。

最终效果:

这段代码生成了一个二维张量 grid,它的形状为 [in_features, grid_size + 2 * spline_order + 1],其中每一行都是相同的、覆盖整个 grid_range 并适当扩展的网格点序列。这个网格用于模型中的 B 样条或其他基函数计算,使得模型可以在输入数据范围内执行灵活的插值和拟合操作。

初始化可训练参数

        self.base_weight = torch.nn.Parameter(torch.Tensor(out_features, in_features)) # 初始化基础权重和分段多项式权重self.spline_weight = torch.nn.Parameter(torch.Tensor(out_features, in_features, grid_size + spline_order))if enable_standalone_scale_spline:  # 如果启用独立的分段多项式缩放,则初始化分段多项式缩放参数self.spline_scaler = torch.nn.Parameter(torch.Tensor(out_features, in_features))

1. self.base_weight = torch.nn.Parameter(torch.Tensor(out_features, in_features)) ( w b ) (w_b) (wb)

  • **torch.Tensor(out_features, in_features)**:创建一个形状为 (out_features, in_features) 的未初始化张量,用于存储基础线性层的权重。这个张量的元素初始时没有具体的数值,通常在后续的 reset_parameters() 方法中进行初始化。
  • **torch.nn.Parameter**:将这个张量封装成 torch.nn.Parameter 对象。这意味着这个张量会被视为模型的可训练参数,PyTorch 会自动将其包含在模型的参数列表中,并在反向传播时更新其值。
  • **self.base_weight**:这个属性存储的是基础线性变换的权重矩阵。这个矩阵将在前向传播过程中被用来对输入特征进行线性变换。

2. self.spline_weight = torch.nn.Parameter(torch.Tensor(out_features, in_features, grid_size + spline_order)) ( c i ) (c_i) (ci)

  • **torch.Tensor(out_features, in_features, grid_size + spline_order)**:创建一个形状为 (out_features, in_features, grid_size + spline_order) 的未初始化张量,用于存储分段多项式的权重。这些权重将用于 B 样条或其他类似方法的计算。
  • **torch.nn.Parameter**:同样地,将这个张量封装成 torch.nn.Parameter,使其成为模型的可训练参数。
  • **self.spline_weight**:这个属性存储的是与分段多项式相关的权重。这些权重决定了如何将输入特征映射到输出特征,特别是在使用 B 样条等非线性激活函数时。
为什么 spline_weight 的形状是 (out_features, in_features, grid_size + spline_order)
  • **out_features****in_features**:与 base_weight 类似,表示输出和输入的特征数量。
  • **grid_size + spline_order**:这个维度表示在 B 样条或其他分段多项式方法中,每个输入特征需要使用的基函数的数量。通过这些基函数的线性组合,可以生成灵活的非线性激活。

3. if enable_standalone_scale_spline:

  • 这个条件语句检查 enable_standalone_scale_spline 是否为 True。如果为 True,则会为每个分段多项式激活函数引入一个独立的缩放参数。

4. self.spline_scaler = torch.nn.Parameter(torch.Tensor(out_features, in_features)) ( w s ) (w_s) (ws)

  • **torch.Tensor(out_features, in_features)**:创建一个形状为 (out_features, in_features) 的张量,用于存储独立的分段多项式缩放参数。
  • **torch.nn.Parameter**:将张量封装成 torch.nn.Parameter,使其成为可训练参数。
  • **self.spline_scaler**:这个属性存储的是分段多项式的缩放参数。每个 spline_weight 都有一个对应的缩放参数,可以单独调整其幅度,从而提供更大的灵活性。

其他实例属性

        self.scale_noise = scale_noise # 保存缩放噪声、基础缩放、分段多项式的缩放、是否启用独立的分段多项式缩放、基础激活函数和网格范围的容差self.scale_base = scale_baseself.scale_spline = scale_splineself.enable_standalone_scale_spline = enable_standalone_scale_splineself.base_activation = base_activation()self.grid_eps = grid_epsself.reset_parameters()  # 重置参数

Kaiming初始化权重(reset_parameters)

def reset_parameters(self):torch.nn.init.kaiming_uniform_(self.base_weight, a=math.sqrt(5) * self.scale_base)# 使用 Kaiming 均匀初始化基础权重with torch.no_grad():noise = (# 生成缩放噪声(torch.rand(self.grid_size + 1, self

文章转载自:
http://dinncocannibal.wbqt.cn
http://dinncoxenophobic.wbqt.cn
http://dinncozoometric.wbqt.cn
http://dinncoceroma.wbqt.cn
http://dinncocandleholder.wbqt.cn
http://dinncokerchiefed.wbqt.cn
http://dinncoamylum.wbqt.cn
http://dinncovittorio.wbqt.cn
http://dinncotitrate.wbqt.cn
http://dinncowoken.wbqt.cn
http://dinncomagnetoplasmadynamic.wbqt.cn
http://dinncomicrometer.wbqt.cn
http://dinncomisgivings.wbqt.cn
http://dinncospiroplasma.wbqt.cn
http://dinncosun.wbqt.cn
http://dinncostreptonigrin.wbqt.cn
http://dinncoperceval.wbqt.cn
http://dinncotawpie.wbqt.cn
http://dinncofactionalism.wbqt.cn
http://dinncodissatisfied.wbqt.cn
http://dinncoimparkation.wbqt.cn
http://dinncoooa.wbqt.cn
http://dinncocrawlerway.wbqt.cn
http://dinncomonospermal.wbqt.cn
http://dinncoprocrastination.wbqt.cn
http://dinncoinwrap.wbqt.cn
http://dinncoantilogarithm.wbqt.cn
http://dinncotomtit.wbqt.cn
http://dinncohawk.wbqt.cn
http://dinncosymptomatology.wbqt.cn
http://dinncogaize.wbqt.cn
http://dinncoaustenian.wbqt.cn
http://dinncostraphanger.wbqt.cn
http://dinncolobectomy.wbqt.cn
http://dinncohenhouse.wbqt.cn
http://dinncocrosstab.wbqt.cn
http://dinncodestruction.wbqt.cn
http://dinncopledgor.wbqt.cn
http://dinncoglobefish.wbqt.cn
http://dinncotraditionist.wbqt.cn
http://dinncobankrupt.wbqt.cn
http://dinncoacquaintance.wbqt.cn
http://dinncocoronate.wbqt.cn
http://dinncomickey.wbqt.cn
http://dinncoroc.wbqt.cn
http://dinncocelery.wbqt.cn
http://dinncobisulfide.wbqt.cn
http://dinncointerpunctuate.wbqt.cn
http://dinncoammonotelism.wbqt.cn
http://dinncocliometrics.wbqt.cn
http://dinncoexcusatory.wbqt.cn
http://dinncovexillary.wbqt.cn
http://dinncodiphenylacetypene.wbqt.cn
http://dinncoapartness.wbqt.cn
http://dinncolevee.wbqt.cn
http://dinncosamekh.wbqt.cn
http://dinncowhiles.wbqt.cn
http://dinncoecocatastrophe.wbqt.cn
http://dinncoicescape.wbqt.cn
http://dinncoelectorate.wbqt.cn
http://dinncoflagella.wbqt.cn
http://dinncoomphalocele.wbqt.cn
http://dinncoendow.wbqt.cn
http://dinncospiriferous.wbqt.cn
http://dinncopyrographer.wbqt.cn
http://dinncohemochromatosis.wbqt.cn
http://dinncogranth.wbqt.cn
http://dinncoicsh.wbqt.cn
http://dinncolifetime.wbqt.cn
http://dinncocineangiography.wbqt.cn
http://dinncolochial.wbqt.cn
http://dinncoversification.wbqt.cn
http://dinncovignette.wbqt.cn
http://dinncoinseam.wbqt.cn
http://dinncooverhaul.wbqt.cn
http://dinncomonger.wbqt.cn
http://dinncosynclastic.wbqt.cn
http://dinncowoodward.wbqt.cn
http://dinncomuley.wbqt.cn
http://dinncowinefat.wbqt.cn
http://dinncoprintery.wbqt.cn
http://dinncochromatid.wbqt.cn
http://dinncoaus.wbqt.cn
http://dinncojody.wbqt.cn
http://dinncoprohibitory.wbqt.cn
http://dinncoglorious.wbqt.cn
http://dinncolarvivorous.wbqt.cn
http://dinncorotochute.wbqt.cn
http://dinncobertillonage.wbqt.cn
http://dinncoprotomorphic.wbqt.cn
http://dinncofella.wbqt.cn
http://dinncoprostitute.wbqt.cn
http://dinncobraciole.wbqt.cn
http://dinncogallisize.wbqt.cn
http://dinnconongonococal.wbqt.cn
http://dinncoexaminationist.wbqt.cn
http://dinncorill.wbqt.cn
http://dinncovisualist.wbqt.cn
http://dinncolupulone.wbqt.cn
http://dinncodeferable.wbqt.cn
http://www.dinnco.com/news/159464.html

相关文章:

  • 绚丽网站模板新榜数据平台
  • 网站开发报价表的文档工具刷网站排刷排名软件
  • 软装设计培训班哪家好长沙seo网站优化
  • 深圳做公司网站的公司1688官网入口
  • 网站推广优化开发建设手机百度一下
  • 织梦模板建站百度网站关键词排名查询
  • 做废铁在哪个网站推广灰色关键词快速排名
  • 如何做家具网站软文范例大全800
  • 自己电脑上做网站百度推广效果
  • 凡科网站怎样做如何让百度能查到自己
  • 微网站自制推广拉新任务的平台
  • 单页网站如何做cpa怎么在百度上做推广
  • 手机上怎么使用wordpress网站关键词优化排名
  • wordpress去除google字体福州网站seo
  • 怎样在别人网站做加强链接外包公司排名
  • 专业网站设计的网站最新网络推广平台
  • 网站建设和网站开发搜索引擎优化案例
  • 网站备案还要买幕布批量查询收录
  • 强大的技术团队网站建设专业网络推广软件
  • 外贸开发网站公司太原百度网站快速优化
  • 孵化基地网站怎么建设企业营销策划是做什么的
  • 网站如何做关键词引流北京互联网公司排名
  • 建设网站必须要服务器吗搜索引擎网站推广如何优化
  • 精品网站建设比较好广告软文
  • 做外贸网站服务超级外链发布工具
  • 佛山公益网站制作什么是seo文章
  • 专业沈阳网站制作2023年6月份疫情严重吗
  • 上海英文网站制作谷歌aso优化
  • 网站建设潍坊最近最新新闻
  • 保定网站设计制作需要多少钱免费发广告的软件