From: emilie Date: Thu, 16 Mar 2017 14:49:30 +0000 (+0100) Subject: update EMGLLF.R and some few details X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/store/%7B%7B?a=commitdiff_plain;h=f227455a1604906b255ef366d64c10a93e796983;p=valse.git update EMGLLF.R and some few details --- diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..91114bf --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,2 @@ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..6616dbe --- /dev/null +++ b/.Rhistory @@ -0,0 +1,512 @@ +lines(1:15, rep(0,15), col='red') +N = 300 +mugamma = c(1,2,3) +Gamma = matrix(c(5,-0.02,0.01,-0.02,1,0.1,0.01,0.1,1),3,3) +s2 = 0.01 +Si = getbasismatrix(seq(0,1,length=15),create.fourier.basis(nbasis = 3)) +gammai = t(sapply(1:N,FUN = function(i){ +rmvnorm(1,mugamma,Gamma) +})) +Xdata = t(sapply(1:N,FUN = function(i){ +as.vector(Si%*%gammai[i,])+rnorm(15,0,s2) +})) +matplot(t(Xdata),type="l") +#beta = c(.1,.5,-.3) +beta = c(1,-3.5,4.5,-2.5) +pydata = sapply(1:N,FUN=function(i){ +a = sum(beta*c(1,gammai[i,])) +return(exp(a)/(1+exp(a))) +}) +U = runif(length(pydata)) +ydata = as.numeric(U1) sum(phi[1:(j-1),mm,r] * Gram2[j,1:(j-1),r]) else 0) + - (if(j1) sum(phi[1:(j-1),mm,r] * Gram2[j,1:(j-1),r]) else 0) + +# (if(j n*lambda*(pi[r]^gamma)) @@ -128,9 +124,8 @@ EMGLLF = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,tau) { #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 ) - shift = 0.5*min(sqNorm2) + for (r in 1:k){ + sqNorm2[r] = sum( (Y[i,]%*%rho[,,r]-X[i,]%*%phi[,,r])^2 )} #compute Gam(:,:) using shift determined above sumLLF1 = 0.0; @@ -138,7 +133,7 @@ EMGLLF = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,tau) { #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] + shift) #* 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) @@ -161,6 +156,7 @@ EMGLLF = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,lambda,X,Y,tau) ite = ite+1 } - - return(list("phi"=phi, "rho"=rho, "pi"=pi, "LLF"=LLF, "S"=S)) + + affec = apply(gam, 1,which.max) + return(list("phi"=phi, "rho"=rho, "pi"=pi, "LLF"=LLF, "S"=S, "affec" = affec )) }