我的梯度下降算法有什么问题

大家好,我正在尝试为一个函数实现梯度下降算法:

enter image description here

我的算法起始点是 w = (u,v) = (2,2)。学习率 eta = 0.01,界限 bound = 10^-14。以下是我的MATLAB代码:

function [resultTable, boundIter] = gradientDescent(w, iters, bound, eta)% FUNCTION [resultTable, boundIter] = gradientDescent(w, its, bound, eta)% % DESCRIPTION: % - This function will do gradient descent error minimization for the% function E(u,v) = (u*exp(v) - 2*v*exp(-u))^2.%% INPUTS: % 'w' a 1-by-2 vector indicating initial weights w = [u,v]% 'its' a positive integer indicating the number of gradient descent% iterations% 'bound' a real number indicating an error lower bound% 'eta' a positive real number indicating the learning rate of GD algorithm%% OUTPUTS: % 'resultTable' a iters+1-by-6 table indicating the error, partial% derivatives and weights for each GD iteration% 'boundIter' a positive integer specifying the GD iteration when the error% function got below the given error bound 'bound'% % The error function E = @(u,v) (u*exp(v) - 2*v*exp(-u))^2;% Partial derivative of E with respect to u pEpu = @(u,v) 2*(u*exp(v) - 2*v*exp(-u))*(exp(v) + 2*v*exp(-u));% Partial derivative of E with respect to v pEpv = @(u,v) 2*(u*exp(v) - 2*v*exp(-u))*(u*exp(v) - 2*exp(-u));% Initialize boundIterboundIter = 0;% Create a table for holding the resultsresultTable = zeros(iters+1, 6);% Iteration numberresultTable(1, 1) = 0;% Error at iteration iresultTable(1, 2) = E(w(1), w(2));% The value of pEpu at initial w = (u,v)resultTable(1, 3) = pEpu(w(1), w(2));% The value of pEpv at initial w = (u,v)resultTable(1, 4) = pEpv(w(1), w(2));% Initial uresultTable(1, 5) = w(1);% Initial vresultTable(1, 6) = w(2);% Loop all the iterationsfor i = 2:iters+1    % Save the iteration number    resultTable(i, 1) = i-1;     % Update the weights    temp1 = w(1) - eta*(pEpu(w(1), w(2)));    temp2 = w(2) - eta*(pEpv(w(1), w(2)));    w(1) = temp1;    w(2) = temp2;    % Evaluate the error function at new weights    resultTable(i, 2) = E(w(1), w(2));    % Evaluate pEpu at the new point     resultTable(i, 3) = pEpu(w(1), w(2));    % Evaluate pEpv at the new point    resultTable(i, 4) = pEpv(w(1), w(2));    % Save the new weights    resultTable(i, 5) = w(1);    resultTable(i, 6) = w(2);    % If the error function is below a specified bound save this iteration    % index    if E(w(1), w(2)) < bound        boundIter = i-1;    endend

这是我机器学习课程中的一个练习,但不知为何我的结果全部错误。代码中肯定有问题。我已经尝试了多次调试但没有发现任何问题…有人能帮我找出问题所在吗?…换句话说,你能检查一下这段代码是否是给定函数的有效梯度下降算法吗?

如果我的问题不够清楚或你需要更多信息,请告诉我:)

感谢你的努力和帮助!=)

这是我五次迭代的结果以及其他人得到的结果:

参数:w = [2,2],eta = 0.01,bound = 10^-14,iters = 5

enter image description here


回答:

如问题下方所讨论:我认为其他人是错的…你的最小化导致了更小的E(u,v)值,检查一下:

E(1.4,1.6) = 37.8 >> 3.6 = E(0.63, -1.67)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注