// Init random ............................................................. void FileName::initRandom(int length) { randomize_random_generator(); *this = ""; for (int i = 0; i < length; i++) *this += 'a' + FLOOR(rnd_unif(0, 26)); }
/* MAIN -------------------------------------------------------------------- */ int main(int argc, char *argv[]) { ProgTestWork program; program.read(argc, argv); //init random seed randomize_random_generator(); program.tryRun(); return 0; }
/* Compute tilting angle --------------------------------------------------- */ void TiltPairAligner::computeGamma() { #define TRIANGLE_NO 15000 #define MIN_AREA 15 #define MAX_AREA 250000 gamma = 0; Matrix1D<int> iju(2), iku(2), ijt(2), ikt(2); // From i to j in untilted // From i to k in untilted // From i to j in tilted // From i to k in tilted int triang = 0; // Number of triangles considered int i, j, k, counter1; counter1 = 0; randomize_random_generator(); long noCombinations; noCombinations = Nu * (Nu - 1) * (Nu - 2) / 6; while (triang < TRIANGLE_NO && counter1 < noCombinations) { counter1++; i = (int)round(rnd_unif(0, Nu - 1)); j = (int)round(rnd_unif(0, Nu - 1)); k = (int)round(rnd_unif(0, Nu - 1)); // Compute area of triangle in untilted micrograph VECTOR_R2(iju, coordU[j] - coordU[i], coordU[j+1] - coordU[i+1]); VECTOR_R2(iku, coordU[k] - coordU[i], coordU[k+1] - coordU[i+1]); double untilted_area = fabs(dotProduct(iju, iku)/*/2*/); if (untilted_area < MIN_AREA ) continue; // For numerical stability // Compute area of the same triangle in the tilted micrograph VECTOR_R2(ijt, coordT[j] - coordT[i], coordT[j+1] - coordT[i+1]); VECTOR_R2(ikt, coordT[k] - coordT[i], coordT[k+1] - coordT[i+1]); double tilted_area = fabs(dotProduct(ijt, ikt)/*/2*/); if (tilted_area < MIN_AREA ) continue; // For numerical stability if (tilted_area > MAX_AREA ) continue; // micrograph are not perfect // sheets so avoid // very far away particles // Now we know that tilted_area=untilted_area*cos(gamma) if (tilted_area > untilted_area) continue; // There are user errors // In the point selection gamma += acos(tilted_area / untilted_area); triang++; } gamma /= triang; gamma = RAD2DEG(gamma); if (triang < 100) std::cout << "Not many particles, tilt angle may not be accurate" << std::endl; }
void readParams() { XmippMetadataProgram::readParams(); min_val = getDoubleParam("--range", 0); max_val = getDoubleParam("--range", 1); sigma = getDoubleParam("--noise"); randomize_random_generator(); if (checkParam("--mask")) { mask_prm.allowed_data_types = INT_MASK; mask_prm.readParams(this); } }
void ProgValidationNonTilt::run() { //Clustering Tendency and Cluster Validity Stephen D. Scott randomize_random_generator(); MetaData md,mdGallery,mdOut,mdOut2,mdSort; MDRow row; FileName fnOut,fnOut2, fnGallery; fnOut = fnDir+"/clusteringTendency.xmd"; fnGallery = fnDir+"/gallery.doc"; fnOut2 = fnDir+"/validation.xmd"; size_t nSamplesRandom = 500; md.read(fnParticles); mdGallery.read(fnGallery); mdSort.sort(md,MDL_IMAGE_IDX,true,-1,0); size_t maxNImg; size_t sz = md.size(); if (useSignificant) mdSort.getValue(MDL_IMAGE_IDX,maxNImg,sz); else { mdSort.getValue(MDL_ITEM_ID,maxNImg,sz); } String expression; MDRow rowP,row2; SymList SL; int symmetry, sym_order; SL.readSymmetryFile(fnSym.c_str()); SL.isSymmetryGroup(fnSym.c_str(), symmetry, sym_order); /* double non_reduntant_area_of_sphere = SL.nonRedundantProjectionSphere(symmetry,sym_order); double area_of_sphere_no_symmetry = 4.*PI; double correction = std::sqrt(non_reduntant_area_of_sphere/area_of_sphere_no_symmetry); */ double correction = 1; double validation = 0; double num_images = 0; MetaData tempMd; std::vector<double> sum_u(nSamplesRandom); double sum_w=0; std::vector<double> H0(nSamplesRandom); std::vector<double> H(nSamplesRandom); std::vector<double> p(nSamplesRandom); if (rank==0) init_progress_bar(maxNImg); for (size_t idx=0; idx<=maxNImg;idx++) { if ((idx)%Nprocessors==rank) { if (useSignificant) expression = formatString("imageIndex == %lu",idx); else expression = formatString("itemId == %lu",idx); tempMd.importObjects(md, MDExpression(expression)); if (tempMd.size()==0) continue; //compute H_0 from noise obtainSumU_2(mdGallery, tempMd,sum_u,H0); //compute H from experimental obtainSumW(tempMd,sum_w,sum_u,H,correction); std::sort(H0.begin(),H0.end()); std::sort(H.begin(),H.end()); double P = 0; for(size_t j=0; j<sum_u.size();j++) { //P += H0.at(j)/H.at(j); P += H0.at(size_t((1-significance_noise)*nSamplesRandom))/H.at(j); p.at(j) = H0.at(j)/H.at(j); } P /= (nSamplesRandom); if (useSignificant) rowP.setValue(MDL_IMAGE_IDX,idx); else rowP.setValue(MDL_ITEM_ID,idx); rowP.setValue(MDL_WEIGHT,P); mdPartial.addRow(rowP); tempMd.clear(); if (rank==0) progress_bar(idx+1); } } if (rank==0) progress_bar(maxNImg); synchronize(); gatherClusterability(); if (rank == 0) { mdPartial.write(fnOut); std::vector<double> P; mdPartial.getColumnValues(MDL_WEIGHT,P); for (size_t idx=0; idx< P.size();idx++) { if (P[idx] > 1) validation += 1.; num_images += 1.; } validation /= (num_images); row2.setValue(MDL_IMAGE,fnInit); row2.setValue(MDL_WEIGHT,validation); mdOut2.addRow(row2); mdOut2.write(fnOut2); } }
void ProgValidationNonTilt::run() { //Clustering Tendency and Cluster Validity Stephen D. Scott randomize_random_generator(); //char buffer[400]; //sprintf(buffer, "xmipp_reconstruct_significant -i %s --initvolumes %s --odir %s --sym %s --iter 1 --alpha0 %f --angularSampling %f",fnIn.c_str(), fnInit.c_str(),fnDir.c_str(),fnSym.c_str(),alpha0,angularSampling); //system(buffer); MetaData md,mdOut,mdOut2; FileName fnMd,fnOut,fnOut2; fnMd = fnDir+"/angles_iter001_00.xmd"; fnOut = fnDir+"/clusteringTendency.xmd"; fnOut2 = fnDir+"/validation.xmd"; size_t nSamplesRandom = 250; md.read(fnMd); size_t maxNImg; size_t sz = md.size(); md.getValue(MDL_IMAGE_IDX,maxNImg,sz); String expression; MDRow rowP,row2; SymList SL; int symmetry, sym_order; SL.readSymmetryFile(fnSym.c_str()); SL.isSymmetryGroup(fnSym.c_str(), symmetry, sym_order); double non_reduntant_area_of_sphere = SL.nonRedundantProjectionSphere(symmetry,sym_order); double area_of_sphere_no_symmetry = 4.*PI; double correction = std::sqrt(non_reduntant_area_of_sphere/area_of_sphere_no_symmetry); double validation = 0; MetaData tempMd; std::vector<double> sum_u(nSamplesRandom); //std::vector<double> sum_w(nSamplesRandom); double sum_w=0; std::vector<double> H0(nSamplesRandom); std::vector<double> H(nSamplesRandom); if (rank==0) init_progress_bar(maxNImg); for (size_t idx=0; idx<=maxNImg;idx++) { if ((idx+1)%Nprocessors==rank) { expression = formatString("imageIndex == %lu",idx); tempMd.importObjects(md, MDExpression(expression)); if (tempMd.size()==0) continue; //compute H_0 from noise obtainSumU(tempMd,sum_u,H0); //compute H from experimental obtainSumW(tempMd,sum_w,sum_u,H,correction); std::sort(H0.begin(),H0.end()); std::sort(H.begin(),H.end()); double P = 0; for(size_t j=0; j<sum_u.size();j++) P += H0.at(j)/H.at(j); P /= (nSamplesRandom); rowP.setValue(MDL_IMAGE_IDX,idx); rowP.setValue(MDL_WEIGHT,P); mdPartial.addRow(rowP); //sum_u.clear(); //sum_w.clear(); //H0.clear(); //H.clear(); tempMd.clear(); if (rank==0) progress_bar(idx+1); } } if (rank==0) progress_bar(maxNImg); synchronize(); gatherClusterability(); if (rank == 0) { mdPartial.write(fnOut); std::vector<double> P; mdPartial.getColumnValues(MDL_WEIGHT,P); for (size_t idx=0; idx< P.size();idx++) { if (P[idx] > 1) validation += 1; } validation /= (maxNImg+1); } row2.setValue(MDL_IMAGE,fnInit); row2.setValue(MDL_WEIGHT,validation); mdOut2.addRow(row2); mdOut2.write(fnOut2); }