4 covY = array(dim = c(5,5,2))
5 covY[,,1] = 0.1*diag(5)
6 covY[,,2] = 0.2*diag(5)
8 beta = array(dim = c(6,5,2))
9 beta[,,2] = matrix(c(rep(2,12),rep(0, 18)))
10 beta[,,1] = matrix(c(rep(1,12),rep(0, 18)))
16 source('~/valse/R/generateSampleInputs.R')
17 data = generateXY(meanX,covX,covY, pi, beta, n)
28 Zinit1 = array(0, dim=c(n))
29 betaInit1 = array(0, dim=c(p,m,k))
30 sigmaInit1 = array(0, dim = c(m,m,k))
31 phiInit1 = array(0, dim = c(p,m,k))
32 rhoInit1 = array(0, dim = c(m,m,k))
35 gamInit1 = array(0, dim=c(n,k))
38 require(MASS) #Moore-Penrose generalized inverse of matrix
40 distance_clus = dist(X)
41 tree_hier = hclust(distance_clus)
42 Zinit1 = cutree(tree_hier, k)
48 Z_indice = seq_len(n)[Z == r] #renvoit les indices où Z==r
49 if (length(Z_indice) == 1) {
50 betaInit1[,,r] = ginv(crossprod(t(X[Z_indice,]))) %*%
51 crossprod(t(X[Z_indice,]), Y[Z_indice,])
53 betaInit1[,,r] = ginv(crossprod(X[Z_indice,])) %*%
54 crossprod(X[Z_indice,], Y[Z_indice,])
56 sigmaInit1[,,r] = diag(m)
57 phiInit1[,,r] = betaInit1[,,r] #/ sigmaInit1[,,r]
58 rhoInit1[,,r] = solve(sigmaInit1[,,r])
59 piInit1[r] = mean(Z == r)
66 dotProduct = tcrossprod(Y[i,]%*%rhoInit1[,,r]-X[i,]%*%phiInit1[,,r])
67 Gam[i,r] = piInit1[r]*det(rhoInit1[,,r])*exp(-0.5*dotProduct)
69 sumGamI = sum(Gam[i,])
70 gamInit1[i,]= Gam[i,] / sumGamI
76 new_EMG = EMGLLF(phiInit1,rhoInit1,piInit1,gamInit1,miniInit,maxiInit,1,0,X,Y,1e-6)
80 LLFEessai = new_EMG$LLF
81 LLFinit1 = LLFEessai[length(LLFEessai)]
84 b = which.max(LLFinit1)
85 phiInit = phiInit1[,,,b]
86 rhoInit = rhoInit1[,,,b]
88 gamInit = gamInit1[,,b]