首页 > 编程知识 正文

torch,pytorch lstm

时间:2023-05-06 01:14:50 阅读:125900 作者:3450

1 .原理1.1原论文

它最初应用于生成模型

《Wasserstein GAN》:https://arxiv.org/ABS/1701.07875

1.2全面介绍

3359砖局域网. zhi Hu.com/p/25071913

1.3好处

Wasserstein距离优于KL分集、JS分集的优点是,即使两个分布不重叠,Wasserstein距离也能反映距离。

2 .代码importtorchimporttorch.NNA snn # adapted from https://github.com/gp Eyre/sinkhornautodiffclasssinkhorndistance (3360 r ' ' giventwoempiricalmeasureseachwith : math : ` p _1` locations 3360 math math bb { r } ^ { d _1} ` and : math : ` p _2` locations 3360 math 3360 ` yinmath bb { r } ^ { d _2} `, outputsanapproximationoftheregularizedotcostforpointclouds.args : EPS (浮动) : regularizationcoefficientmax _ ITER 33365306; ions reduction (字符串, optional ) :特定型别ductiontoapplytotheoutput : ' none '|mean ' | sum '.' none ' : noreductionwillbeapps ' mean ' : thesumoftheoutputwillbedividedbythenumberofelementsintheoutputput, ' sum ' : theoutputwillbesummed.default : ' none ' shape :-input :3360 math : ` (n,P_1), D_1)、)、)、)、)、) )、)、D_2) `-output:math:`(n ) ` or :math: ` ()、depending on reduction='none ' ) :super(sinkhorndistance,self ).__init__ () self.EPS=EPSself.max_iter=max x y ) : # thesinkhornalgorithmtakesasinputthreevariables 3360 c=self._ cost _ matrix (x, y ).cuda (# wassersteincostfunctionx _ points=x.shape (-2 ) y_points=y.shape(-2 ) ifx.DIM ) ) ) ) bothmarginalsarefixedwithequalweightsmu=torch.empty dype=torch.float, requires_grad=False ).fill_(1.0/x_points ).squeeze(.cuda ) nu=torch.empty requires _ grad=false (. y_points ).squeeze ).cuda ) ) u=torch.zeros_like ) ) mu ) v=torch ocheckifalgorithmterminatesbecauseofthreshofthoreshorithd stoppingcriterionthresh=1e-1 # sinkhorniterationsforiinrange (self.max _ ITER ) : u1=u # usefultochecktheupdateu ) torch.log ) mu1e -Torch.Logsumexp(self.m(c,u,v ), dim=-1 ) ) uv=self.EPS* ) Torch.log(nu1e-8 )-Torch.Logsumexp dim=-1 () verr=(u-U1 ).abs ).sum v=v#transportplanpi=diag(a ) k*diag ) pi=torch.exp (self.m ) c、u、v ) ) sinkhorndistancecost=torch . v ) : ' modifiedcostforlogarithmicupdates ' ' $ m _ { ij }=(-c _ { ij } u _ iv _ j )/epsilon $ ' return (-Cu . self.EPS @ staticmethoddef _ cost _ matrix ) x,y p=2) : ' returnsthematrixof $|x _ I-y _ j|^ p $.' x _ -1) returnc@staticmethoddefave(u,u1,tau ) : 'Barycenter subroutine,usedbykineticaccelerationthroughextrapolatine

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。