void FeatureEval::pca(){ boost::shared_ptr<PointCloud> cloud = core_->cl_->active_; if(cloud == nullptr) return; std::vector<int> sub_idxs; pcl::PointCloud<pcl::PointXYZI>::Ptr smaller_cloud = octreeDownsample(cloud.get(), subsample_res_, sub_idxs); t_.start(); qDebug() << "Timer started (PCA)"; boost::shared_ptr<std::vector<Eigen::Vector3f> > pca = getPCA(smaller_cloud.get(), search_radius_, max_nn_); qDebug() << "PCA in " << (time_ = t_.elapsed()) << " ms"; computeCorrelation(reinterpret_cast<float *>(pca->data()), 3, pca->size(), sub_idxs, sizeof(Eigen::Vector3f)/sizeof(float)); if(!visualise_on_) return; // // Draw // boost::shared_ptr<std::vector<Eigen::Vector3f> > grid = boost::make_shared<std::vector<Eigen::Vector3f> >(grid_to_cloud->size(), Eigen::Vector3f(0.0f, 0.0f, 0.0f)); // for(int i = 0; i < grid_to_cloud->size(); i++) { // int idx = (*grid_to_cloud)[i]; // if(idx != -1) // (*grid)[i] = (*pca)[idx]; // } // drawVector3f(grid, cloud); }
void FeatureEval::normal_standard_deviation(){ boost::shared_ptr<PointCloud> cloud = core_->cl_->active_; if(cloud == nullptr) return; pcl::PointCloud<pcl::Normal>::Ptr normals = ne_->getNormals(cloud); // Downsample and zipper up normals and xyzi std::vector<int> sub_idxs; pcl::PointCloud<pcl::PointXYZINormal>::Ptr smaller_cloud = zipNormals(cloud, normals); smaller_cloud = octreeDownsample(smaller_cloud.get(), subsample_res_, sub_idxs); // Compute t_.start(); qDebug() << "Timer started (Normal stdev)"; boost::shared_ptr<std::vector<float>> stdev = normal_stdev<pcl::PointXYZINormal, pcl::PointXYZINormal>(smaller_cloud, smaller_cloud, search_radius_, max_nn_); qDebug() << "Normal stdev in " << (time_ = t_.elapsed()) << " ms"; // Correlate computeCorrelation(stdev->data(), 1, stdev->size(), sub_idxs); if(!visualise_on_) return; // Draw int h = cloud->scan_width(); int w = cloud->scan_height(); boost::shared_ptr<std::vector<float>> grid = boost::make_shared<std::vector<float>>(w*h, 0.0f); const std::vector<int> & cloudtogrid = cloud->cloudToGridMap(); for(uint big_idx = 0; big_idx < cloud->size(); big_idx++) { int small_idx = sub_idxs[big_idx]; int grid_idx = cloudtogrid[big_idx]; (*grid)[grid_idx] = (*stdev)[small_idx]; } drawFloats(grid, cloud); }
void FeatureEval::fast_point_feature_histogram(){ qDebug() << "params used: " << subsample_res_ << search_radius_; qDebug() << "-----------------------------------"; boost::shared_ptr<PointCloud> _cloud = core_->cl_->active_; if(_cloud == nullptr) return; pcl::PointCloud<pcl::PointXYZINormal>::Ptr filt_cloud; std::vector<int> sub_idxs; filt_cloud = downsample(_cloud, subsample_res_, sub_idxs); // Compute t_.start(); qDebug() << "Timer started (FPFH)"; pcl::FPFHEstimation<pcl::PointXYZINormal, pcl::PointXYZINormal, pcl::FPFHSignature33> fpfh; fpfh.setInputCloud(filt_cloud); fpfh.setInputNormals(filt_cloud); pcl::search::KdTree<pcl::PointXYZINormal>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZINormal>); fpfh.setSearchMethod(tree); fpfh.setRadiusSearch(search_radius_); pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs (new pcl::PointCloud<pcl::FPFHSignature33> ()); fpfh.compute(*fpfhs); qDebug() << "FPFH in " << (time_ = t_.elapsed()) << " ms"; // Correlate computeCorrelation(reinterpret_cast<float*>(fpfhs->points.data()), 33, fpfhs->points.size(), sub_idxs); if(!visualise_on_) return; }
void FeatureEval::eigen_plane_consine_similarity(){ boost::shared_ptr<PointCloud> cloud = core_->cl_->active_; if(cloud == nullptr) return; std::vector<int> sub_idxs; pcl::PointCloud<pcl::PointXYZI>::Ptr smaller_cloud = octreeDownsample(cloud.get(), subsample_res_, sub_idxs); t_.start(); qDebug() << "Timer started (eigen_plane_consine_similarity)"; boost::shared_ptr<std::vector<Eigen::Vector3f> > pca = getPCA(smaller_cloud.get(), 0.05f, 20); boost::shared_ptr<std::vector<float>> plane_likelyhood = boost::make_shared<std::vector<float>>(pca->size(), 0.0f); Eigen::Vector3f ideal_plane(1.0f, 0.0f, 0.0f); ideal_plane.normalize(); for(uint i = 0; i < pca->size(); i++) { Eigen::Vector3f & val = (*pca)[i]; // Not enough neighbours if(val[1] < val[2]) { (*plane_likelyhood)[i] = 0; continue; } float similarity = cosine(val, ideal_plane); (*plane_likelyhood)[i] = similarity; } qDebug() << "eigen_plane_consine_similarity in " << (time_ = t_.elapsed()) << " ms"; // Correlate computeCorrelation(plane_likelyhood->data(), 1, plane_likelyhood->size(), sub_idxs); if(!visualise_on_) return; // Draw int h = cloud->scan_width(); int w = cloud->scan_height(); /* boost::shared_ptr<std::vector<Eigen::Vector3f> > grid = boost::make_shared<std::vector<Eigen::Vector3f> >(grid_to_cloud->size(), Eigen::Vector3f(0.0f, 0.0f, 0.0f)); for(int i = 0; i < grid_to_cloud->size(); i++) { int idx = (*grid_to_cloud)[i]; if(idx != -1) (*grid)[i] = (*pca)[idx]; } drawVector3f(grid, cloud); */ boost::shared_ptr<const std::vector<float>> img = cloudToGrid(cloud->cloudToGridMap(), w*h, plane_likelyhood); drawFloats(img, cloud); }
void FeatureEval::curvature(){ boost::shared_ptr<PointCloud> _cloud = core_->cl_->active_; if(_cloud == nullptr) return; pcl::PointCloud<pcl::PointXYZINormal>::Ptr filt_cloud; std::vector<int> big_to_small; filt_cloud = downsample(_cloud, subsample_res_, big_to_small); // Compute t_.start(); qDebug() << "Timer started (Curvature)"; pcl::PrincipalCurvaturesEstimation<pcl::PointXYZINormal, pcl::PointXYZINormal, pcl::PrincipalCurvatures> principal_curvatures_estimation; principal_curvatures_estimation.setInputCloud (filt_cloud); principal_curvatures_estimation.setInputNormals (filt_cloud); pcl::search::KdTree<pcl::PointXYZINormal>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZINormal>); principal_curvatures_estimation.setSearchMethod (tree); principal_curvatures_estimation.setRadiusSearch (search_radius_); pcl::PointCloud<pcl::PrincipalCurvatures>::Ptr principal_curvatures (new pcl::PointCloud<pcl::PrincipalCurvatures> ()); principal_curvatures_estimation.compute (*principal_curvatures); qDebug() << "Curvature in " << (time_ = t_.elapsed()) << " ms"; // Correlate size_t csize = sizeof(pcl::PrincipalCurvatures)/sizeof(float); computeCorrelation(reinterpret_cast<float*>(principal_curvatures->points.data()), 2, principal_curvatures->points.size(), big_to_small, csize, 3); if(!visualise_on_) return; // Draw int w = _cloud->scan_width(); int h = _cloud->scan_height(); boost::shared_ptr<std::vector<float>> grid = boost::make_shared<std::vector<float>>(w*h, 0.0f); const std::vector<int> & cloudtogrid = _cloud->cloudToGridMap(); for(uint big_idx = 0; big_idx < _cloud->size(); big_idx++) { int small_idx = big_to_small[big_idx]; int grid_idx = cloudtogrid[big_idx]; pcl::PrincipalCurvatures & pc = (*principal_curvatures)[small_idx]; (*grid)[grid_idx] = pc.pc1 + pc.pc2; } drawFloats(grid, _cloud); }
void FeatureEval::difference_of_normals(){ boost::shared_ptr<PointCloud> _cloud = core_->cl_->active_; if(_cloud == nullptr) return; int w = _cloud->scan_width(); int h = _cloud->scan_height(); pcl::PointCloud<pcl::Normal>::Ptr normals = ne_->getNormals(_cloud); float res1 = subsample_res_; float res2 = subsample_res_2_; // Downsample pcl::PointCloud<pcl::PointXYZINormal>::Ptr smaller_cloud; std::vector<int> sub_idxs; smaller_cloud = downsample(_cloud, res1, sub_idxs); t_.start(); pcl::PointCloud<pcl::Normal>::Ptr donormals = don(*smaller_cloud, *smaller_cloud, res1, res2); (time_ = t_.elapsed()); // Correlate computeCorrelation(reinterpret_cast<float*>(donormals->points.data()), 3, donormals->points.size(), sub_idxs, 4); if(!visualise_on_) return; // Draw pcl::PointCloud<pcl::Normal> big_donormals; map_small_to_big((*donormals).points, big_donormals.points, sub_idxs); const std::vector<int> & cloudtogrid = _cloud->cloudToGridMap(); boost::shared_ptr<std::vector<Eigen::Vector3f> > grid = boost::make_shared<std::vector<Eigen::Vector3f> >(w*h, Eigen::Vector3f(0.0f, 0.0f, 0.0f)); for(uint i = 0; i < normals->size(); i++){ int grid_idx = cloudtogrid[i]; (*grid)[grid_idx] = big_donormals[i].getNormalVector3fMap(); } // Draw drawVector3f(grid, _cloud); }
void FeatureEval::intensity(){ boost::shared_ptr<PointCloud> _cloud = core_->cl_->active_; if(_cloud == nullptr) return; // Subsample pcl::PointCloud<pcl::PointXYZINormal>::Ptr smaller_cloud; std::vector<int> sub_idxs; smaller_cloud = downsample(_cloud, subsample_res_, sub_idxs); time_ = 0; // Copy to contigious structure std::vector<float> tmp(smaller_cloud->size()); for(uint i = 0; i < smaller_cloud->size(); i++){ tmp[i] = smaller_cloud->points[i].intensity; } // Correlate computeCorrelation(reinterpret_cast<float*>(tmp.data()), 1, tmp.size(), sub_idxs); }
int main(int argc, char **argv) { TypePosition orderstart=1, orderend=10; char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g'; TypeSetOfSequences *set; TypeAlignment aln, atmp; int fixed = 0; double threshold = 0.001, tmin = 0.00000000001, tmax=0.1, tstep = 0.00001; double thre; TypeNumber n; TypeDistance distA, distB, distC; TypePosition l, tot; double corrAB, corrAC; TypeSetOfSequences *dec; TypeMarkovModel *model; FILE *fi, *fo; int i = 1, typeDist = 0; for(i=0; i<256; i++) option[i] = 0; for(i=1; i<argc && *(argv[i]) == '-'; i++) { int j; for(j=1; argv[i][j] != '\0'; j++) option[argv[i][j]] = 1; if(option['f']) { option['f'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1) i++; } if(option['s']) { option['s'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1) i++; } if(option['c']) { option['c'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1) i++; } if(option['m']) { option['m'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%d", &typeDist) == 1) i++; if(typeDist >= MAX_FUNC) typeDist = 0; } if(option['t']) { option['t'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1) i++; } if(option['h']) { printf("%s\n", HELPMESSAGE); exitProg(ExitOk, NULL); } } if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); switch(typeAlphabet) { case 'd': table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char)); strcpy(table, DNA); break; case 'r': table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char)); strcpy(table, RNA); break; case 'p': table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char)); strcpy(table, PRO); break; case '?': default: table = (char*) monmalloc(sizeof(char)); table[0] = '\0'; } if(fi = fopen(inputFileName, "r")) { aln = readAlignement(fi, table, typeAlphabet == '?'); switch(typeAlphabet) { case 'd': case 'r': aln.ambiguity = getXNAAmbiguity(); break; case 'p': aln.ambiguity = getProteinAmbiguity(); break; case '?': default: aln.ambiguity.number = 0; } aln.cardinal -= aln.ambiguity.number; fclose(fi); } else { exitProg(ErrorReading, inputFileName); } if(!(fo = fopen(outputFileName, "w"))) exitProg(ErrorWriting, outputFileName); fixAlignmentAmbiguity(&aln); set=toSequences(&aln); model = estimateMarkovModel(set); distA = computeWholeDistancePairAln(aln, computeNorm1Aln); dec = getDecodedFromThreshold(set, threshold, model); distB = computeWholeDistanceDec(dec); corrAB = computeCorrelation(distA, distB); //printf("%lE\n", corrAB); monfree((void*)distB.table); for(n=0; n<dec->number; n++) monfree((void*) dec->sequence[n]); monfree((void*) dec->sequence); monfree((void*) dec->size); monfree((void*) dec); distC = computeMSMDistance(set); corrAC = computeCorrelation(distA, distC); monfree((void*)distC.table); monfree((void*)distA.table); fprintf(fo, "%lE\t%lE\n", corrAB, corrAC); fprintf(stdout, "%lE\t%lE\n", corrAB, corrAC); monfree((void*)set->size); for(n=0; n<set->number; n++) monfree((void*)set->sequence[n]); monfree((void*)set->sequence); monfree((void*)set); fclose(fo); /* sprintf(bufferOutput, "%s_Ali.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distA); fclose(fo); sprintf(bufferOutput, "%s_New.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distB); fclose(fo); */ exitProg(ExitOk,NULL); return 0; }
void FeatureEval::intensity_histogram(){ boost::shared_ptr<PointCloud> _cloud = core_->cl_->active_; if(_cloud == nullptr) return; pcl::PointCloud<pcl::PointXYZINormal>::Ptr smaller_cloud; std::vector<int> sub_idxs; smaller_cloud = downsample(_cloud, subsample_res_, sub_idxs); // Compute t_.start(); qDebug() << "Timer started (Intensity histogram)"; boost::shared_ptr<std::vector<std::vector<float> > > hists = calcIntensityHist(*smaller_cloud, bins_, search_radius_, max_nn_); qDebug() << "Intensity histogram" << (time_ = t_.elapsed()) << " ms"; // Copy to contigious structure std::vector<float> tmp(bins_*smaller_cloud->size()); for(uint i = 0; i < smaller_cloud->size(); i++){ for(int j = 0; j < bins_; j++){ tmp[i*bins_+j] = (*hists)[i][j]; } } // Correlate computeCorrelation(tmp.data(), bins_, tmp.size(), sub_idxs); if(!visualise_on_) return; // Draw, TODO; Multidimentional draw boost::shared_ptr<std::vector<std::vector<float> > > hists2 = boost::make_shared<std::vector<std::vector<float> > >(_cloud->size()); // map back to cloud for(uint i = 0; i < _cloud->size(); i++) { int idx = sub_idxs[i]; (*hists2)[i] = (*hists)[idx]; } hists.reset(); boost::shared_ptr<const std::vector<int>> grid_to_cloud = _cloud->gridToCloudMap(); int w = _cloud->scan_width(); int h = _cloud->scan_height(); // in the grid, subtract (x, y+1) from every (x, y) boost::shared_ptr<std::vector<float>> diffs = boost::make_shared<std::vector<float>>(w*h, 0.0f); //auto distfunc = EuclidianDist; auto distfunc = KLDist; /* // Lambda auto maxval = [] (float * array, int size) { float max = FLT_MIN; for(int i = 0; i < size; i++) { if(array[i] > max) max = array[i]; } return max; }; */ const int feature_size = bins_; for(int x = 1; x < w-1; x ++) { //qDebug() << "yes"; for(int y = 1; y < h-1; y ++) { int center = (*grid_to_cloud)[x*h + y]; int up = (*grid_to_cloud)[x*h + y-1]; int down = (*grid_to_cloud)[x*h + y+1]; int left = (*grid_to_cloud)[(x-1)*h + y]; int right = (*grid_to_cloud)[(x+1)*h + y]; (*diffs)[center] = 0; if(center == -1){ continue; } // NB! assumed histograms are normalised if(up != -1 && down != -1){ float * feature1 = &((*hists2)[up][0]); float * feature2 = &((*hists2)[down][0]); //float max1 = maxval(feature1, feature_size); //float max2 = maxval(feature2, feature_size); //(*diffs)[center] += fabs(max1 - max2); (*diffs)[center] += distfunc(feature1, feature2, feature_size); } if(left != -1 && right != -1){ float * feature1 = &((*hists2)[left][0]); float * feature2 = &((*hists2)[right][0]); //float max1 = maxval(feature1, feature_size); //float max2 = maxval(feature2, feature_size); //(*diffs)[center] += fabs(max1 - max2); (*diffs)[center] += distfunc(feature1, feature2, feature_size); } } } boost::shared_ptr<const std::vector<float>> img = cloudToGrid(_cloud->cloudToGridMap(), w*h, diffs); drawFloats(img, _cloud); hists2.reset(); }
// PCA for each point, ratio of eigen values void FeatureEval::pca_eigen_value_ratio(){ boost::shared_ptr<PointCloud> cloud = core_->cl_->active_; if(cloud == nullptr) return; // Downsample std::vector<int> sub_idxs; pcl::PointCloud<pcl::PointXYZI>::Ptr smaller_cloud = octreeDownsample(cloud.get(), subsample_res_, sub_idxs); // Compute PCA t_.start(); qDebug() << "Timer started (PCA and speculaion)"; boost::shared_ptr<std::vector<Eigen::Vector3f> > pca = getPCA(smaller_cloud.get(), search_radius_, max_nn_); // Compute ratio boost::shared_ptr<std::vector<float>> likely_veg = boost::make_shared<std::vector<float>>(pca->size(), 0.0f); for(uint i = 0; i < pca->size(); i++) { Eigen::Vector3f eig = (*pca)[i]; // Not enough neighbours if(eig[1] < eig[2]) { (*likely_veg)[i] = 0; continue; } /* float eig_sum = eig.sum(); eig /= eig_sum; float fudge_factor = 5.0f; bool is_planar = eig[1] < 0.05 * fudge_factor || eig[2] < 0.01 * fudge_factor; if(!is_planar) { (*likely_veg)[i] = 0; } else { (*likely_veg)[i] = 1; } */ float curvature; if(eig[0] > eig[2]) curvature = eig[1] / (eig[0]); else curvature = 1; (*likely_veg)[i] = curvature; } qDebug() << "PCA in " << (time_ = t_.elapsed()) << " ms"; computeCorrelation(likely_veg->data(), 1, likely_veg->size(), sub_idxs); if(!visualise_on_) return; // Draw int h = cloud->scan_width(); int w = cloud->scan_height(); boost::shared_ptr<std::vector<float>> likely_veg2 = boost::make_shared<std::vector<float>>(cloud->size(), 0.0f); for(uint i = 0; i < cloud->size(); i++) { uint subidx = sub_idxs[i]; (*likely_veg2)[i] = (*likely_veg)[subidx]; } boost::shared_ptr<const std::vector<float>> img = cloudToGrid(cloud->cloudToGridMap(), w*h, likely_veg2); drawFloats(img, cloud); }
int main(int argc, char **argv) { TypePosition orderstart=1, orderend=10; char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g', type = 't'; TypeSetOfSequences *set, seq; TypeAlignment aln, atmp; int fixed = 0; double threshold = 0.001, tmin = 1E-20, tmax=0.1, tstep = 0.00001, qmin = -25, qmax = -3, qprec = 0.5; double thre; TypeNumber n; TypeDistance distA, distB; TypePosition l, tot, lmax = 50; TypeSuffixTree *suffixTree; TypeMarkovModel *model; TypeCodeScheme *scheme; /* TypeDistFunction *distfunc[MAX_FUNC]= {computeProba, computeKullbackLeiber1, computePham, computeCommon, computeCommonBis, computeGillesPham, computeMatchesBis, computeMatches, computeAlex, computeAlexBis}; */ FILE *fi, *fo; int i = 1, typeDist = 0; for(i=0; i<256; i++) option[i] = 0; for(i=1; i<argc && *(argv[i]) == '-'; i++) { int j; for(j=1; argv[i][j] != '\0'; j++) option[argv[i][j]] = 1; if(option['f']) { option['f'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1) i++; } if(option['s']) { option['s'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1) i++; } if(option['c']) { option['c'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1) i++; } if(option['m']) { option['m'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &tmin) == 1) i++; if(typeDist >= MAX_FUNC) typeDist = 0; } if(option['t']) { option['t'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1) i++; } if(option['y']) { option['y'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &type) == 1) i++; } if(option['h']) { printf("%s\n", HELPMESSAGE); exitProg(ExitOk, NULL); } } if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); switch(typeAlphabet) { case 'd': table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char)); strcpy(table, DNA); break; case 'r': table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char)); strcpy(table, RNA); break; case 'p': table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char)); strcpy(table, PRO); break; case '?': default: table = (char*) monmalloc(sizeof(char)); table[0] = '\0'; } if(fi = fopen(inputFileName, "r")) { aln = readAlignement(fi, table, typeAlphabet == '?'); switch(typeAlphabet) { case 'd': case 'r': aln.ambiguity = getXNAAmbiguity(); break; case 'p': aln.ambiguity = getProteinAmbiguity(); break; case '?': default: aln.ambiguity.number = 0; } aln.cardinal -= aln.ambiguity.number; fclose(fi); } else { exitProg(ErrorReading, inputFileName); } fixAlignmentAmbiguity(&aln); set=toSequences(&aln); if(!(fo = fopen(outputFileName, "w"))) exitProg(ErrorWriting, outputFileName); distA = computeWholeDistancePairAln(aln, computeNorm1Aln); scheme = (TypeCodeScheme*) monmalloc(sizeof(TypeCodeScheme)); scheme->suffixTree = getSuffixTree(set); scheme->code = (TypePosition*) monmalloc(scheme->suffixTree->size*sizeof(TypePosition)); scheme->buffSize = INC_SIZE_CODE; scheme->lengthCode = (TypePosition*) monmalloc(scheme->buffSize*sizeof(TypePosition)); if(type == 't') { int l; model = estimateMarkovModel(set); // for(thre=tmin; thre<=tmax; thre *= 10.0) { for(l=tmin; l<=-1; l++) { double t; int k; thre = pow(10.0, (double) l); for(k=0; k<10; k++) { // for(t=thre; t<thre*10; t+=thre) { double corr, sc; TypeSetOfSequences *dec; t = ((double)k+1.)*thre; scheme->cardCode = 0; buildCodeThreshold(t, scheme->suffixTree->root, 0, 1., model, scheme); //printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode); dec = getDecodedFromScheme(scheme); //printf("cardinal dec = %ld\n", dec->cardinal); distB = computeWholeDistanceDec(dec); corr = computeCorrelation(distA, distB); monfree((void*)distB.table); sc = score(dec); printf("%lE\t%lf\t%.2lf\n", t, corr, sc); fprintf(fo, "%lE\t%lf\t%.2lf\n", t, corr, sc); for(n=0; n<dec->number; n++) monfree((void*) dec->sequence[n]); monfree((void*) dec->sequence); monfree((void*) dec->size); monfree((void*) dec); } } fprintf(stdout, "\n\n%.4lE\n\n", findMode(set, qmin, qmax, qprec, scheme, model)); freeModel(model); } else { for(l = lmax; l>=1; l--) { double corr; TypeSetOfSequences *dec; scheme->cardCode = 0; buildCodeLength(l, scheme->suffixTree->root, 0, scheme); //printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode); dec = getDecodedFromScheme(scheme); //printf("cardinal dec = %ld\n", dec->cardinal); distB = computeWholeDistanceDec(dec); corr = computeCorrelation(distA, distB); monfree((void*)distB.table); fprintf(fo, "%ld\t%lf\n", l, corr); fprintf(stdout, "%ld\t%lf\n", l, corr); for(n=0; n<dec->number; n++) monfree((void*) dec->sequence[n]); monfree((void*) dec->sequence); monfree((void*) dec->size); monfree((void*) dec); } } freeScheme(scheme); monfree((void*)distA.table); fprintf(stdout, "\n\n%ld\n\n", totalLength(*set)); monfree((void*)set->size); for(n=0; n<set->number; n++) monfree((void*)set->sequence[n]); monfree((void*)set->sequence); monfree((void*)set); fclose(fo); /* sprintf(bufferOutput, "%s_Ali.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distA); fclose(fo); sprintf(bufferOutput, "%s_New.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distB); fclose(fo); */ ; exitProg(ExitOk,NULL); return 0; }
/*! * \fn int main(int argc, char *argv[]) * \ingroup main * * \brief This is the main of the software. * \param[in] argc : An integer which represents the number of arguments passed to the line command. * \param[in] argv : An array of character which represents all the arguments. */ int main(int argc, char *argv[]) { Data* data; std::list<Solution> allSolution; long int nbToCompute; long int nbWithNeighbor; long int nbSolLS(0); long int boxBeforeFitlering(0); long int boxAfterFiltering(0); long int boxAfterReconstruction(0); long int numberBoxComputed(0); long double boxTotal(0); //Time strucure struct timeval start, end, beginB, endB, beginBF, endBF, beginRC, endRC, beginLS, endLS; //## READING ARGUMENTS ## Argument::parse( argc, argv ); if ( Argument::help ) { Argument::usage( argv[0] ); return 0; } else if ( Argument::filename.empty() ) { std::cout << "Type for help : " << argv[0] << " --help" << std::endl; return 0; } if (Argument::verbose) { Argument::print( std::clog ); } //## END READING ARGUMENTS ## std::srand( Argument::random_seed ); data = Parser::Parsing(Argument::filename); if (Argument::mode_export) { ToFile::removeFiles(); computeCorrelation(*data); } if (Argument::verbose) { std::clog << std::endl << "+" << std::setfill('-') << std::setw(15) << "+" << " INSTANCE " << "+" << std::setw(16) << "+" << std::endl << std::setfill(' ') << " " << std::setw(20) << std::left << "Name " << "|" << std::setw(20) << std::right << data->getFileName() << " " << std::endl << " " << std::setw(20) << std::left << "Facility " << "|" << std::setw(20) << std::right << data->getnbFacility() << " " << std::endl << " " << std::setw(20) << std::left << "Customer " << "|" << std::setw(20) << std::right << data->getnbCustomer() << " " << std::endl << " " << std::setw(20) << std::left << "Correlation " << "|" << std::setw(20) << std::right << computeCorrelation(*data) << " " << std::endl << "+" << std::setfill('-') << std::setw(42) << "+" << std::endl << std::endl; } gettimeofday(&start, 0); //############################# //## Functions to create Box ## boxTotal = std::pow((long double)2, (int)data->getnbFacility() )-1; std::vector<Box*> vectorBox; gettimeofday(&beginB, 0); numberBoxComputed = createBox(vectorBox, *data); boxBeforeFitlering = vectorBox.size(); gettimeofday(&endB, 0); if (Argument::verbose) { std::clog << "+" << std::setfill('-') << std::setw(18) << "+" << " BOX " << "+" << std::setw(18) << "+" << std::endl << std::setfill (' ') << "+" << std::setfill(' ') << std::setw(10) << " " << " ! before filtering ! " << " " << std::setw(9) << "+" << std::endl << " " << std::setw(20) << std::left << "Box Total " << "|" << std::setw(20) << std::right << boxTotal << " " << std::endl << " " << std::setw(20) << std::left << "Box Computed " << "|" << std::setw(20) << std::right << numberBoxComputed << " " << std::endl << " " << std::setw(20) << std::left << "Box Non-Dominated" << "|" << std::setw(20) << std::right << boxBeforeFitlering << " " << std::endl << " " << std::setw(20) << std::left << "Time (ms) " << "|" << std::setw(20) << std::right << (1000*time_s_Diff(beginB,endB) + time_ms_Diff(beginB,endB)) << " " << std::endl << "+" << std::setfill('-') << std::setw(42) << "+" << std::endl << std::endl; } //################################################## //## Functions to filter Boxes and reconstruction ## std::vector<Box*> vectorBoxFinal; if (Argument::filtering) { gettimeofday(&beginBF, 0); boxFiltering(vectorBox, *data, nbToCompute, nbWithNeighbor); gettimeofday(&endBF, 0); boxAfterFiltering = vectorBox.size(); if (Argument::reconstruction) { gettimeofday(&beginRC, 0); recomposition(vectorBox, vectorBoxFinal, *data, nbToCompute, nbWithNeighbor); gettimeofday(&endRC, 0); boxAfterReconstruction = vectorBoxFinal.size(); } else { vectorBoxFinal = vectorBox; } if (Argument::verbose) { std::clog << "+" << std::setfill('-') << std::setw(13) << "+" << " BOX FILTERING " << "+" << std::setw(13) << "+" << std::endl << std::setfill(' ') << "+" << std::setfill(' ') << std::setw(10) << " " << " ! after filtering ! " << " " << std::setw(9) << "+" << std::endl << " " << std::setw(20) << std::left << "Box " << "|" << std::setw(20) << std::right << boxAfterFiltering << " " << std::endl << " " << std::setw(20) << std::left << "Time (ms) " << "|" << std::setw(20) << std::right << (1000*time_s_Diff(beginBF,endBF) + time_ms_Diff(beginBF,endBF)) << " " << std::endl; if (Argument::reconstruction) { std::clog << "+" << std::setfill(' ') << std::setw(8) << " " << " ! after reconstruction ! " << " " << std::setw(6) << "+" << std::endl << " " << std::setw(20) << std::left << "Box " << "|" << std::setw(20) << std::right << boxAfterReconstruction << " " << std::endl << " " << std::setw(20) << std::left << "Time (ms) " << "|" << std::setw(20) << std::right << (1000*time_s_Diff(beginRC,endRC) + time_ms_Diff(beginRC,endRC)) << " " << std::endl; } std::clog << "+" << std::setfill('-') << std::setw(42) << "+" << std::endl << std::endl; } } else { vectorBoxFinal = vectorBox; } //########################### //## LABEL SETTING or MOGA ## if ( Argument::moga ) { gettimeofday(&beginLS, 0); nbSolLS = runMOGA(vectorBoxFinal, *data, allSolution); gettimeofday(&endLS, 0); } else // use Label Setting { gettimeofday(&beginLS, 0); nbSolLS = runLabelSetting(vectorBoxFinal, *data, allSolution); gettimeofday(&endLS, 0); } if (Argument::verbose) { std::clog << "+" << std::setfill('-') << std::setw(Argument::moga?17:13) << "+" << (Argument::moga ? " MOGA " : " LABEL SETTING ") << "+" << std::setw(Argument::moga?18:13) << "+" << std::endl << std::setfill (' ') << " " << std::setw(20) << std::left << "Sol computed " << "|" << std::setw(20) << std::right << nbSolLS << " " << std::endl << " " << std::setw(20) << std::left << "Time (ms) " << "|" << std::setw(20) << std::right << (1000*time_s_Diff(beginLS,endLS) + time_ms_Diff(beginLS,endLS)) << " " << std::endl << "+" << std::setfill('-') << std::setw(42) << "+" << std::endl; } //######### //## END ## gettimeofday(&end, 0); std::clog << std::endl << "+" << std::setfill('-') << std::setw(15) << "+" << " SYNTHESIS " << "+" << std::setw(15) << "+" << std::endl << std::setfill(' ') << " " << std::setw(20) << std::left << "Instance " << "|" << std::setw(20) << std::right << data->getFileName() << " " << std::endl << " " << std::setw(20) << std::left << "Solutions " << "|" << std::setw(20) << std::right << nbSolLS << " " << std::endl << " " << std::setw(20) << std::left << "Total Time (ms) " << "|" << std::setw(20) << std::right << (1000*time_s_Diff(start,end) + time_ms_Diff(start,end)) << " " << std::endl << "+" << std::setfill('-') << std::setw(42) << "+" << std::endl << std::endl; if (Argument::mode_export) { if( system("./plot/plot.sh") != 0 ) { std::cerr << " Failure in the execution of the script " << std::endl; } } else { std::list<Solution>::iterator iter; for ( iter = allSolution.begin(); iter != allSolution.end(); ++iter ) { for (int k = 0; k < (*iter).getNbObjective(); ++k) { if (k > 0) std::cout << ' '; std::cout << (*iter).getObj(k); } std::cout << std::endl; } } vectorBox.clear(); vectorBoxFinal.clear(); delete data; return 0; }