Machine learning 在倍频程中实现梯度下降的困难
我一直在尝试用八度音阶实现梯度下降。这是我目前掌握的代码:Machine learning 在倍频程中实现梯度下降的困难,machine-learning,octave,gradient-descent,Machine Learning,Octave,Gradient Descent,我一直在尝试用八度音阶实现梯度下降。这是我目前掌握的代码: function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) %GRADIENTDESCENT Performs gradient descent to learn theta % theta = GRADIENTDESCENT(X, y, theta, alpha, num_iters) updates theta by %
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
%GRADIENTDESCENT Performs gradient descent to learn theta
% theta = GRADIENTDESCENT(X, y, theta, alpha, num_iters) updates theta by
% taking num_iters gradient steps with learning rate alpha
% Initialize some useful values
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
for iter = 1:num_iters
% ====================== YOUR CODE HERE ======================
% Instructions: Perform a single gradient step on the parameter vector
% theta.
%
% Hint: While debugging, it can be useful to print out the values
% of the cost function (computeCost) and gradient here.
%
theta
X
y
theta' .* X
for inner = 1:length(theta)
hypothesis = (X * theta - y)';
% Updating the parameters
temp0 = theta(1) - (alpha * (1/m) * hypothesis * X(:, 1));
temp1 = theta(2) - (alpha * (1/m) * hypothesis * X(:, 2));
theta(1) = temp0;
theta(2) = temp1;
J_history(iter) = computeCost(X, y, theta);
end
end
我真的不知道这段代码出了什么问题,它编译并运行,但它是自动分级的,每次都失败
编辑:对不起,没有具体说明。我应该实现GD的一个步骤,而不是整个循环 编辑2:下面是全部内容。只有for循环中的内容与imo相关
编辑3:两个测试用例都失败了,所以我的计算有问题。我想我的问题是,出于某种原因,我在那里有一个额外的for循环。这个问题需要回答。不管怎样,你有数学问题的测试用例吗?一些简单的域/方程,你知道它的解吗?梯度下降是一个迭代过程,但我看这里没有循环…对不起,没有具体说明。我应该实现GD的一个步骤,循环已经预先编码到我正在处理的文件中。我有一个测试用例,但是它有97个不同的数据点,所以我认为我没有空间发布所有的测试用例。发布整个文件,包括预编码的东西。我们还可以如何重现这个问题?您能否创建一组应该工作但不更新的琐碎数据。你说得对karlphillip