function [theta,x] =SPSA(x0,fun,a,c,alpha,gamma,A,n)
theta = x0;
p = length(x0);
for k = 0:n-1
ak = a/(k+1+A)^alpha;
ck = c/(k+1)^gamma;
delta = 2*round(rand(1,p))-1;
thetaplus = theta+ck*delta;
thetaminus = theta-ck*delta;
yplus = fun(thetaplus);
yminus = fun(thetaminus);
ghat = (yplus-yminus)./(2*ck*delta);
x(k+1,:) = theta';
theta = theta-ak*ghat;
end
%Notes:
%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);
%The MATLAB feval operation (not used above) is useful in
%yplus and yminus evaluations to allow for easy change of
%loss function.
%Algorithm initialization not shown above (see discussion
%in introduction to MATLAB code).
没有合适的资源?快使用搜索试试~ 我知道了~
SPSA Algorithm.rar
共5个文件
m:5个
5星 · 超过95%的资源 需积分: 50 30 下载量 103 浏览量
2020-10-13
16:45:20
上传
评论 3
收藏 2KB RAR 举报
温馨提示
提供了同步扰动随机近似优化算法(SPSA) 内部包含优化测试函数示例 可以直接点开运行,注释十分清晰
资源推荐
资源详情
资源评论
收起资源包目录
SPSA Algorithm.rar (5个子文件)
SPSA Algorithm
SPSA.m 906B
SPSAscript.m 895B
practice.m 376B
practice2.m 0B
fun.m 109B
共 5 条
- 1
JellyChen
- 粉丝: 3
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页