From: Benjamin Goehry Date: Mon, 16 Jan 2017 17:57:49 +0000 (+0100) Subject: new tests + correction X-Git-Url: https://git.auder.net/doc/html/css/%7B%7B?a=commitdiff_plain;h=f1b906da691f13c6eae25899188d1c071e79b04e;p=valse.git new tests + correction --- diff --git a/src/test/generate_test_data/generateRunSaveTest_EMGrank.R b/src/test/generate_test_data/generateRunSaveTest_EMGrank.R new file mode 100644 index 0000000..6fc812a --- /dev/null +++ b/src/test/generate_test_data/generateRunSaveTest_EMGrank.R @@ -0,0 +1,34 @@ +generateRunSaveTest_EMGrank = function(n=200, p=15, m=10, k=3, mini=5, maxi=10, gamma=1.0, rank = c(1,2,4)){ + testFolder = "data/" + dir.create(testFolder, showWarnings=FALSE, mode="0755") + delimiter = " " + + tau = 1e-6 + + pi = rep(1.0/k, k) + rho = array(0, dim=c(m,m,k)) + + for(i in 1:k){ + rho[,,i] = diag(1,m) + } + + #Generate X and Y + generateIOdef = generateIOdefault(n, p, m, k) + + #save inputs + write.table(paste(testFolder,"rho",sep=""), rho, sep=delimiter) + write.table(paste(testFolder,"pi",sep=""), pi, sep=delimiter) + write.table(paste(testFolder,"mini",sep=""), mini, sep=delimiter) + write.table(paste(testFolder,"maxi",sep=""), maxi, sep=delimiter) + write.table(paste(testFolder,"X",sep=""), generateIOdef$X sep=delimiter) + write.table(paste(testFolder,"Y",sep=""), generateIOdef$Y, sep=delimiter) + write.table(paste(testFolder,"tau",sep=""), tau, sep=delimiter) + write.table(paste(testFolder,"rank",sep=""), rank, sep=delimiter) + write.table(paste(testFolder,"dimensions",sep=""), c(n,p,m,k), sep=delimiter) + + EMG_rank = EMG(pi,rho,mini,maxi,X,Y,tau,rank) + + #save output + write.table(paste(testFolder,"phi",sep=""), EMG_rank$phi, sep=delimiter) + write.table(paste(testFolder,"LLF",sep=""), EMG_rank$LLF, sep=delimiter) +} diff --git a/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoMLE.R b/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoMLE.R index d367bfd..104cb3f 100644 --- a/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoMLE.R +++ b/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoMLE.R @@ -1,76 +1,45 @@ -generateRunSaveTest_constructionModelesLassoMLE = function(n, p, m, k, mini, maxi, gamma, glambda, varargin){ - #set defaults for optional inputs - optargs = c(200 15 10 3 5 10 1.0 list(0.0,0.01,0.02,0.03,0.05,0.1,0.2,0.3,0.5,0.7,0.85,0.99)) - #replace defaults by user parameters - optargs[1:length(varargin)] = varargin - n = optargs[1] - p = optargs[2] - m = optargs[3] - k = optargs[4] - mini = optargs[5] - maxi = optargs[6] - gamma = optargs[7] - glambda = optargs[8] - tau = 1e-6 - seuil = 1e-15 - L = length(glambda) +generateRunSaveTest_constructionModelesLassoMLE = function(n=200, p=15, m=10, k=3, mini=5, maxi=10, gamma=1.0, glambda=list(0.0,0.01,0.02,0.03,0.05,0.1,0.2,0.3,0.5,0.7,0.85,0.99)){ + testFolder = "data/" + dir.create(testFolder, showWarnings=FALSE, mode="0755") + delimiter = " " #Generate phiInit,piInit,... - basicInit = basicInitParameters(n, p, m, k) - phiInit = basicInit$phiInit - rhoInit = basicInit$rhoInit - piInit = basicInit$piInit - gamInit = basicInit$gamInit - - #Generate X and Y - generateIOdef = generateIOdefault(n, p, m, k) - X = generateIOdef$X - Y = generateIOdef$Y + params = basicInitParameters(n, p, m, k) + #save inputs + write.table(paste(testFolder,"phiInit",sep=""), params$phiInit, sep=delimiter) + write.table(paste(testFolder,"rhoInit",sep=""), params$rhoInit, sep=delimiter) + write.table(paste(testFolder,"piInit",sep=""), params$piInit, sep=delimiter) + write.table(paste(testFolder,"gamInit",sep=""), params$gamInit, sep=delimiter) + write.table(paste(testFolder,"mini",sep=""), mini, sep=delimiter) + write.table(paste(testFolder,"maxi",sep=""), maxi, sep=delimiter) + write.table(paste(testFolder,"gamma",sep=""), gamma, sep=delimiter) + write.table(paste(testFolder,"lambda",sep=""), lambda, sep=delimiter) + write.table(paste(testFolder,"X",sep=""), io$X, sep=delimiter) + write.table(paste(testFolder,"Y",sep=""), io$Y, sep=delimiter) + write.table(paste(testFolder,"tau",sep=""), tau, sep=delimiter) + write.table(paste(testFolder,"dimensions",sep=""), c(n,p,m,k), sep=delimiter) + A2 = array(0, dim=c(p, m+1, L)) A1 = array(0, dim=c(p, m+1, L)) for(i in 1:L){ - for(j in 1:p){ - A2[j, 1, i] = j - A1[j, 1, i] = j - } - for(k in 1:5){ - A2[k,2,i] = k - A1[k,2,i] = k - } + A2[,1,i] = seq(1,p) + A2[,2,i] = seq(1,5) + A1[,1, i] = seq(1,p) + A1[,2,i] = seq(1,5) } - - testFolder = 'data/' - dir.create(testFolder) - delimiter = ' ' - - #save inputs - write(strcat(testFolder,'phiInit'), reshape(phiInit,1), delimiter) - write(strcat(testFolder,'rhoInit'), reshape(rhoInit,1), delimiter) - write(strcat(testFolder,'piInit'), piInit, delimiter) - write(strcat(testFolder,'gamInit'), reshape(gamInit,1), delimiter) - write(strcat(testFolder,'mini'), mini, delimiter) - write(strcat(testFolder,'maxi'), maxi, delimiter) - write(strcat(testFolder,'gamma'), gamma, delimiter) - write(strcat(testFolder,'glambda'), glambda, delimiter) - write(strcat(testFolder,'X'), reshape(X,1), delimiter) - write(strcat(testFolder,'Y'), reshape(Y,1), delimiter) - mwrite(strcat(testFolder,'seuil'), seuil, delimiter) - write(strcat(testFolder,'tau'), tau, delimiter) - write(strcat(testFolder,'A1'), reshape(A1,1), delimiter) - write(strcat(testFolder,'A2'), reshape(A2,1), delimiter) - write(strcat(testFolder,'dimensions'), [n,p,m,k,L], delimiter) - - construct_LME = constructionModelesLassoMLE(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,A1,A2) + #Generate X and Y + generateIOdef = generateIOdefault(n, p, m, k) + construct_LME = constructionModelesLassoMLE(params$phiInit,params$rhoInit,params$piInit,params$gamInit,mini,maxi,gamma,glambda,generateIOdef$X,generateIOdef$Y,seuil,tau,A1,A2) phi = construct_LME$phi rho = construct_LME$rho pi = construct_LME$pi lvraisemblance = construct_LME$lvraisemblance #save output - write(strcat(testFolder,'phi'), reshape(phi,1), delimiter); - write(strcat(testFolder,'rho'), reshape(rho,1), delimiter); - write(strcat(testFolder,'pi'), reshape(pi,1), delimiter); - write(strcat(testFolder,'lvraisemblance'), reshape(lvraisemblance,1), delimiter); + write.table(paste(testFolder,"phi",sep=""), construct_LME$phi, sep=delimiter) + write.table(paste(testFolder,"rho",sep=""), construct_LME$rho, sep=delimiter) + write.table(paste(testFolder,"pi",sep=""), construct_LME$pi, sep=delimiter) + write.table(paste(testFolder,"lvraisemblance",sep=""), construct_LME$lvraisemblance, sep=delimiter) } diff --git a/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoRank.R b/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoRank.R new file mode 100644 index 0000000..09d9823 --- /dev/null +++ b/src/test/generate_test_data/generateRunSaveTest_constructionModelesLassoRank.R @@ -0,0 +1,45 @@ +generateRunSaveTest_constructionModelesLassoRank = function(n=200, p=15, m=10, L=12, mini=5, maxi=10, gamma=1.0, rangmin=3, rangmax=6){ + testFolder = "data/" + dir.create(testFolder, showWarnings=FALSE, mode="0755") + delimiter = " " + + tau = 1e-6 + + + pi = matrix(0, k,L) + for(i in 1:L){ + pi[,i] = rep(1.0/k, k) + } + rho = array(0, dim=c(m,m,k,L)) + for(l in 1:L){ + for(r in 1:k){ + rho[,,r,l] = diag(1,m) + } + } + #Generate X and Y + generateIOdef = generateIOdefault(n, p, m, k) + + A1 = matrix(0,p,L) + for(i in 1:L){ + A1[,i] = seq(1,p) + } + #save inputs + write.table(paste(testFolder,"rho",sep=""), rho, sep=delimiter) + write.table(paste(testFolder,"pi",sep=""), pi, sep=delimiter) + write.table(paste(testFolder,"mini",sep=""), mini, sep=delimiter) + write.table(paste(testFolder,"maxi",sep=""), maxi, sep=delimiter) + write.table(paste(testFolder,"X",sep=""), generateIOdef$X sep=delimiter) + write.table(paste(testFolder,"Y",sep=""), generateIOdef$Y, sep=delimiter) + write.table(paste(testFolder,"tau",sep=""), tau, sep=delimiter) + write.table(paste(testFolder,"A1",sep=""), A1, sep=delimiter) + write.table(paste(testFolder,"rangmin",sep=""), rangmin, sep=delimiter) + write.table(paste(testFolder,"rangmax",sep=""), rangmax, sep=delimiter) + write.table(paste(testFolder,"dimensions",sep=""), c(n,p,m,k), sep=delimiter) + + construct = constructionModelesLassoRank(pi,rho,mini,maxi,X,Y,tau,A1,rangmin,rangmax)) + + #save output + write.table(paste(testFolder,"phi",sep=""), construct$phi, sep=delimiter) + write.table(paste(testFolder,"lvraisemblance",sep=""), construct$lvraisemblance, sep=delimiter) + +} \ No newline at end of file diff --git a/src/test/generate_test_data/generateRunSaveTest_selectiontotale.R b/src/test/generate_test_data/generateRunSaveTest_selectiontotale.R new file mode 100644 index 0000000..b366ec9 --- /dev/null +++ b/src/test/generate_test_data/generateRunSaveTest_selectiontotale.R @@ -0,0 +1,34 @@ +generateRunSaveTest_selectiontotale= function(n=200, p=15, m=10, k=3, mini=5, maxi=10, gamma=1.0, glambda=list(0.0,0.01,0.02,0.03,0.05,0.1,0.2,0.3,0.5,0.7,0.85,0.99)){ + testFolder = "data/" + dir.create(testFolder, showWarnings=FALSE, mode="0755") + delimiter = " " + + #Generate phiInit,piInit,... + params = basicInitParameters(n, p, m, k) + + #Generate X and Y + generateIOdef = generateIOdefault(n, p, m, k) + + #save inputs + write.table(paste(testFolder,"phiInit",sep=""), params$phiInit, sep=delimiter) + write.table(paste(testFolder,"rhoInit",sep=""), params$rhoInit, sep=delimiter) + write.table(paste(testFolder,"piInit",sep=""), params$piInit, sep=delimiter) + write.table(paste(testFolder,"gamInit",sep=""), params$gamInit, sep=delimiter) + write.table(paste(testFolder,"mini",sep=""), mini, sep=delimiter) + write.table(paste(testFolder,"maxi",sep=""), maxi, sep=delimiter) + write.table(paste(testFolder,"gamma",sep=""), gamma, sep=delimiter) + write.table(paste(testFolder,"lambda",sep=""), glambda, sep=delimiter) + write.table(paste(testFolder,"X",sep=""), io$X, sep=delimiter) + write.table(paste(testFolder,"Y",sep=""), io$Y, sep=delimiter) + write.table(paste(testFolder,"tau",sep=""), tau, sep=delimiter) + write.table(paste(testFolder,"dimensions",sep=""), c(n,p,m,k), sep=delimiter) + + + selec = selectiontotale(params$phiInit,params$rhoInit,params$piInit,params$gamInit,mini,maxi,gamma,glambda,generateIOdef$X,generateIOdef$Y,seuil, tau) + + #save output + write.table(paste(testFolder,"A1",sep=""), selec$A1, sep=delimiter) + write.table(paste(testFolder,"A2",sep=""), selec$A2, sep=delimiter) + write.table(paste(testFolder,"rho",sep=""), selec$rho, sep=delimiter) + write.table(paste(testFolder,"pi",sep=""), selec$pi, sep=delimiter) +}