QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) : QCoreApplication(argc, argv), m_runMode(LaunchMode), m_process(0), m_hostName(QLatin1String("127.0.0.1")), m_port(3768), m_pendingRequest(REQUEST_NONE), m_verbose(false), m_recording(true), m_interactive(false), m_qmlProfilerClient(&m_connection), m_v8profilerClient(&m_connection), m_connectionAttempts(0), m_qmlDataReady(false), m_v8DataReady(false) { m_connectTimer.setInterval(1000); connect(&m_connectTimer, SIGNAL(timeout()), this, SLOT(tryToConnect())); connect(&m_connection, SIGNAL(connected()), this, SLOT(connected())); connect(&m_connection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(connectionStateChanged(QAbstractSocket::SocketState))); connect(&m_connection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError))); connect(&m_qmlProfilerClient, SIGNAL(enabledChanged()), this, SLOT(traceClientEnabled())); connect(&m_qmlProfilerClient, SIGNAL(range(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation)), &m_profilerData, SLOT(addQmlEvent(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation))); connect(&m_qmlProfilerClient, SIGNAL(traceFinished(qint64)), &m_profilerData, SLOT(setTraceEndTime(qint64))); connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), &m_profilerData, SLOT(setTraceStartTime(qint64))); connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), this, SLOT(notifyTraceStarted())); connect(&m_qmlProfilerClient, SIGNAL(frame(qint64,int,int,int)), &m_profilerData, SLOT(addFrameEvent(qint64,int,int,int))); connect(&m_qmlProfilerClient, SIGNAL(sceneGraphFrame(QQmlProfilerDefinitions::SceneGraphFrameType, qint64,qint64,qint64,qint64,qint64,qint64)), &m_profilerData, SLOT(addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGraphFrameType, qint64,qint64,qint64,qint64,qint64,qint64))); connect(&m_qmlProfilerClient, SIGNAL(pixmapCache(QQmlProfilerDefinitions::PixmapEventType,qint64, QmlEventLocation,int,int,int)), &m_profilerData, SLOT(addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType,qint64, QmlEventLocation,int,int,int))); connect(&m_qmlProfilerClient, SIGNAL(memoryAllocation(QQmlProfilerDefinitions::MemoryType,qint64, qint64)), &m_profilerData, SLOT(addMemoryEvent(QQmlProfilerDefinitions::MemoryType,qint64, qint64))); connect(&m_qmlProfilerClient, SIGNAL(inputEvent(QQmlProfilerDefinitions::EventType,qint64)), &m_profilerData, SLOT(addInputEvent(QQmlProfilerDefinitions::EventType,qint64))); connect(&m_qmlProfilerClient, SIGNAL(complete()), this, SLOT(qmlComplete())); connect(&m_v8profilerClient, SIGNAL(enabledChanged()), this, SLOT(profilerClientEnabled())); connect(&m_v8profilerClient, SIGNAL(range(int,QString,QString,int,double,double)), &m_profilerData, SLOT(addV8Event(int,QString,QString,int,double,double))); connect(&m_v8profilerClient, SIGNAL(complete()), this, SLOT(v8Complete())); connect(&m_profilerData, SIGNAL(error(QString)), this, SLOT(logError(QString))); connect(&m_profilerData, SIGNAL(dataReady()), this, SLOT(traceFinished())); }
/* initialization */ void set_parameters(int _Cycles, int _Gmax, int _numSpecies, int _NP, int _Nobj, int _D, double _F, double _CR, char *pro) { Cycles=_Cycles; Gmax=_Gmax; numSpecies=_numSpecies; NP = _NP; Nobj = _Nobj; D = _D; DSp = (int)(D/numSpecies); F = _F; CR = _CR; strcpy(problemInstance,pro); EMO_TEST_SUITE::set_para(D,Nobj,2); setMPI(); memoryAllocation(); return; }
int main ( int argc, char *argv[] ) { // Loop variables int i=0, j=0, k=0, l=0; // The number of faces and their size depend of the database of faces int n=0,m=0; // size of faces int N = 0; // number of faces char **originFacesPath = NULL; Image *originFaces = NULL; Image *eigenFaces = NULL; Image faceAverage; // ACP elements : // we use array of doubles double** R = NULL; // Matrice d'image (une ligne = un visage) double** transposedR = NULL; // Matrice d'image transposée double* uR = NULL; // Vecteur moyen double** XXT = NULL; // Eigen elements double* eigenValues = NULL; // the same for XXT and XTX double** eigenVectorsV = NULL; // eigen vectors of XXT double** eigenVectorsU = NULL; // eigen vectors of XTX // Face projetction on the new space int q; // dimension of the new space double** tabCoefficients = NULL; double** eigenProjections = NULL; Image *faceProjections = NULL; // Output pictures char output[OUTPUT_SIZE]; if(argc <= 1){ fprintf(stderr, "Usage : %s image1 image2 ...\n",argv[0]); exit (EXIT_FAILURE); } N = argc - 1; originFacesPath = parseArgv(argv,N); printf("Faces importation... "); // Importation des N visages sources (matrix nxm) originFaces = importFaces(originFacesPath,N); free(originFacesPath); free(originFacesPath[0]); originFacesPath = NULL; n = originFaces[0].nbLignes; m = originFaces[0].nbColonnes; // Conversion des visages en vecteurs lignes dans R // (première colonne de la matrice puis seconde etc. = m colonnes qui se suivent de n pixels) // R = {I1,I2, ... IN}T avec N le nombre de visages (cela donne une matrice de N * (n*m)) // Un visage dans R correspond à une ligne R = facesConversion(originFaces,N); for(i=0 ; i<N ; i++){ originFaces[i].t2D = imageDesallocation(originFaces[i].t2D); } free(originFaces); printf("Success!\n"); // If it is a center ACP we have to find the average face uR uR = averageFace(R,N,(n*m)); // then, for a center ACP, we transform R in a center matrix : R <- R - uR centerFacesMatrix(R,uR,N,(n*m)); matrixExport(uR,n,m,"averageFace.pgm"); // dim(XXT) = N*N != dim(XTX) = (n*m) * (n*m) [BEAUCOUP] // Donc on fait l'ACP sur XXT puis on récupère les composantes principales (CP) de XTX grâce aux formules : // va = CP de l'axe a de XXT et ua = CP de l'axe A de XTX // ua = va * XT * 1/sqrt(lambdaA) avec lambdaA la valeur propre de l'axe A (eigenValues of XXT are equal to the eigenValues of XTX) // a. XXT transposedR = transposeMatrix(R,N,(n*m)); XXT = multiplyMatrix(R,N,(n*m),transposedR,(n*m),N); // R = matrixDesallocation(R); // b. Valeurs propres et vecteurs propres if((eigenValues = malloc(N*sizeof(double)))==NULL){ perror("Memory allocation error\n"); exit(EXIT_FAILURE); } eigenVectorsV = memoryAllocation(N,N); printf("ACP... "); acp(XXT,N,eigenValues,eigenVectorsV); XXT = matrixDesallocation(XXT); // c. Now we have to recovery the principal components of XTX eigenVectorsU = memoryAllocation(n*m,n*m); // /!\ we must consider the number of eigen values != 0 // There are as many eigen values !=0 in XXT as in XTX // but the size of these matrix is different // so the loop stop before n*m and even N because here N < n*m for(j=0 ; j<N ; j++){ // we multiply the transposedR matrix by the XXT eigen vector of the jth column. for(i=0 ; i<n*m ; i++){ double sum = 0; for(k=0 ; k<N ; k++){ sum += transposedR[i][k]*eigenVectorsV[k][j]; } eigenVectorsU[i][j]=sum/sqrt(eigenValues[j]); } } free(eigenValues); transposedR = matrixDesallocation(transposedR); eigenVectorsV = matrixDesallocation(eigenVectorsV); if ((eigenFaces = malloc(N*sizeof(Image))) == NULL){ perror("Memory allocation error\n"); exit(EXIT_FAILURE); } for(i=0 ; i< N ; i++){ eigenFaces[i].nbLignes = n; eigenFaces[i].nbColonnes = m; eigenFaces[i].t2D = imageAllocation(n,m); } //inverseFacesConversion(eigenFaces,eigenVectorsU,N,n,m); for(k=0 ; k<N ; k++){ for(i=0 ; i<n ; i++){ for(j=0 ; j<m ; j++){ // /!\ Why a and b ?! without values are too low double a = 110; double b = 7000; if(k==0) printf("%g\t",eigenVectorsU[j*n+i][k]); eigenFaces[k].t2D[i][j] = (Pixel) (abs((int) (a+eigenVectorsU[j*n+i][k]*b))); } if(k==0) printf("\n"); } } // eigenVectorsU = matrixDesallocation(eigenVectorsU); /* for(k=0 ; k<N ; k++){ sprintf(output,"eigen_faces/eigen_face%d.pgm",k); matrixExport(eigenVectorsU[][k],n,m,output); }*/ printf("Success!\n"); printf("# Writing eigen faces ...\n"); for(i = 0 ; i < N ; i++){ sprintf(output,"img/eigen_faces/eigen_face%d.pgm",i); ecrireImage (eigenFaces[i], output); } // desallocation memoire for(i=0 ; i<N ; i++){ eigenFaces[i].t2D = imageDesallocation(eigenFaces[i].t2D); } printf("# Face projection ...\n"); // face projection q = N - 1; // each line contains the coefficients of the face in the new q-dimension-space tabCoefficients = memoryAllocation(N,q); eigenProjections = memoryAllocation(N,n*m); for(i=0 ; i<N ; i++){ projection(R[i], eigenVectorsU, uR, n, m, q, tabCoefficients[i], eigenProjections[i]); } // We search the origin face which is the closest of the face to project search_face("img/toProject.pgm", eigenVectorsU, uR, n, m, q, N, tabCoefficients); tabCoefficients = matrixDesallocation(tabCoefficients); eigenVectorsU = matrixDesallocation(eigenVectorsU); R = matrixDesallocation(R); free(uR); uR = NULL; // Now we have to create faceProjection with the eigenProjections /* if((faceProjections=malloc(N*sizeof(Image)))==NULL){ perror("Memory allocation error !"); exit(EXIT_FAILURE); } for(i=0 ; i< N ; i++){ faceProjections[i].nbLignes = n; faceProjections[i].nbColonnes = m; faceProjections[i].t2D = imageAllocation(n,m); } for(k=0 ; k<N ; k++){ for(i=0 ; i<n ; i++){ for(j=0 ; j<m ; j++){ faceProjections[k].t2D[i][j] = (Pixel) eigenProjections[k][j*n+i]; } } }*/ for(i=0 ; i<N ; i++){ sprintf(output,"projections/projection%d.pgm",i); matrixExport(eigenProjections[i],n,m,output); } eigenProjections = matrixDesallocation(eigenProjections); /*printf("# Writing projection faces ...\n"); for(i = 0 ; i < N ; i++){ sprintf(output,"img/projections/projection%d.pgm",i); ecrireImage (faceProjections[i], output); } // Memory desallocation for(i=0 ; i<N ; i++){ faceProjections[i].t2D = imageDesallocation(faceProjections[i].t2D); }*/ return EXIT_SUCCESS; }