X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=R%2Fselectionmodele.R;h=ed32731c29691931734681b301f52ca5b5c98657;hp=b92c4e4bf00aef0871accb7a30f5c3d4e4d17b9d;hb=39046da6016f15d625bd99cf0303ea8beb838c79;hpb=8266149c7d93aa0543cee2a1b22e1233e7b82617 diff --git a/R/selectionmodele.R b/R/selectionmodele.R index b92c4e4..ed32731 100644 --- a/R/selectionmodele.R +++ b/R/selectionmodele.R @@ -1,38 +1,45 @@ -vec_bin = function(X,r){ - Z = c() - indice = c() - j=1 - for(i in 1:length(X)){ - if(X[i] == r){ - Z[i] = 1 - indice[j] = i - j=j+1 - } - else{ - Z[i] = 0 - } - } - return(list(Z,indice)) +vec_bin = function(X,r) +{ + Z = c() + indice = c() + + j = 1 + for(i in 1:length(X)) + { + if(X[i] == r) + { + Z[i] = 1 + indice[j] = i + j=j+1 + } else + Z[i] = 0 + } + + return (list(Z=Z,indice=indice)) } -selectionmodele = function(vraisemblance){ - D = vraimsemblance[,2] - D1 = unique(D) - - indice = rep(1, length(D1)) - - #select argmax MLE - if(length(D1)>2){ - for(i in 1:length(D1)){ - A = c() - for(j in 1:length(D)){ - if(D[[j]]==D1[[i]]){ - a = c(a, vraimsemblance[j,1]) - } - } - b = max(a) - indice[i] = which.max(vec_bin(vraimsemblance,b)[[1]]) #retourne le premier indice du vecteur binaire où u_i ==1 - } - } - return(list(indice,D1)) -} \ No newline at end of file +selectionmodele = function(vraisemblance) +{ + D = vraimsemblance[,2] + D1 = unique(D) + + indice = rep(1, length(D1)) + #select argmax MLE + if (length(D1)>2) + { + for (i in 1:length(D1)) + { + A = c() + for (j in 1:length(D)) + { + if(D[[j]]==D1[[i]]) + a = c(a, vraimsemblance[j,1]) + } + b = max(a) + #indice[i] : premier indice du vecteur binaire où u_i ==1 + indice[i] = which.max(vec_bin(vraimsemblance,b)[[1]]) + } + } + + return (list(indice=indice,D1=D1)) +}