X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=src%2Fsources%2FEMGLLF.c;h=7e7a3d1d5938d22c607f20e18460a8c67d0b7c02;hp=87fd1997517296d47a02733011d40ac5963ad47d;hb=ef67d338c7f28ba041abe40ca9a8ab69f8365a90;hpb=c3bc47052f3ccb659659c59a82e9a99ea842398d diff --git a/src/sources/EMGLLF.c b/src/sources/EMGLLF.c index 87fd199..7e7a3d1 100644 --- a/src/sources/EMGLLF.c +++ b/src/sources/EMGLLF.c @@ -36,7 +36,6 @@ void EMGLLF_core( //S is already allocated, and doesn't need to be 'zeroed' //Other local variables - //NOTE: variables order is always [maxi],n,p,m,k Real* gam = (Real*)malloc(n*k*sizeof(Real)); copyArray(gamInit, gam, n*k); Real* b = (Real*)malloc(k*sizeof(Real)); @@ -54,6 +53,7 @@ void EMGLLF_core( Real* Gam = (Real*)malloc(n*k*sizeof(Real)); Real* X2 = (Real*)malloc(n*p*k*sizeof(Real)); Real* Y2 = (Real*)malloc(n*m*k*sizeof(Real)); + Real* sqNorm2 = (Real*)malloc(k*sizeof(Real)); gsl_matrix* matrix = gsl_matrix_alloc(m, m); gsl_permutation* permutation = gsl_permutation_alloc(m); Real* YiRhoR = (Real*)malloc(m*sizeof(Real)); @@ -61,8 +61,8 @@ void EMGLLF_core( Real dist = 0.; Real dist2 = 0.; int ite = 0; - Real EPS = 1e-15; - Real* dotProducts = (Real*)malloc(k*sizeof(Real)); + const Real EPS = 1e-15; + const Real gaussConstM = pow(2.*M_PI,m/2.); while (ite < mini || (ite < maxi && (dist >= tau || dist2 >= sqrt(tau)))) { @@ -75,19 +75,19 @@ void EMGLLF_core( { for (int mm=0; mm= 0) pi2AllPositive = 1; for (int r=0; r - Real dotProduct = 0.0; + Real dotProduct = 0.; for (int u=0; u1) sum(phi[1:(j-1),mm,r] * Gram2[j,1:(j-1),r]) else 0) + + // (if(j n*lambda*pow(pi[r],gamma)) - phi[ai(j,mm,r,p,m,k)] = (n*lambda*pow(pi[r],gamma) - S[ai(j,mm,r,p,m,k)]) + else if (S[ai(j,mm,r,p,m,k)] > n*lambda*pow_pir_gamma) + { + phi[ai(j,mm,r,p,m,k)] = (n*lambda*pow_pir_gamma - S[ai(j,mm,r,p,m,k)]) / Gram2[ai(j,j,r,p,p,k)]; + } else - phi[ai(j,mm,r,p,m,k)] = -(n*lambda*pow(pi[r],gamma) + S[ai(j,mm,r,p,m,k)]) + { + phi[ai(j,mm,r,p,m,k)] = -(n*lambda*pow_pir_gamma + S[ai(j,mm,r,p,m,k)]) / Gram2[ai(j,j,r,p,p,k)]; + } } } } @@ -265,18 +274,11 @@ void EMGLLF_core( Real sumLogLLF2 = 0.0; for (int i=0; i - dotProducts[r] = 0.0; + //compute sq norm || Y(:,i)*rho(:,:,r)-X(i,:)*phi(:,:,r) ||_2^2 + sqNorm2[r] = 0.0; for (int u=0; u EPS - ? Gam[mi(i,r,n,k)] / sumGamI - : 0.0; + //gam[i,] = Gam[i,] / sumGamI + gam[mi(i,r,n,k)] = sumGamI > EPS ? Gam[mi(i,r,n,k)] / sumGamI : 0.; } } - - //sum(pen(ite,:)) + + //sumPen = sum(pi^gamma * b) Real sumPen = 0.0; for (int r=0; r dist2) dist2 = Dist3; - + ite++; } - + //free memory free(b); free(gam); @@ -409,5 +409,5 @@ void EMGLLF_core( free(pi2); free(X2); free(Y2); - free(dotProducts); + free(sqNorm2); }