4 warnings mathematical-optimization octave
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
  m = length(y);
  J_history = zeros(num_iters, 1);
  for iter = 1:num_iters
    ## warning: product: automatic broadcasting operation applied
    theta = theta - sum(X .* (X * theta - y))' .* (alpha / (m .* 2));
    J_history(iter) = computeCost(X, y, theta);
  end
end
这是我的作业,但我不要求你为我做这件事(我实际上认为我已经做过或接近过).我在提到播放的地方已经红了,但是我还是不明白,为什么我在这里收到警告?
问题是,size(theta')是1 2和size(X)是m 2.
当你乘他们,八度开始乘以X(1,1)通过theta'(1,1)和X(1,2)通过theta'(1,2).然后移动到第二排X,并试图乘X(2,1)用theta'(2,1).但是theta'没有第二行所以操作毫无意义.
Octave不仅仅是崩溃,而是猜测你是想扩展theta'它以便它具有与X开始乘法之前一样多的行.但是,因为它在猜测某些东西,所以它应该警告你它正在做什么.
在使用repmat函数开始乘法之前,可以通过显式扩展theta的长度来避免警告.
repmat(theta',m,1) .* X
| 归档时间: | 
 | 
| 查看次数: | 9629 次 | 
| 最近记录: |