首页 > 编程知识 正文

梯度下降法求极值,梯度下降法求最小值

时间:2023-05-04 15:30:55 阅读:170607 作者:3027

我试图在MATLAB上实现“静态梯度设计”。 我完全遵循算法,但得到了非常大的w(coffients )预测/拟合函数。 算法有错误吗? 随机梯度下降实无情的金毛/p

x=0:0.1:2*pi //X-axis

n=size(x,2 );

r=-0.2(0.4 ).*rand(n,1 ); //generatingrandomnoisetobeaddedtothesin (x ) function

t=Zeros(1,n );

for i=1:n

t(I )=sin ) x ) I ) ) r ) I; //adding the noise

结束

f=round(1rand ) 20,1 ) *n ); //generating random indexes

h=x(f ); //choosing random x points

k=t(f ); //chossing random y points

m=size(h,2 ); //length of the h vector

scatter(h,k,' Red ' ); //drawingthetrainingpoints (with noise ) )。

%scatter(x,t,2 );

保持打开;

plot(x,sin ) x ); //plotting the Sin function

a=0.05; //learning rate 'alpha '

//------------- algorithm-------/

for i=1:20

v=[1h(I ) h ) I ).^2]; //X vector

e=() w*v ) )-k ) I ) ) . //prediction - observation

结束

保持打开;

l=0:1:6;

g=w(1) w )2) Lw )3) ) *(l.^2;

plot(L,g,' Yellow ' ); //drawing the prediction function

2011-02-25

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