|||
for k=0:n-1
ak=a/(k+1+A)^alpha;
ck=c/(k+1)^gamma;
delta=2*round(rand(p,1))-1;
thetaplus=theta+ck*delta;
thetaminus=theta-ck*delta;
yplus=loss(thetaplus);
yminus=loss(thetaminus);
ghat=(yplus-yminus)./(2*ck*delta);
theta=theta-ak*ghat;
end
theta
If maximum and minimum values on the values of
theta can be specified, say thetamax and
thetamin, then the following two lines can be
added below the theta update line to impose the
constraints
theta=min(theta,thetamax);
theta=max(theta,thetamin);
对于学习SPSA算法的初学者来讲非常有用。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-19 12:18
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社