reorganize test folder: tests generation with MATLAB almost OK (but suboptimal method)
[valse.git] / OLD_MATLAB / ProcLassoMLE / constructionModelesLassoMLE.m
CommitLineData
1d3c1faa
BA
1function[phi,rho,pi,lvraisemblance] = constructionModelesLassoMLE(...
2 phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,A1,A2)
3
4 PI = 4.0 * atan(1.0);
5
6 %get matrix sizes
7 n = size(X, 1);
8 [p,m,k] = size(phiInit);
9 L = length(glambda);
10
11 %output parameters
12 phi = zeros(p,m,k,L);
13 rho = zeros(m,m,k,L);
14 pi = zeros(k,L);
15 lvraisemblance = zeros(L,2);
16
17 for lambdaIndex=1:L
18 % Procedure Lasso-MLE
19 a = A1(:,1,lambdaIndex);
20 a(a==0) = [];
21 if length(a) == 0
22 continue;
23 end
24 [phiLambda,rhoLambda,piLambda,~,~] = EMGLLF(...
25 phiInit(a,:,:),rhoInit,piInit,gamInit,mini,maxi,gamma,0,X(:,a),Y,tau);
26
27 for j=1:length(a)
28 phi(a(j),:,:,lambdaIndex) = phiLambda(j,:,:);
29 end
30 rho(:,:,:,lambdaIndex) = rhoLambda;
31 pi(:,lambdaIndex) = piLambda;
32
33 dimension = 0;
34 for j=1:p
35 b = A2(j,2:end,lambdaIndex);
36 b(b==0) = [];
37 if length(b) > 0
38 phi(A2(j,1,lambdaIndex),b,:,lambdaIndex) = 0.0;
39 end
40 c = A1(j,2:end,lambdaIndex);
41 c(c==0) = [];
42 dimension = dimension + length(c);
43 end
44
45 %on veut calculer l'EMV avec toutes nos estimations
46 densite = zeros(n,L);
47 for i=1:n
48 for r=1:k
49 delta = Y(i,:)*rho(:,:,r,lambdaIndex) - (X(i,a)*(phi(a,:,r,lambdaIndex)));
50 densite(i,lambdaIndex) = densite(i,lambdaIndex) +...
51 pi(r,lambdaIndex)*det(rho(:,:,r,lambdaIndex))/(sqrt(2*PI))^m*exp(-dot(delta,delta)/2.0);
52 end
53 end
54 lvraisemblance(lambdaIndex,1) = sum(log(densite(:,lambdaIndex)));
55 lvraisemblance(lambdaIndex,2) = (dimension+m+1)*k-1;
56 end
57
58end