Xmipp  v3.23.11-Nereus
classify_evaluate_classes.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Authors: Carlos Oscar Sorzano (coss@cnb.csic.es)
3  *
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
28 
30 {
31  FRC_05=DPR_05=0;
32  overfitting=false;
33 }
34 
36 {
37  eval.FRC_05=0;
38  eval.DPR_05=0;
39  if (MD.size()<10)
40  return;
41 
42  MetaDataVec MDrandomized;
43  std::vector<MetaDataVec> vMD;
44  MultidimArray<double> I0, I1, freq, frc, dpr, frc_noise, error_l2;
45 
46  // Compute FRC
47  MDrandomized.randomize(MD);
48  MDrandomized.split(2,vMD,MDL_IMAGE);
49  getAverageApplyGeo(vMD[0],I0);
50  getAverageApplyGeo(vMD[1],I1);
51  I0.setXmippOrigin();
52  I1.setXmippOrigin();
53  frc_dpr(I0, I1, 1, freq, frc, frc_noise, dpr, error_l2, true);
54 
55  // Compute the frequency of FRC=0.5
56  int i_05=-1;
58  if (dAi(frc,i)<0.5)
59  {
60  i_05=i;
61  break;
62  }
63  if (i_05==-1)
64  {
65  i_05=XSIZE(frc)-1;
66  eval.overfitting=true;
67  }
68 
69  // Extract evaluators
70  eval.FRC_05=dAi(freq,i_05);
71  eval.DPR_05=dAi(dpr,i_05);
72 }
73 
74 // Evaluate classes program -------------------------------------------
76 {
77  fnClass=getParam("-i");
78  fnOut=getParam("-o");
79 }
80 
82 {
83  addUsageLine("Evaluate the quality of a set of classes");
84  addUsageLine("+The program associates to each class a number of quality measures:");
85  addUsageLine("+");
86  addUsageLine("+FRC_05 is the digital frequency (<0.5) at which the Fourier Ring Correlation drops below 0.5 ");
87  addUsageLine("+(to convert from a digital frequency to one measured in Angstrom invert the digital frequency and multiply by the sampling rate).");
88  addUsageLine("+");
89  addUsageLine("+DPR_05 is the Differential Phase Residual at the frequency of FRC_05");
90  addParamsLine(" -i <infile> : Metadata with the classification (normally the output of CL2D or ML2D)");
91  addParamsLine(" [-o <outfile=\"\">] : Output file");
92  addExampleLine("xmipp_classify_evaluate_classes -i 2D/CL2D/run_001/results_level_00_classes.xmd");
93 }
94 
96 {
97  if (!verbose)
98  return;
99  std::cout
100  << "Input: " << fnClass << std::endl
101  << "Output: " << fnOut << std::endl;
102 }
103 
105 {
106  MetaDataVec MD((String)"classes@"+fnClass), MDclass;
107  ClassEvaluation eval;
108  if (verbose>0)
109  init_progress_bar(MD.size());
110  int idx=0;
111  for (size_t objId : MD.ids())
112  {
113  int classNo;
114  MD.getValue(MDL_REF,classNo,objId);
115  MDclass.read(formatString("class%06d_images@%s",classNo,fnClass.c_str()));
116  evaluateClass(MDclass,eval);
117  MD.setValue(MDL_CLASSIFICATION_FRC_05,eval.FRC_05,objId);
118  MD.setValue(MDL_CLASSIFICATION_DPR_05,eval.DPR_05,objId);
119  idx++;
120  if (verbose>0)
121  progress_bar(idx);
122  }
123  if (verbose>0)
124  progress_bar(MD.size());
125  if (fnOut=="")
126  fnOut=fnClass;
127  MD.write((String)"classes@"+fnOut,MD_APPEND);
128 }
#define dAi(v, i)
void init_progress_bar(long total)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
void defineParams()
Define input parameters.
void readParams()
Read input parameters.
void split(size_t n, std::vector< MetaDataVec > &results, const MDLabel sortLabel=MDL_OBJID) const
void frc_dpr(MultidimArray< double > &m1, MultidimArray< double > &m2, double sampling_rate, MultidimArray< double > &freq, MultidimArray< double > &frc, MultidimArray< double > &frc_noise, MultidimArray< double > &dpr, MultidimArray< double > &error_l2, bool dodpr, bool doRfactor, double minFreq, double maxFreq, double *rFactor)
Definition: xmipp_fftw.cpp:491
void randomize(const MetaData &MDin)
#define i
FileName fnOut
#define XSIZE(v)
void progress_bar(long rlen)
void evaluateClass(MetaData &MD, ClassEvaluation &eval)
Digital frequency at which the FRC drops below 0.5 (double)
virtual size_t size() const =0
Class to which the image belongs (int)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
Class containing evaluators.
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
void getAverageApplyGeo(const MetaData &md, MultidimArray< double > &_ave, MDLabel image_label)
Name of an image (std::string)
Differential Phase Residual evaluated at FRC=0.5.