Commit | Line | Data |
---|---|---|
0f51ccae BA |
1 | function[A1,A2,Rho,Pi] = selectiontotale(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau) |
2 | ||
3 | [p,m,k] = size(phiInit); | |
4 | L = length(glambda); | |
5 | A1 = zeros(p,m+1,L,'int64'); | |
6 | A2 = zeros(p,m+1,L,'int64'); | |
7 | Rho = zeros(m,m,k,L); | |
8 | Pi = zeros(k,L); | |
9 | ||
10 | %Pour chaque lambda de la grille, on calcule les coefficients | |
11 | for lambdaIndex=1:L | |
12 | [phi,rho,pi,~,~] = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda(lambdaIndex),X,Y,tau); | |
13 | ||
14 | %Si un des coefficients est supérieur au seuil, on garde cette variable | |
15 | selectedVariables = zeros(p,m); | |
16 | discardedVariables = zeros(p,m); | |
17 | atLeastOneSelectedVariable = false; | |
18 | for j=1:p | |
19 | cpt=1; | |
20 | cpt2=1; | |
21 | for mm=1:m | |
22 | if max(abs(phi(j,mm,:))) > seuil | |
23 | selectedVariables(j,cpt) = mm; | |
24 | cpt = cpt+1; | |
25 | atLeastOneSelectedVariable = true; | |
26 | else | |
27 | discardedVariables(j,cpt2) = mm; | |
28 | cpt2 = cpt2+1; | |
29 | end | |
30 | end | |
31 | end | |
32 | ||
33 | %Si aucun des coefficients n'a été gardé on renvoit la matrice nulle | |
34 | %Et si on enlevait ces colonnes de zéro ??? Indices des colonnes vides | |
35 | if atLeastOneSelectedVariable | |
36 | vec = []; | |
37 | for j=1:p | |
38 | if selectedVariables(j,1) ~= 0 | |
39 | vec = [vec;j]; | |
40 | end | |
41 | end | |
42 | ||
43 | %Sinon on renvoit les numéros des coefficients utiles | |
44 | A1(:,1,lambdaIndex) = [vec;zeros(p-length(vec),1)]; | |
45 | A1(1:length(vec),2:m+1,lambdaIndex) = selectedVariables(vec,:); | |
46 | A2(:,1,lambdaIndex) = 1:p; | |
47 | A2(:,2:m+1,lambdaIndex) = discardedVariables; | |
48 | Rho(:,:,:,lambdaIndex) = rho; | |
49 | Pi(:,lambdaIndex) = pi; | |
50 | end | |
51 | ||
52 | end | |
53 | ||
54 | end |