資源簡介
介紹了共軛梯度法,包含程序以及與其他學習方法的比較。
代碼片段和文件信息
x?=?load(‘ex3x.dat‘);??????
y?=?load(‘ex3y.dat‘);??????
??????
trustRegionBound?=?1000;??????
x?=?[ones(size(x1)1)?x];??????
meanx?=?mean(x);%求均值??????
sigmax?=?std(x);%求標準偏差??????
x(:2)?=?(x(:2)-meanx(2))./sigmax(2);??????
x(:3)?=?(x(:3)-meanx(3))./sigmax(3);??????
itera_num?=?1000;?%嘗試的迭代次數??????
sample_num?=?size(x1);?%訓練樣本的次數??????
jj=0.00001;??
figure??????
alpha?=?[0.03?0.1?1];%因為差不多是選取每個3倍的學習率來測試,所以直接枚舉出來??????
plotstyle?=?{‘b‘?‘r‘?‘g‘};???????
theta_grad_descent?=?zeros(size(x(1:)));
plotstyle1?=?{‘y-‘?‘k-‘?‘c-‘‘g--‘‘r-‘};?
%%?CG方法
for?ii=1:5
theta?=?zeros(size(x2)1);?%theta的初始值賦值為0??????
Jtheta?=?zeros(itera_num?1);??
Jtheta(1)?=?(1/(2*sample_num)).*(x*theta-y)‘*(x*theta-y);??
grad1=(1/sample_num).*x‘*(x*theta-y);??
Q=x‘*x;
d1=-grad1;
- 上一篇:圖像紋理分析灰度共生矩陣matlab源碼
- 下一篇:蜂群算法matlab
評論
共有 條評論