資源簡介
用matlab實現(xiàn)softmax回歸

代碼片段和文件信息
function?numgrad?=?computeNumericalGradient(J?theta)
%?numgrad?=?computeNumericalGradient(J?theta)
%?theta:?a?vector?of?parameters
%?J:?a?function?that?outputs?a?real-number.?Calling?y?=?J(theta)?will?return?the
%?function?value?at?theta.?
??
%?Initialize?numgrad?with?zeros
numgrad?=?zeros(size(theta));
%%?----------?YOUR?CODE?HERE?--------------------------------------
%?Instructions:?
%?Implement?numerical?gradient?checking?and?return?the?result?in?numgrad.??
%?(See?Section?2.3?of?the?lecture?notes.)
%?You?should?write?code?so?that?numgrad(i)?is?(the?numerical?approximation?to)?the?
%?partial?derivative?of?J?with?respect?to?the?i-th?input?argument?evaluated?at?theta.??
%?I.e.?numgrad(i)?should?be?the?(approximately)?the?partial?derivative?of?J?with?
%?respect?to?theta(i).
%????????????????
%?Hint:?You?will?probably?want?to?compute?the?elements?of?numgrad?one?at?a?time.?
%?epsilon=0.0001;
%?n=size(theta1);
%?E=eye(n);
%?for?i=1:n
%?????delta=E(:i)*epsilon;
%?????numgrad(i)=(J(theta+delta)-J(theta-delta))/(epsilon*2.0);
%?end
epsilon?=?10^(-4);
n?=?size(theta?1);
J1?=?zeros(1?1);
J2?=?zeros(1?1);
grad?=?zeros(size(numgrad));
temp1?=?zeros(size(theta));
temp2?=?zeros(size(theta));
for?i?=?1?:?n
????temp1?=?theta;
????temp2?=?theta;
????temp1(i)?=?temp1(i)?+?epsilon;
????temp2(i)?=?temp2(i)?-?epsilon;
????[J1?grad]?=?J(temp1);
????[J2?grad]?=?J(temp2);
????numgrad(i)?=?(J1?-?J2)?/?(2*epsilon);
end
%%?---------------------------------------------------------------
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1510??2016-03-30?10:32??softmax分類(Matlab程序)\computeNumericalGradient.m
?????文件????????811??2014-03-25?21:18??softmax分類(Matlab程序)\loadMNISTImages.m
?????文件????????516??2011-04-25?17:32??softmax分類(Matlab程序)\loadMNISTLabels.m
?????文件???????3251??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\ArmijoBacktrack.m
?????文件????????807??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\autoGrad.m
?????文件????????901??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\autoHess.m
?????文件????????317??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\autoHv.m
?????文件????????870??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\autoTensor.m
?????文件????????385??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\callOutput.m
?????文件???????1845??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\conjGrad.m
?????文件????????995??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\dampedUpdate.m
?????文件???????2421??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\example_minFunc.m
?????文件???????1604??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\example_minFunc_LR.m
?????文件????????107??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\isLegal.m
?????文件????????924??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgs.m
?????文件???????2408??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.c
?????文件???????7707??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexa64
?????文件???????7733??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexglx
?????文件???????9500??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexmac
?????文件??????12660??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexmaci
?????文件???????8800??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexmaci64
?????文件???????7168??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexw32
?????文件???????9728??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsC.mexw64
?????文件????????614??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\lbfgsUpdate.m
?????文件????????417??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\LogisticDiagPrecond.m
?????文件????????216??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\LogisticHv.m
?????文件????????659??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\LogisticLoss.m
?????文件???????1154??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\mexutil.c
?????文件????????317??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\mexutil.h
?????文件????????227??2011-01-03?21:39??softmax分類(Matlab程序)\minFunc\logistic\mylogsumexp.m
............此處省略33個文件信息
評論
共有 條評論