From: Benjamin Auder Date: Sun, 2 Apr 2017 09:11:35 +0000 (+0200) Subject: Fix errors in EMGLLF.c :) X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/favicon.png%27%29%20%7D%7D?a=commitdiff_plain;h=435cb8419ebcdb624aa053f351c981133d58d6b6;p=valse.git Fix errors in EMGLLF.c :) --- diff --git a/pkg/src/sources/EMGLLF.c b/pkg/src/sources/EMGLLF.c index 7ce6ded..520d57b 100644 --- a/pkg/src/sources/EMGLLF.c +++ b/pkg/src/sources/EMGLLF.c @@ -77,7 +77,7 @@ void EMGLLF_core( { //Y2[,mm,r] = sqrt(gam[,r]) * Y[,mm] for (int u=0; u + //< X2[i,,r] , phi[,mm,r] > Real dotProduct = 0.; for (int u=0; u n*lambda*pow_pir_gamma) + //S[j,mm,r] = -rho[mm,mm,r]*ps2[j,mm,r] + sum(phi[-j,mm,r] * Gram2[j,-j,r]) + S[ai(j,mm,r,p,m,k)] = -rho[ai(mm,mm,r,m,m,k)] * ps2[ai(j,mm,r,p,m,k)] + phiDotGram2; + Real pirPowGamma = pow(pi[r],gamma); + if (fabs(S[ai(j,mm,r,p,m,k)]) <= n*lambda*pirPowGamma) + phi[ai(j,mm,r,p,m,k)] = 0.; + else if (S[ai(j,mm,r,p,m,k)] > n*lambda*pirPowGamma) { - phi[ai(j,mm,r,p,m,k)] = (n*lambda*pow_pir_gamma - S[ai(j,mm,r,p,m,k)]) + phi[ai(j,mm,r,p,m,k)] = (n*lambda*pirPowGamma - 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_pir_gamma + S[ai(j,mm,r,p,m,k)]) + phi[ai(j,mm,r,p,m,k)] = -(n*lambda*pirPowGamma + S[ai(j,mm,r,p,m,k)]) / Gram2[ai(j,j,r,p,p,k)]; } } @@ -281,7 +283,7 @@ void EMGLLF_core( YiRhoR[u] += Y[mi(i,v,n,m)] * rho[ai(v,u,r,m,m,k)]; } - //compute X(i,:)*phi(:,:,r) + //compute X[i,]%*%phi[,,r] for (int u=0; u1) sum(phi[1:(j-1),mm,r] * Gram2[j,1:(j-1),r]) else 0) + -# (if(j n*lambda*(pi[r]^gamma)) phi[j,mm,r] = (n*lambda*(pi[r]^gamma)-S[j,mm,r]) / Gram2[j,j,r] @@ -124,16 +122,14 @@ EMGLLF_R = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,ta { #precompute sq norms to numerically adjust their values sqNorm2 = rep(0,k) - for (r in 1:k){ - sqNorm2[r] = sum( (Y[i,]%*%rho[,,r]-X[i,]%*%phi[,,r])^2 )} + for (r in 1:k) + sqNorm2[r] = sum( (Y[i,]%*%rho[,,r]-X[i,]%*%phi[,,r])^2 ) - #compute Gam(:,:) + #compute Gam[,] sumLLF1 = 0.0; for (r in 1:k) { - #FIXME: numerical problems, because 0 < det(Rho[,,r] < EPS; what to do ?! - # consequence: error in while() at line 77 - Gam[i,r] = pi[r] * exp(-0.5*sqNorm2[r])* det(rho[,,r]) + Gam[i,r] = pi[r] * exp(-0.5*sqNorm2[r]) * det(rho[,,r]) sumLLF1 = sumLLF1 + Gam[i,r] / (2*base::pi)^(m/2) } sumLogLLF2 = sumLogLLF2 + log(sumLLF1) @@ -146,9 +142,7 @@ EMGLLF_R = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,ta sumPen = sum(pi^gamma * b) LLF[ite] = -sumLogLLF2/n + lambda*sumPen - dist = ifelse( ite == 1, LLF[ite], (LLF[ite]-LLF[ite-1]) / (1+abs(LLF[ite])) ) - Dist1 = max( (abs(phi-Phi)) / (1+abs(phi)) ) Dist2 = max( (abs(rho-Rho)) / (1+abs(rho)) ) Dist3 = max( (abs(pi-Pi)) / (1+abs(Pi)) )