From: Benjamin Auder Date: Thu, 23 Feb 2017 17:47:41 +0000 (+0100) Subject: Drop useless files (we will use R 'parallel' package) X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/static/doc/html/packages.html?a=commitdiff_plain;h=7f1a6cf08a4d4d67e8a95b8c1c0cc74ff3deb5a4;p=valse.git Drop useless files (we will use R 'parallel' package) --- diff --git a/src/test/generate_test_data/helpers/constructionModelesLassoMLE.R b/R/constructionModelesLassoMLE.R similarity index 100% rename from src/test/generate_test_data/helpers/constructionModelesLassoMLE.R rename to R/constructionModelesLassoMLE.R diff --git a/src/test/generate_test_data/helpers/constructionModelesLassoRank.R b/R/constructionModelesLassoRank.R similarity index 100% rename from src/test/generate_test_data/helpers/constructionModelesLassoRank.R rename to R/constructionModelesLassoRank.R diff --git a/src/adapters/a.constructionModelesLassoMLE.c b/src/adapters/a.constructionModelesLassoMLE.c deleted file mode 100644 index ec519a9..0000000 --- a/src/adapters/a.constructionModelesLassoMLE.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include "constructionModelesLassoMLE.h" - -SEXP constructionModelesLassoMLE( - SEXP phiInit_, - SEXP rhoInit_, - SEXP piInit_, - SEXP gamInit_, - SEXP mini_, - SEXP maxi_, - SEXP gamma_, - SEXP glambda_, - SEXP X_, - SEXP Y_, - SEXP seuil_, - SEXP tau_, - SEXP A1_, - SEXP A2_ -) { - // Get matrices dimensions - int n = INTEGER(getAttrib(X_, R_DimSymbol))[0]; - SEXP dim = getAttrib(phiInit_, R_DimSymbol); - int p = INTEGER(dim)[0]; - int m = INTEGER(dim)[1]; - int k = INTEGER(dim)[2]; - int L = length(glambda_); - - //////////// - // INPUTS // - //////////// - - // get scalar parameters - int mini = INTEGER_VALUE(mini_); - int maxi = INTEGER_VALUE(maxi_); - double gamma = NUMERIC_VALUE(gamma_); - double seuil = NUMERIC_VALUE(seuil_); - double tau = NUMERIC_VALUE(tau_); - - // Get pointers from SEXP arrays ; WARNING: by columns ! - double* phiInit = REAL(phiInit_); - double* rhoInit = REAL(rhoInit_); - double* piInit = REAL(piInit_); - double* gamInit = REAL(gamInit_); - double* glambda = REAL(glambda_); - double* X = REAL(X_); - double* Y = REAL(Y_); - int* A1 = INTEGER(A1_); - int* A2 = INTEGER(A2_); - - ///////////// - // OUTPUTS // - ///////////// - - SEXP phi, rho, pi, llh, dimPhi, dimRho; - PROTECT(dimPhi = allocVector(INTSXP, 4)); - int* pDimPhi = INTEGER(dimPhi); - pDimPhi[0] = p; pDimPhi[1] = m; pDimPhi[2] = k; pDimPhi[3] = L; - PROTECT(dimRho = allocVector(INTSXP, 4)); - int* pDimRho = INTEGER(dimRho); - pDimRho[0] = m; pDimRho[1] = m; pDimRho[2] = k; pDimRho[3] = L; - PROTECT(phi = allocArray(REALSXP, dimPhi)); - PROTECT(rho = allocArray(REALSXP, dimRho)); - PROTECT(pi = allocMatrix(REALSXP, k, L)); - PROTECT(llh = allocMatrix(REALSXP, L, 2)); - double *pPhi=REAL(phi), *pRho=REAL(rho), *pPi=REAL(pi), *pllh=REAL(llh); - - ///////////////////////////////////////// - // Call to constructionModelesLassoMLE // - ///////////////////////////////////////// - - constructionModelesLassoMLE_core( - phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,A1,A2, - pPhi,pRho,pPi,pllh, - n,p,m,k,L); - - // Build list from OUT params and return it - SEXP listParams, listNames; - PROTECT(listParams = allocVector(VECSXP, 4)); - char* lnames[4] = {"phi", "rho", "pi", "llh"}; //lists labels - PROTECT(listNames = allocVector(STRSXP,4)); - for (int i=0; i<4; i++) - SET_STRING_ELT(listNames,i,mkChar(lnames[i])); - setAttrib(listParams, R_NamesSymbol, listNames); - SET_VECTOR_ELT(listParams, 0, phi); - SET_VECTOR_ELT(listParams, 1, rho); - SET_VECTOR_ELT(listParams, 2, pi); - SET_VECTOR_ELT(listParams, 3, llh); - - UNPROTECT(8); - return listParams; -} diff --git a/src/adapters/a.constructionModelesLassoRank.c b/src/adapters/a.constructionModelesLassoRank.c deleted file mode 100644 index 0e069d4..0000000 --- a/src/adapters/a.constructionModelesLassoRank.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include "constructionModelesLassoRank.h" - -SEXP constructionModelesLassoRank( - SEXP Pi_, - SEXP Rho_, - SEXP mini_, - SEXP maxi_, - SEXP X_, - SEXP Y_, - SEXP tau_, - SEXP A1_, - SEXP rangmin_, - SEXP rangmax_ -) { - // Get matrices dimensions - SEXP dimX = getAttrib(X_, R_DimSymbol); - int n = INTEGER(dimX)[0]; - int p = INTEGER(dimX)[1]; - SEXP dimRho = getAttrib(Rho_, R_DimSymbol); - int m = INTEGER(dimRho)[0]; - int k = INTEGER(dimRho)[2]; - int L = INTEGER(getAttrib(A1_, R_DimSymbol))[1]; - - //////////// - // INPUTS // - //////////// - - // get scalar parameters - int mini = INTEGER_VALUE(mini_); - int maxi = INTEGER_VALUE(maxi_); - double tau = NUMERIC_VALUE(tau_); - double rangmin = NUMERIC_VALUE(rangmin_); - double rangmax = NUMERIC_VALUE(rangmax_); - - // Get pointers from SEXP arrays ; WARNING: by columns ! - double* Pi = REAL(Pi_); - double* Rho = REAL(Rho_); - double* X = REAL(X_); - double* Y = REAL(Y_); - int* A1 = INTEGER(A1_); - - ///////////// - // OUTPUTS // - ///////////// - - int Size = pow(rangmax-rangmin+1,k); - SEXP phi, llh, dimPhi; - PROTECT(dimPhi = allocVector(INTSXP, 4)); - int* pDimPhi = INTEGER(dimPhi); - pDimPhi[0] = p; pDimPhi[1] = m; pDimPhi[2] = k; pDimPhi[3] = L*Size; - PROTECT(phi = allocArray(REALSXP, dimPhi)); - PROTECT(llh = allocMatrix(REALSXP, L*Size, 2)); - double *pPhi=REAL(phi), *pllh=REAL(llh); - - ////////////////////////////////////////// - // Call to constructionModelesLassoRank // - ////////////////////////////////////////// - - constructionModelesLassoRank_core( - Pi,Rho,mini,maxi,X,Y,tau,A1,rangmin,rangmax, - pPhi,pllh, - n,p,m,k,L); - - // Build list from OUT params and return it - SEXP listParams, listNames; - PROTECT(listParams = allocVector(VECSXP, 2)); - char* lnames[2] = {"phi", "llh"}; //lists labels - PROTECT(listNames = allocVector(STRSXP,2)); - for (int i=0; i<2; i++) - SET_STRING_ELT(listNames,i,mkChar(lnames[i])); - setAttrib(listParams, R_NamesSymbol, listNames); - SET_VECTOR_ELT(listParams, 0, phi); - SET_VECTOR_ELT(listParams, 1, llh); - - UNPROTECT(5); - return listParams; -} diff --git a/src/adapters/a.selectiontotale.c b/src/adapters/a.selectiontotale.c deleted file mode 100644 index 3bfab9f..0000000 --- a/src/adapters/a.selectiontotale.c +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include "selectiontotale.h" - -SEXP selectiontotale( - SEXP phiInit_, - SEXP rhoInit_, - SEXP piInit_, - SEXP gamInit_, - SEXP mini_, - SEXP maxi_, - SEXP gamma_, - SEXP glambda_, - SEXP X_, - SEXP Y_, - SEXP seuil_, - SEXP tau_ -) { - // Get matrices dimensions - SEXP dimX = getAttrib(X_, R_DimSymbol); - int n = INTEGER(dimX)[0]; - int p = INTEGER(dimX)[1]; - SEXP dimRhoInit = getAttrib(rhoInit_, R_DimSymbol); - int m = INTEGER(dimRhoInit)[0]; - int k = INTEGER(dimRhoInit)[2]; - int L = length(glambda_); - - //////////// - // INPUTS // - //////////// - - // get scalar parameters - int mini = INTEGER_VALUE(mini_); - int maxi = INTEGER_VALUE(maxi_); - double gamma = NUMERIC_VALUE(gamma_); - double seuil = NUMERIC_VALUE(seuil_); - double tau = NUMERIC_VALUE(tau_); - - // Get pointers from SEXP arrays ; WARNING: by columns ! - double* phiInit = REAL(phiInit_); - double* rhoInit = REAL(rhoInit_); - double* piInit = REAL(piInit_); - double* gamInit = REAL(gamInit_); - double* glambda = REAL(glambda_); - double* X = REAL(X_); - double* Y = REAL(Y_); - - ///////////// - // OUTPUTS // - ///////////// - - SEXP A1, A2, rho, pi, dimA, dimRho; - PROTECT(dimA = allocVector(INTSXP, 3)); - int* pDimA = INTEGER(dimA); - pDimA[0] = p; pDimA[1] = m+1; pDimA[2] = L; - PROTECT(A1 = allocArray(INTSXP, dimA)); - PROTECT(A2 = allocArray(INTSXP, dimA)); - PROTECT(dimRho = allocVector(INTSXP, 4)); - int* pDimRho = INTEGER(dimRho); - pDimRho[0] = m; pDimRho[1] = m; pDimRho[2] = k; pDimRho[3] = L; - PROTECT(rho = allocArray(REALSXP, dimRho)); - PROTECT(pi = allocMatrix(REALSXP, k, L)); - int *pA1=INTEGER(A1), *pA2=INTEGER(A2); - double *pRho=REAL(rho), *pPi=REAL(pi); - - ///////////////////////////// - // Call to selectiontotale // - ///////////////////////////// - - selectiontotale_core( - phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau, - pA1,pA2,pRho,pPi, - n,p,m,k,L); - - // Build list from OUT params and return it - SEXP listParams, listNames; - PROTECT(listParams = allocVector(VECSXP, 4)); - char* lnames[4] = { "A1", "A2", "rho", "pi" }; //lists labels - PROTECT(listNames = allocVector(STRSXP, 4)); - for (int i=0; i<4; i++) - SET_STRING_ELT(listNames,i,mkChar(lnames[i])); - setAttrib(listParams, R_NamesSymbol, listNames); - SET_VECTOR_ELT(listParams, 0, A1); - SET_VECTOR_ELT(listParams, 1, A2); - SET_VECTOR_ELT(listParams, 2, rho); - SET_VECTOR_ELT(listParams, 3, pi); - - UNPROTECT(7); - return listParams; -} diff --git a/src/sources/constructionModelesLassoMLE.c b/src/sources/constructionModelesLassoMLE.c deleted file mode 100644 index 34e5808..0000000 --- a/src/sources/constructionModelesLassoMLE.c +++ /dev/null @@ -1,214 +0,0 @@ -#include "EMGLLF.h" -#include "utils.h" -#include -#include -#include - -// TODO: comment on constructionModelesLassoMLE purpose -void constructionModelesLassoMLE_core( - // IN parameters - const Real* phiInit, // parametre initial de moyenne renormalisé - const Real* rhoInit, // parametre initial de variance renormalisé - const Real* piInit,// parametre initial des proportions - const Real* gamInit, // paramètre initial des probabilités a posteriori de chaque échantillon - int mini,// nombre minimal d'itérations dans l'algorithme EM - int maxi,// nombre maximal d'itérations dans l'algorithme EM - Real gamma,// valeur de gamma : puissance des proportions dans la pénalisation - //pour un Lasso adaptatif - const Real* glambda, // valeur des paramètres de régularisation du Lasso - const Real* X, // régresseurs - const Real* Y, // réponse - Real seuil,// seuil pour prendre en compte une variable - Real tau,// seuil pour accepter la convergence - const int* A1, // matrice des coefficients des parametres selectionnes - const int* A2, // matrice des coefficients des parametres non selectionnes - // OUT parameters - Real* phi,// estimateur ainsi calculé par le Lasso - Real* rho,// estimateur ainsi calculé par le Lasso - Real* pi, // estimateur ainsi calculé par le Lasso - Real* llh, // estimateur ainsi calculé par le Lasso - // additional size parameters - int n, // taille de l'echantillon - int p, // nombre de covariables - int m, // taille de Y (multivarié) - int k, // nombre de composantes - int L) // taille de glambda -{ - //preparation: phi,rho,pi = 0, llh=+Inf - for (int u=0; u 0) - { - //phi[A2[j,1,lambdaIndex],b,,lambdaIndex] = 0. - for (int mm=0; mmdata[u*m+v] = rho[ai4(u,v,r,lambdaIndex,m,m,k,L)]; - } - gsl_linalg_LU_decomp(matrix, permutation, &signum); - Real detRhoR = gsl_linalg_LU_det(matrix, signum); - - //compute Y(i,:)*rho(:,:,r,lambdaIndex) - for (int u=0; u - Real dotProduct = 0.0; - for (int u=0; u -#include -#include -#include "EMGrank.h" -#include "utils.h" - -// TODO: comment on constructionModelesLassoRank purpose -void constructionModelesLassoRank_core( - // IN parameters - const Real* pi,// parametre initial des proportions - const Real* rho, // parametre initial de variance renormalisé - int mini, // nombre minimal d'itérations dans l'algorithme EM - int maxi, // nombre maximal d'itérations dans l'algorithme EM - const Real* X,// régresseurs - const Real* Y,// réponse - Real tau, // seuil pour accepter la convergence - const int* A1, // matrice des coefficients des parametres selectionnes - int rangmin, //rang minimum autorisé - int rangmax, //rang maximum autorisé - // OUT parameters (all pointers, to be modified) - Real* phi,// estimateur ainsi calculé par le Lasso - Real* llh,// estimateur ainsi calculé par le Lasso - // additional size parameters - int n,// taille de l'echantillon - int p,// nombre de covariables - int m,// taille de Y (multivarié) - int k,// nombre de composantes - int L)// taille de glambda -{ - //On cherche les rangs possiblement intéressants - int deltaRank = rangmax-rangmin+1; - int Size = (int)pow(deltaRank,k); - int* Rank = (int*)malloc(Size*k*sizeof(int)); - for (int r=0; r 0 - Real* phiLambda = (Real*)malloc(longueurActive*m*k*sizeof(Real)); - Real LLF; - for (int j=0; j -#include -#include -#include "EMGLLF.h" -#include "utils.h" - -// Main job on raw inputs (after transformation from mxArray) -void selectiontotale_core( - // IN parameters - const Real* phiInit, // parametre initial de moyenne renormalisé - const Real* rhoInit, // parametre initial de variance renormalisé - const Real* piInit,// parametre initial des proportions - const Real* gamInit, // paramètre initial des probabilités a posteriori de chaque échantillon - int mini, // nombre minimal d'itérations dans lambdaIndex'algorithme EM - int maxi, // nombre maximal d'itérations dans lambdaIndex'algorithme EM - Real gamma, // valeur de gamma : puissance des proportions dans la pénalisation pour un Lasso adaptatif - const Real* glambda, // valeur des paramètres de régularisation du Lasso - const Real* X,// régresseurs - const Real* Y,// réponse - Real seuil, // seuil pour prendre en compte une variable - Real tau, // seuil pour accepter la convergence - // OUT parameters (all pointers, to be modified) - int* A1, // matrice des coefficients des parametres selectionnes - int* A2, // matrice des coefficients des parametres non selectionnes - Real* Rho,// estimateur ainsi calculé par le Lasso - Real* Pi,// estimateur ainsi calculé par le Lasso - // additional size parameters - int n,// taille de lambdaIndex'echantillon - int p,// nombre de covariables - int m,// taille de Y (multivarié) - int k,// nombre de composantes - int L) // taille de glambda -{ - // Fill outputs with zeros: they might not be assigned - for (int u=0; u maxPhi) - maxPhi = fabs(phi[ai(j,jj,r,p,m,k)]); - } - if (maxPhi > seuil) - { - selectedVariables[mi(j,cpt,p,m)] = jj+1; - atLeastOneSelectedVariable = 1; - cpt++; - } - else - { - discardedVariables[mi(j,cpt2,p,m)] = jj+1; - cpt2++; - } - } - } - free(phi); - - if (atLeastOneSelectedVariable) - { - int* vec = (int*)malloc(p*sizeof(int)); - int vecSize = 0; - for (int j=0; j - -#include - -int main(int argc, char** argv) -{ - int* dimensions = readArray_int("dimensions"); - int n = dimensions[0]; - int p = dimensions[1]; - int m = dimensions[2]; - int k = dimensions[3]; - int L = dimensions[4]; - free(dimensions); - - //////////// - // INPUTS // - Real* phiInit = readArray_real("phiInit"); - Real* rhoInit = readArray_real("rhoInit"); - Real* piInit = readArray_real("piInit"); - Real* gamInit = readArray_real("gamInit"); - int mini = read_int("mini"); - int maxi = read_int("maxi"); - Real gamma = read_real("gamma"); - Real* glambda = readArray_real("glambda"); - Real* X = readArray_real("X"); - Real* Y = readArray_real("Y"); - Real seuil = read_real("seuil"); - Real tau = read_real("tau"); - int* A1 = readArray_int("A1"); - int* A2 = readArray_int("A2"); - //////////// - - ///////////// - // OUTPUTS // - Real* phi = (Real*)malloc(p*m*k*L*sizeof(Real)); - Real* rho = (Real*)malloc(m*m*k*L*sizeof(Real)); - Real* pi = (Real*)malloc(k*L*sizeof(Real)); - Real* llh = (Real*)malloc(L*2*sizeof(Real)); - ///////////// - - ///////////////////////////////////////// - // Call to constructionModelesLassoMLE // - constructionModelesLassoMLE_core( - phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,A1,A2, - phi,rho,pi,llh, - n,p,m,k,L); - ///////////////////////////////////////// - - free(phiInit); - free(rhoInit); - free(piInit); - free(gamInit); - free(X); - free(Y); - free(A1); - free(A2); - free(glambda); - - // Compare to reference outputs - Real* ref_phi = readArray_real("phi"); - compareArray_real("phi", phi, ref_phi, p*m*k*L); - free(phi); - free(ref_phi); - - Real* ref_rho = readArray_real("rho"); - compareArray_real("rho", rho, ref_rho, m*m*k*L); - free(rho); - free(ref_rho); - - Real* ref_pi = readArray_real("pi"); - compareArray_real("pi", pi, ref_pi, k*L); - free(pi); - free(ref_pi); - - Real* ref_llh = readArray_real("llh"); - compareArray_real("llh", llh, ref_llh, L*2); - free(llh); - free(ref_llh); - - return 0; -} diff --git a/src/test/test.constructionModelesLassoRank.c b/src/test/test.constructionModelesLassoRank.c deleted file mode 100644 index f60ffea..0000000 --- a/src/test/test.constructionModelesLassoRank.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "constructionModelesLassoRank.h" -#include "test_utils.h" -#include -#include - -int main(int argc, char** argv) -{ - int* dimensions = readArray_int("dimensions"); - int n = dimensions[0]; - int p = dimensions[1]; - int m = dimensions[2]; - int k = dimensions[3]; - int L = dimensions[4]; - free(dimensions); - - //////////// - // INPUTS // - Real* pi = readArray_real("pi"); - Real* rho = readArray_real("rho"); - int mini = read_int("mini"); - int maxi = read_int("maxi"); - Real* X = readArray_real("X"); - Real* Y = readArray_real("Y"); - Real tau = read_real("tau"); - int* A1 = readArray_int("A1"); - int rangmin = read_int("rangmin"); - int rangmax = read_int("rangmax"); - //////////// - - ///////////// - // OUTPUTS // - int Size = (int)pow(rangmax-rangmin+1, k); - Real* phi = (Real*)malloc(p*m*k*L*Size*sizeof(Real)); - Real* llh = (Real*)malloc(L*Size*2*sizeof(Real)); - ///////////// - - ///////////////////////////////////////// - // Call to constructionModelesLassoMLE // - constructionModelesLassoRank_core( - pi,rho,mini,maxi,X,Y,tau,A1,rangmin,rangmax, - phi,llh, - n,p,m,k,L); - ///////////////////////////////////////// - - free(rho); - free(pi); - free(X); - free(Y); - free(A1); - - // Compare to reference outputs - Real* ref_phi = readArray_real("phi"); - compareArray_real("phi", phi, ref_phi, p*m*k*L*Size); - free(phi); - free(ref_phi); - - Real* ref_llh = readArray_real("llh"); - compareArray_real("llh", llh, ref_llh, L*Size*2); - free(llh); - free(ref_llh); - - return 0; -} diff --git a/src/test/test.selectiontotale.c b/src/test/test.selectiontotale.c deleted file mode 100644 index 843a04d..0000000 --- a/src/test/test.selectiontotale.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "selectiontotale.h" -#include "test_utils.h" -#include - -int main(int argc, char** argv) -{ - int* dimensions = readArray_int("dimensions"); - int n = dimensions[0]; - int p = dimensions[1]; - int m = dimensions[2]; - int k = dimensions[3]; - int L = dimensions[4]; - free(dimensions); - - //////////// - // INPUTS // - Real* phiInit = readArray_real("phiInit"); - Real* rhoInit = readArray_real("rhoInit"); - Real* piInit = readArray_real("piInit"); - Real* gamInit = readArray_real("gamInit"); - int mini = read_int("mini"); - int maxi = read_int("maxi"); - Real gamma = read_real("gamma"); - Real* glambda = readArray_real("glambda"); - Real* X = readArray_real("X"); - Real* Y = readArray_real("Y"); - Real seuil = read_real("seuil"); - Real tau = read_real("tau"); - //////////// - - ///////////// - // OUTPUTS // - int* A1 = (int*)malloc(p*(m+1)*L*sizeof(int)); - int* A2 = (int*)malloc(p*(m+1)*L*sizeof(int)); - Real* Rho = (Real*)malloc(m*m*k*L*sizeof(Real)); - Real* Pi = (Real*)malloc(k*L*sizeof(Real)); - ///////////// - - ///////////////////////////////////////// - // Call to constructionModelesLassoMLE // - selectiontotale_core( - phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau, - A1,A2,Rho,Pi, - n,p,m,k,L); - ///////////////////////////////////////// - - free(phiInit); - free(rhoInit); - free(piInit); - free(gamInit); - free(glambda); - free(X); - free(Y); - - // Compare to reference outputs - int* ref_A1 = readArray_int("A1"); - compareArray_int("A1", A1, ref_A1, p*(m+1)*L); - free(A1); - free(ref_A1); - - int* ref_A2 = readArray_int("A2"); - compareArray_int("A2", A2, ref_A2, p*(m+1)*L); - free(A2); - free(ref_A2); - - Real* ref_Rho = readArray_real("Rho"); - compareArray_real("Rho", Rho, ref_Rho, m*m*k*L); - free(Rho); - free(ref_Rho); - - Real* ref_Pi = readArray_real("Pi"); - compareArray_real("Pi", Pi, ref_Pi, k*L); - free(Pi); - free(ref_Pi); - - return 0; -}