Home > other >  Is there a big help to look at the younger brother of the code (Lars_lasso matlab have a problem)
Is there a big help to look at the younger brother of the code (Lars_lasso matlab have a problem)

Time:10-16

 function x=LARS (y, D, N) 
[nd, md]=size (D);
X=zeros (md, 1);

D=ones (md, 1);
For I=1: md
D (I)=norm (d (: I));
If d (I) & gt; 0
D (:, I)=D (: I)/D (I);
The else
D (I)=1;
End
End

ActiveSet=zeros (N, 1);
S=zeros (md, 1);
Flags=zeros (md, 1);

C=D '* y;
Absc=abs (c);
[C, j]=Max (absc);
Nj=1;
ActiveSet (nj)=j;
S (j)=sign (j) (c);
Flags (j)=1;

For I=1: N
If nj==0
Break
End
Xa=ones (nd, 1) * s (activeSet (1: nj)) '. * D (:, activeSet (1: nj));
The Ga=Xa '* Xa;
E=ones (nj, 1);
Aa=(e '/Ga * e) ^ 0.5;
W=Aa * Ga \ e;
A=D '* Xa * w;

Rs=zeros (2 * md, 1);
For g=1: md
If (flags (g)==1)
continue;
End
Rs (2 * g - 1)=(C - C (g))/(Aa - a (g));
Rs (2 * g)=(C + C (g))/(Aa + a (g));
End
R=min (rs (rs> 0));
If isempty (r)
Break
End
J=find (rs==r, 1);
J=floor ((j + 1)/2);
Wa=zeros (md, 1);
Wa (activeSet (1: nj))=s (activeSet (1: nj)). * w;
Rj=x./wa;
Rh=min (rj (rj> 0));
If (~ isempty (rh) & amp; & Rh<=r)
C=C - rh * Aa;
Jj=find (rj==rh, 1);
X=x + rh * wa;
Flags (jj)=0;
Jj=find (activeSet==jj);
ActiveSet: [jj nj - 1)=activeSet (jj + 1: nj);
Nj=nj - 1;
The else
If (r * Aa & lt; 1-8 e)
Break
End
C=C - r * Aa;
X=x + r * wa;
Nj=nj + 1;
ActiveSet (nj)=j;
Flags (j)=1;
End
C=D * (y - D * x).
S (j)=sign (j) (c);

D1=norm (y - D * x);
If (C<1-6 e | | d1 & lt; 1 e - 6)
Break
End

End

X=x./d;


CodePudding user response:

Again some of the data, d1 decreases first, the value of x would suddenly become bigger, so I added a
If (r * Aa & lt; 1-8 e)
Break
End
But the effect is not very good,

CodePudding user response:

Help! The top
  • Related