33 out << block.
block <<
"@" << block.
fnLevel <<
" -> level " << block.
level << std::endl;
41 if (!
node->isMaster())
72 std::cout <<
"CL2D rootname: " <<
fnRoot << std::endl
73 <<
"CL2D output dir: " <<
fnODir << std::endl;
75 std::cout <<
"Tolerance: " <<
tolerance << std::endl;
77 std::cout <<
"Threshold PCA Zscore: " <<
thPCAZscore << std::endl
78 <<
"Number of PCA dimensions: " <<
NPCA << std::endl;
87 addParamsLine(
" --computeCore <thPCAZscore=3> <NPCA=2>: The class cores are computed by thresholding the Zscore of");
88 addParamsLine(
" : the class images and their projections onto a nD PCA space (by default, n=2)");
89 addParamsLine(
"or --computeStableCore <tolerance=1> : The stable core is formed by all the images in the class that have been");
90 addParamsLine(
" : in the same class (except in tolerance levels) in the whole hierarchy.");
91 addParamsLine(
" : If tolerance=0, then the stable core is formed by the set of images that");
92 addParamsLine(
" : have been always together. For this reason, the stable core can be computed only");
94 addExampleLine(
"mpirun -np 4 `which xmipp_mpi_classify_CL2D_core_analysis` -i 2D/CL2D/run_001/results --computeCore");
95 addExampleLine(
"mpirun -np 4 `which xmipp_mpi_classify_CL2D_core_analysis` -i 2D/CL2D/run_001/results --computeStableCore");
114 for (
int level=0; level<=
maxLevel; level++)
121 for (
size_t i=0;
i<blocksAux.size();
i++)
123 if (blocksAux[
i].
find(
"class")!=std::string::npos &&
124 blocksAux[
i].find(
"images")!=std::string::npos)
133 size_t Nblocks=
blocks.size();
148 std::cerr <<
"Computing cores ...\n";
152 analyzeCluster.
Niter=10;
158 size_t Nblocks=
blocks.size();
162 for (
size_t idx=first; idx<=last; ++idx)
168 analyzeCluster.
run();
190 std::cerr <<
"Computing stable cores ...\n";
191 MetaDataDb thisClass, anotherClass, commonImages, thisClassCore;
195 int Nblocks=
blocks.size();
197 std::vector<size_t> commonIdx;
198 std::map<String,size_t> thisClassOrder;
201 for (
size_t idx=first; idx<=last; ++idx)
210 thisClassCore.
clear();
213 if (thisClass.
size()>0)
216 thisClassOrder.clear();
217 for (
size_t objId : thisClass.
ids())
220 thisClassOrder[fnImg]=order++;
224 size_t NthisClass=thisClass.
size();
228 coocurrence.
initZeros(NthisClass,NthisClass);
231 std::cerr << e.what() << std::endl;
232 std::cerr <<
"There is a memory allocation error. Most likely there are too many images in this class (" 233 << NthisClass <<
" images). Consider increasing the number of initial and final classes\n";
236 for (
int n=0;
n<Nblocks;
n++)
246 commonIdx.resize(commonImages.
size());
248 for (
size_t objId : commonImages.
ids())
251 commonIdx[idx++]=thisClassOrder[fnImg];
253 size_t Ncommon=commonIdx.size();
254 for (
size_t i=0;
i<Ncommon;
i++)
256 size_t idx_i=commonIdx[
i];
257 for (
size_t j=
i+1;
j<Ncommon;
j++)
259 size_t idx_j=commonIdx[
j];
260 MAT_ELEM(coocurrence,idx_i,idx_j)+=1;
267 maximalCoocurrence.
initZeros(NthisClass);
270 if (
MAT_ELEM(coocurrence,
i,
j)==aimedCoocurrence)
274 for (
size_t objId : thisClass.
ids())
277 size_t idx=thisClassOrder[fnImg];
278 if (
VEC_ELEM(maximalCoocurrence,idx))
295 FileName fnBlock, fnClass, fnSummary, fnSummaryOriginal;
299 int Nblocks=
blocks.size();
300 for (
int level=firstLevel; level<=
maxLevel; level++)
304 for (
int idx=0; idx<Nblocks; idx++)
306 if (
blocks[idx].level!=level)
308 fnBlock=fnSummary+
"_"+
blocks[idx].block+
".xmd";
314 size_t classSize=MD.
size();
315 fnClass.
compose(classNo,fnSummary,
"stk");
319 classAverage().initZeros(
Ydim,
Xdim);
320 classAverage.
write(fnClass);
329 classes.
write((
String)
"classes@"+fnSummary+
".xmd");
333 for (
int idx=0; idx<Nblocks; idx++)
336 fnBlock=fnSummary+
"_"+
blocks[idx].block+
".xmd";
340 unlink(fnBlock.c_str());
355 int Nblocks=
blocks.size();
358 for (
int idx=0; idx<Nblocks; idx++)
363 MDoriginal.
read(fnSummaryOriginal);
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
ProgClassifyCL2DCore(int argc, char **argv)
Empty constructor.
void init_progress_bar(long total)
double getDoubleParam(const char *param, int arg=0)
void computeCores()
Remove outliers.
#define REPORT_ERROR(nerr, ErrormMsg)
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
FileName insertBeforeExtension(const String &str) const
There is not enough memory for allocation.
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void compose(const String &str, const size_t no, const String &ext="")
String integerToString(int I, int _width, char fill_with)
std::vector< String > StringVector
void produceSideInfo()
Produce side info.
#define MAT_ELEM(m, i, j)
int argc
Original command line arguments.
std::ostream & operator<<(std::ostream &out, const CL2DBlock &block)
Show CL2Dblock.
const char * getParam(const char *param, int arg=0)
void progress_bar(long rlen)
std::unique_ptr< MpiTaskDistributor > taskDistributor
void addExampleLine(const char *example, bool verbatim=true)
void produceClassInfo()
Produce class input format.
void defineParams()
Usage.
int verbose
Verbosity level.
void computeStableCores()
Compute cores.
void gatherResults(int firstLevel, const String &suffix)
Gather results.
std::vector< CL2DBlock > blocks
void readParams()
Read argument from command line.
bool fileExists(const char *filename)
String formatString(const char *format,...)
int textToInteger(const char *str)
bool checkParam(const char *param)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)
std::shared_ptr< MpiNode > node
ClassifyCL2DCoreAction action