问题描述
我完全不知道下一步该做什么。我的任务是 1) 改变假设函数,现在是 h(x) = t2x^2 + t1x + t0 2)并更改代码,以便绘制所有三个参数调整值。 这是我到目前为止所拥有的。现在我只需要将假设修改为 h(x) = t2x^2 + t1x + t0。
M = 100;
x = 5*randn(1,M)
y = x.^2 + 10*randn(1,M);
# Initial values for t0,t1 and t2
t1 = randn(1);
t0 = randn(1);
alkuarvaus_t1 = t1;
alkuarvaus_t0 = t0;
# recording parameters
adj_t1 = t1;
adj_t0 = t0;
# Thaching Rounds times
Rounds = 20;
rate = 0.001;
for I = 1:Rounds
grad_t1 = 0;
grad_t0 = 0;
for J = 1:M
grad_t1 = grad_t1 + (( t1*x(J) + t0) - y(J) ) * x(J);
grad_t0 = grad_t0 + ( t1*x(J) + t0) - y(J);
endfor
t1 = t1 - (rate/M)*grad_t1;
t0 = t0 - (rate/M)*grad_t0;
adj_t1 = [adj_t1 t1];
adj_t0 = [adj_t0 t0];
xakseli = -10:0.5:10;
hold on
figure(5);plot( xakseli,xakseli*t1 + t0,'-',x,y,'*');title('adjustment ongoing');
endfor
hold off
xakseli = -10:0.5:10;
yakseli = xakseli.*alkuarvaus_t1 + alkuarvaus_t0;
figure(1);plot( xakseli,yakseli,'*');title('hypotesis in the beginning');
figure(2);stem(adj_t1);
figure(3);stem(adj_t0);
figure(4);plot( xakseli,'*');title('hypotesis in the end');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)