X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=R%2Fselectiontotale.m;fp=R%2Fselectiontotale.m;h=5d36a968afea2cc8be1e7bdc56de37534a9f659b;hp=0000000000000000000000000000000000000000;hb=31ef8a5c9bbaefcf40d2c2bad43b27d469c28c34;hpb=017063cd636a3678c3c74d809c3b89b2a49d11b1 diff --git a/R/selectiontotale.m b/R/selectiontotale.m new file mode 100644 index 0000000..5d36a96 --- /dev/null +++ b/R/selectiontotale.m @@ -0,0 +1,54 @@ +function[A1,A2,Rho,Pi] = selectiontotale(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau) + + [p,m,k] = size(phiInit); + L = length(glambda); + A1 = zeros(p,m+1,L,'int64'); + A2 = zeros(p,m+1,L,'int64'); + Rho = zeros(m,m,k,L); + Pi = zeros(k,L); + + %Pour chaque lambda de la grille, on calcule les coefficients + for lambdaIndex=1:L + [phi,rho,pi,~,~] = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda(lambdaIndex),X,Y,tau); + + %Si un des coefficients est supérieur au seuil, on garde cette variable + selectedVariables = zeros(p,m); + discardedVariables = zeros(p,m); + atLeastOneSelectedVariable = false; + for j=1:p + cpt=1; + cpt2=1; + for mm=1:m + if max(abs(phi(j,mm,:))) > seuil + selectedVariables(j,cpt) = mm; + cpt = cpt+1; + atLeastOneSelectedVariable = true; + else + discardedVariables(j,cpt2) = mm; + cpt2 = cpt2+1; + end + end + end + + %Si aucun des coefficients n'a été gardé on renvoit la matrice nulle + %Et si on enlevait ces colonnes de zéro ??? Indices des colonnes vides + if atLeastOneSelectedVariable + vec = []; + for j=1:p + if selectedVariables(j,1) ~= 0 + vec = [vec;j]; + end + end + + %Sinon on renvoit les numéros des coefficients utiles + A1(:,1,lambdaIndex) = [vec;zeros(p-length(vec),1)]; + A1(1:length(vec),2:m+1,lambdaIndex) = selectedVariables(vec,:); + A2(:,1,lambdaIndex) = 1:p; + A2(:,2:m+1,lambdaIndex) = discardedVariables; + Rho(:,:,:,lambdaIndex) = rho; + Pi(:,lambdaIndex) = pi; + end + + end + +end