Xmipp  v3.23.11-Nereus
Classes | Functions | Variables
Collaboration diagram for without tilt:

Classes

class  ProgValidationNonTilt
 

Functions

void ProgValidationNonTilt::readParams ()
 
void ProgValidationNonTilt::defineParams ()
 
void ProgValidationNonTilt::run ()
 
 ProgValidationNonTilt::ProgValidationNonTilt ()
 
void ProgValidationNonTilt::obtainSumU (const MetaData &tempMd, std::vector< double > &sum_u, std::vector< double > &H0)
 
void ProgValidationNonTilt::obtainSumU_2 (const MetaData &mdGallery, const MetaData &tempMd, std::vector< double > &sum_u, std::vector< double > &H0)
 
void ProgValidationNonTilt::obtainSumW (const MetaData &tempMd, double &sum_W, std::vector< double > &sum_u, std::vector< double > &H, const double factor)
 
virtual void ProgValidationNonTilt::gatherClusterability ()
 Gather alignment. More...
 
virtual void ProgValidationNonTilt::synchronize ()
 Synchronize with other processors. More...
 

Variables

FileName ProgValidationNonTilt::fnDir
 
FileName ProgValidationNonTilt::fnSym
 
FileName ProgValidationNonTilt::fnInit
 
FileName ProgValidationNonTilt::fnParticles
 
MetaDataDb ProgValidationNonTilt::mdPartial
 
size_t ProgValidationNonTilt::rank
 
size_t ProgValidationNonTilt::Nprocessors
 
bool ProgValidationNonTilt::useSignificant
 
double ProgValidationNonTilt::significance_noise
 

Detailed Description

Function Documentation

◆ defineParams()

void ProgValidationNonTilt::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 49 of file validation_nontilt.cpp.

50 {
51  addUsageLine("Validate a 3D reconstruction from its projections attending to directionality and spread of the angular assignments from a given significant value");
52  addParamsLine(" [--i <md_file=\"\">] : Metadata file with input projections");
53  addParamsLine(" [--volume <md_file=\"\">] : Volume to validate");
54  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
55  addParamsLine(" [--sym <symfile=c1>] : Enforce symmetry in projections");
56  addParamsLine(" [--significance_noise<float=0.95>] : Significance of the alignment with respect the noise");
57  addParamsLine(" [--useSignificant] : Use Significant as alignment method. If not use projection matching");
58 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ gatherClusterability()

virtual void ProgValidationNonTilt::gatherClusterability ( )
inlinevirtual

Gather alignment.

Reimplemented in MpiProgValidationNonTilt.

Definition at line 71 of file validation_nontilt.h.

71 {}

◆ obtainSumU()

void ProgValidationNonTilt::obtainSumU ( const MetaData tempMd,
std::vector< double > &  sum_u,
std::vector< double > &  H0 
)

Definition at line 187 of file validation_nontilt.cpp.

188 {
189 
190  const size_t tempMdSz= tempMd.size();
191  double xRan,yRan,zRan;
192  double x,y;
193  double sumWRan;
194  auto * xRanArray = new double[tempMdSz];
195  auto * yRanArray = new double[tempMdSz];
196  auto * zRanArray = new double[tempMdSz];
197  std::vector<double> weightV;
198  double a;
199  std::random_device rd;
200  std::mt19937 g(rd());
201 
202  for (size_t n=0; n<sum_u.size(); n++)
203  {
204  for (size_t nS=0; nS<tempMd.size(); nS++)
205  {
206  /*
207  x = sin(tilt*PI/180)*cos(rot*PI/180);
208  y = sin(tilt*PI/180)*sin(rot*PI/180);
209  z = std::abs(cos(tilt*PI/180));
210  */
211 
212  //http://mathworld.wolfram.com/SpherePointPicking.html
213  x = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;
214  y = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;
215 
216  while (x*x+y*y >= 1 )
217  {
218  x = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
219  y = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
220  }
221 
222  xRan = 2*x*std::sqrt(1-x*x-y*y);
223  yRan = 2*y*std::sqrt(1-x*x-y*y);
224  zRan = std::abs(1-2*(x*x+y*y));
225 
226 /* tilt = (double(std::rand())/RAND_MAX)*(PI);
227  rot = (std::rand()-RAND_MAX/2)*(2*PI/RAND_MAX);
228  xRan = sin(tilt)*cos(rot);
229  yRan = sin(tilt)*sin(rot);
230  zRan = std::abs(cos(tilt));
231 */
232  //std::cout << tilt << " " << rot << std::endl;
233  //std::cout << xRan << " " << yRan << " " << zRan << " " << std::endl;
234  //zRan=(std::rand()-RAND_MAX/2);
235  //norm = std::sqrt(xRan*xRan+yRan*yRan+zRan*zRan);
236  //xRan = (xRan/norm);
237  //yRan = (yRan/norm);
238  //zRan = std::abs(zRan/norm);
239 
240  xRanArray[nS] = xRan;
241  yRanArray[nS] = yRan;
242  zRanArray[nS] = zRan;
243  //tempMd.getColumnValues(MDL_WEIGHT, weightV);
244  tempMd.getColumnValues(MDL_MAXCC, weightV);
245 
246  std::shuffle(weightV.begin(), weightV.end(), g);
247  }
248 
249  sumWRan = 0;
250  double WRan=0;
251  double tempWRan, tempW1, tempW2, temp;
252  for (size_t nS1=0; nS1<tempMd.size(); nS1++)
253  {
254  tempWRan = 1e3;
255  for (size_t nS2=0; nS2<tempMd.size(); nS2++)
256  {
257  temp = xRanArray[nS1]*xRanArray[nS2]+yRanArray[nS1]*yRanArray[nS2]+zRanArray[nS1]*zRanArray[nS2];
258  if (temp < 1)
259  a = std::abs(std::acos(temp));
260  else
261  a = 0;
262 
263  if ( (a<tempWRan) && (a > 0.00001) && (temp<1) )
264  {
265  tempWRan = a;
266  tempW2 = weightV[nS2];
267  tempW1 = weightV[nS1];
268  WRan = a*std::exp(std::abs(tempW1-tempW2))*std::exp(-(tempW1+tempW2));
269  if (WRan == 0)
270  WRan = a;
271 
272  }
273  }
274  sumWRan += WRan;
275  }
276 
277  if (sumWRan == 0)
278  sumWRan = 0.075*tempMd.size();
279 
280  sum_u.at(n)=sumWRan;
281 
282  }
283 
284  size_t idx = 0;
285  while (idx < sum_u.size())
286  {
287  std::shuffle(sum_u.begin(), sum_u.end(), g);
288 
289  if(sum_u.at(0) != sum_u.at(1))
290  {
291  H0[idx] = sum_u.at(0)/(sum_u.at(0)+sum_u.at(1));
292  idx += 1;
293  }
294  }
295 
296  delete[] xRanArray;
297  delete[] yRanArray;
298  delete[] zRanArray;
299 
300 }
doublereal * g
void sqrt(Image< double > &op)
static double * y
void abs(Image< double > &op)
doublereal * x
Maximum cross-correlation for the image (double)
virtual size_t size() const =0
std::vector< T > getColumnValues(const MDLabel label) const
int * n
doublereal * a

◆ obtainSumU_2()

void ProgValidationNonTilt::obtainSumU_2 ( const MetaData mdGallery,
const MetaData tempMd,
std::vector< double > &  sum_u,
std::vector< double > &  H0 
)

Definition at line 376 of file validation_nontilt.cpp.

377 {
378 
379  const size_t tempMdSz= tempMd.size();
380  const size_t numGallery= mdGallery.size();
381 
382  double xRan,yRan,zRan;
383  size_t indx;
384  double sumWRan;
385  auto * xRanArray = new double[tempMdSz];
386  auto * yRanArray = new double[tempMdSz];
387  auto * zRanArray = new double[tempMdSz];
388  std::vector<double> weightV;
389  double a;
390 
391  double rot,tilt;
392  bool mirror;
393  std::random_device rd;
394  std::mt19937 g(rd());
395  for (size_t n=0; n<sum_u.size(); n++)
396  {
397  for (size_t nS=0; nS<tempMd.size(); nS++)
398  {
399  indx = (size_t) (double( std::rand())*numGallery)/RAND_MAX;
400 
401  while ( (indx ==0) || (indx > numGallery) )
402  indx = (size_t) (double( std::rand())*numGallery )/RAND_MAX;
403 
404  mdGallery.getValue(MDL_ANGLE_ROT,rot,indx);
405  mdGallery.getValue(MDL_ANGLE_TILT,tilt,indx);
406  mdGallery.getValue(MDL_FLIP,mirror,indx);
407 
408  if (mirror == 1)
409  tilt = tilt + 180;
410 
411  xRan = sin(tilt*PI/180.)*cos(rot*PI/180.);
412  yRan = sin(tilt*PI/180.)*sin(rot*PI/180.);
413  zRan = std::abs(cos(tilt*PI/180.));
414 
415  xRanArray[nS] = xRan;
416  yRanArray[nS] = yRan;
417  zRanArray[nS] = zRan;
418  //tempMd.getColumnValues(MDL_WEIGHT, weightV);
419  tempMd.getColumnValues(MDL_MAXCC, weightV);
420  std::shuffle(weightV.begin(), weightV.end(), g);
421  }
422 
423 
424  sumWRan = 0;
425  double WRan=0;
426  double tempWRan, tempW1, tempW2, temp;
427  for (size_t nS1=0; nS1<tempMd.size(); nS1++)
428  {
429  tempWRan = 1e3;
430  for (size_t nS2=0; nS2<tempMd.size(); nS2++)
431  {
432  temp = xRanArray[nS1]*xRanArray[nS2]+yRanArray[nS1]*yRanArray[nS2]+zRanArray[nS1]*zRanArray[nS2];
433  if (temp < 1)
434  a = std::abs(std::acos(temp));
435  else
436  a = 0;
437 
438  if ( (a<tempWRan) && (a > 0.00001) && (temp<1) )
439  {
440  tempWRan = a;
441  tempW2 = weightV[nS2];
442  tempW1 = weightV[nS1];
443  WRan = a*std::exp(std::abs(tempW1-tempW2))*std::exp(-(tempW1+tempW2));
444  if (WRan == 0)
445  WRan = a;
446  }
447  }
448  sumWRan += WRan;
449  }
450 
451  if (sumWRan == 0)
452  sumWRan = 0.075*tempMd.size();
453 
454  sum_u.at(n)=sumWRan;
455 
456  }
457 
458  size_t idx = 0;
459  while (idx < sum_u.size())
460  {
461  std::shuffle(sum_u.begin(), sum_u.end(), g);
462 
463  if(sum_u.at(0) != sum_u.at(1))
464  {
465  H0[idx] = sum_u.at(0)/(sum_u.at(0)+sum_u.at(1));
466  idx += 1;
467  }
468  }
469 
470  delete[] xRanArray;
471  delete[] yRanArray;
472  delete[] zRanArray;
473 
474 }
Rotation angle of an image (double,degrees)
doublereal * g
Tilting angle of an image (double,degrees)
void abs(Image< double > &op)
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
Flip the image? (bool)
Maximum cross-correlation for the image (double)
virtual size_t size() const =0
std::vector< T > getColumnValues(const MDLabel label) const
#define PI
Definition: tools.h:43
int * n
doublereal * a

◆ obtainSumW()

void ProgValidationNonTilt::obtainSumW ( const MetaData tempMd,
double &  sum_W,
std::vector< double > &  sum_u,
std::vector< double > &  H,
const double  factor 
)

Definition at line 302 of file validation_nontilt.cpp.

303 {
304  double a;
305  double rot,tilt,w;
306  double x,y,z;
307  double xx,yy,zz;
308  bool mirror;
309  double w2;
310  double tempW;
311  double W=0;
312  double temp;
313  double sumW;
314 
315  sumW = 0;
316  for (size_t objId : tempMd.ids())
317  {
318  tempMd.getValue(MDL_ANGLE_ROT,rot,objId);
319  tempMd.getValue(MDL_ANGLE_TILT,tilt,objId);
320  tempMd.getValue(MDL_FLIP,mirror,objId);
321  if (mirror == 1)
322  tilt = tilt + 180;
323 
324  //tempMd.getValue(MDL_WEIGHT,w,objId);
325  tempMd.getValue(MDL_MAXCC,w,objId);
326  x = sin(tilt*PI/180.)*cos(rot*PI/180.);
327  y = sin(tilt*PI/180.)*sin(rot*PI/180.);
328  z = std::abs(cos(tilt*PI/180.));
329 
330  tempW = 1e3;
331  for (size_t objId2 : tempMd.ids())
332  {
333  tempMd.getValue(MDL_ANGLE_ROT,rot,objId2);
334  tempMd.getValue(MDL_ANGLE_TILT,tilt,objId2);
335  //tempMd.getValue(MDL_WEIGHT,w2,objId2);
336  tempMd.getValue(MDL_MAXCC,w2,objId2);
337  tempMd.getValue(MDL_FLIP,mirror,objId2);
338  if (mirror == 1)
339  tilt = tilt + 180;
340 
341  xx = sin(tilt*PI/180.)*cos(rot*PI/180.);
342  yy = sin(tilt*PI/180.)*sin(rot*PI/180.);
343  zz = std::abs(cos(tilt*PI/180.));
344  temp = x*xx+y*yy+z*zz;
345 
346  if (temp < 1)
347  a = std::abs(std::acos(temp));
348  else
349  a = 0;
350 
351  if ( (a<tempW) && (a > 0.00001) && (temp<1 ))
352  {
353  W = a*std::exp(std::abs(w-w2))*std::exp(-(w+w2));
354  tempW = a;
355 
356  if (W == 0)
357  W = a;
358  }
359  }
360  sumW += W;
361  }
362 
363  //Here the problem is that maybe the changes are only in psi angle. We give the best solution assuming an angular sampling of 0.5º
364  if (sumW == 0)
365  sumW = 0.075*tempMd.size();
366 
367  sum_W = sumW;
368  for (size_t n=0; n<sum_u.size(); n++)
369  {
370  H[n] = sumW/(sumW+factor*sum_u.at(n));
371  }
372 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
static double * y
doublereal * w
void abs(Image< double > &op)
virtual IdIteratorProxy< false > ids()
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
doublereal * x
Flip the image? (bool)
double z
Maximum cross-correlation for the image (double)
virtual size_t size() const =0
#define PI
Definition: tools.h:43
int * n
doublereal * a

◆ ProgValidationNonTilt()

ProgValidationNonTilt::ProgValidationNonTilt ( )

Definition at line 33 of file validation_nontilt.cpp.

34 {
35  rank=0;
36  Nprocessors=1;
37 }

◆ readParams()

void ProgValidationNonTilt::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippProgram.

Definition at line 39 of file validation_nontilt.cpp.

40 {
41  fnParticles = getParam("--i");
42  fnDir = getParam("--odir");
43  fnSym = getParam("--sym");
44  fnInit = getParam("--volume");
45  useSignificant = checkParam("--useSignificant");
46  significance_noise = getDoubleParam("--significance_noise");
47 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)

◆ run()

void ProgValidationNonTilt::run ( )
virtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 60 of file validation_nontilt.cpp.

61 {
62  //Clustering Tendency and Cluster Validity Stephen D. Scott
64  MetaDataDb md,mdGallery,mdOut,mdOut2,mdSort;
65  MDRowVec row;
66 
67  FileName fnOut,fnOut2, fnGallery;
68  fnOut = fnDir+"/clusteringTendency.xmd";
69  fnGallery = fnDir+"/gallery.doc";
70  fnOut2 = fnDir+"/validation.xmd";
71  size_t nSamplesRandom = 500;
72 
73  md.read(fnParticles);
74  mdGallery.read(fnGallery);
75  mdSort.sort(md,MDL_IMAGE_IDX,true,-1,0);
76 
77  size_t maxNImg;
78  size_t sz = md.size();
79 
80  if (useSignificant)
81  mdSort.getValue(MDL_IMAGE_IDX,maxNImg,sz);
82  else
83  {
84  mdSort.getValue(MDL_ITEM_ID,maxNImg,sz);
85  }
86 
87  String expression;
88  MDRowVec rowP,row2;
89  SymList SL;
90  int symmetry, sym_order;
91  SL.readSymmetryFile(fnSym.c_str());
92  SL.isSymmetryGroup(fnSym.c_str(), symmetry, sym_order);
93 
94 /*
95  double non_reduntant_area_of_sphere = SL.nonRedundantProjectionSphere(symmetry,sym_order);
96  double area_of_sphere_no_symmetry = 4.*PI;
97  double correction = std::sqrt(non_reduntant_area_of_sphere/area_of_sphere_no_symmetry);
98 */
99  double correction = 1;
100  double validation = 0;
101  double num_images = 0;
102 
103  MetaDataDb tempMd;
104  std::vector<double> sum_u(nSamplesRandom);
105  double sum_w=0;
106  std::vector<double> H0(nSamplesRandom);
107  std::vector<double> H(nSamplesRandom);
108  std::vector<double> p(nSamplesRandom);
109 
110  if (rank==0)
111  init_progress_bar(maxNImg);
112 
113  for (size_t idx=0; idx<=maxNImg;idx++)
114  {
115  if (idx%Nprocessors==rank)
116  {
117  if (useSignificant)
118  expression = formatString("imageIndex == %lu",idx);
119  else
120  expression = formatString("itemId == %lu",idx);
121 
122  tempMd.importObjects(md, MDExpression(expression));
123 
124 
125  if (tempMd.size()==0)
126  continue;
127 
128  //compute H_0 from noise
129  obtainSumU_2(mdGallery, tempMd,sum_u,H0);
130  //compute H from experimental
131  obtainSumW(tempMd,sum_w,sum_u,H,correction);
132 
133  std::sort(H0.begin(),H0.end());
134  std::sort(H.begin(),H.end());
135 
136  double P = 0;
137  for(size_t j=0; j<sum_u.size();j++)
138  {
139  //P += H0.at(j)/H.at(j);
140  P += H0.at(size_t((1-significance_noise)*nSamplesRandom))/H.at(j);
141  p.at(j) = H0.at(j)/H.at(j);
142  }
143 
144  P /= nSamplesRandom;
145 
146  if (useSignificant)
147  rowP.setValue(MDL_IMAGE_IDX,idx);
148  else
149  rowP.setValue(MDL_ITEM_ID,idx);
150 
151  rowP.setValue(MDL_WEIGHT,P);
152  mdPartial.addRow(rowP);
153  tempMd.clear();
154 
155  if (rank==0)
156  progress_bar(idx+1);
157  }
158  }
159 
160  if (rank==0)
161  progress_bar(maxNImg);
162 
163  synchronize();
165 
166  if (rank == 0)
167  {
168  mdPartial.write(fnOut);
169  std::vector<double> P;
171 
172  for (size_t idx=0; idx< P.size();idx++)
173  {
174  if (P[idx] > 1)
175  validation += 1.;
176  num_images += 1.;
177  }
178  validation /= num_images;
179 
180  row2.setValue(MDL_IMAGE,fnInit);
181  row2.setValue(MDL_WEIGHT,validation);
182  mdOut2.addRow(row2);
183  mdOut2.write(fnOut2);
184  }
185 }
void init_progress_bar(long total)
virtual void gatherClusterability()
Gather alignment.
Index of an image within a list (size_t)
bool getValue(MDObject &mdValueOut, size_t id) const override
void setValue(const MDObject &object) override
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
Definition: symmetries.cpp:33
bool isSymmetryGroup(FileName fn_sym, int &pgGroup, int &pgOrder)
Definition: symmetries.cpp:601
Unique identifier for items inside a list or set (std::size_t)
void obtainSumW(const MetaData &tempMd, double &sum_W, std::vector< double > &sum_u, std::vector< double > &H, const double factor)
void getColumnValues(const MDLabel label, std::vector< MDObject > &valuesOut) const override
size_t addRow(const MDRow &row) override
FileName fnOut
void obtainSumU_2(const MetaData &mdGallery, const MetaData &tempMd, std::vector< double > &sum_u, std::vector< double > &H0)
void progress_bar(long rlen)
void clear() override
Definition: metadata_db.cpp:54
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
size_t size() const override
#define j
void importObjects(const MetaData &md, const std::vector< size_t > &objectsToAdd, bool doClear=true) override
void sort(MetaDataDb &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
virtual void synchronize()
Synchronize with other processors.
unsigned int randomize_random_generator()
Name of an image (std::string)
< Score 4 for volumes

◆ synchronize()

virtual void ProgValidationNonTilt::synchronize ( )
inlinevirtual

Synchronize with other processors.

Reimplemented in MpiProgValidationNonTilt.

Definition at line 74 of file validation_nontilt.h.

74 {}

Variable Documentation

◆ fnDir

FileName ProgValidationNonTilt::fnDir

Filenames

Definition at line 42 of file validation_nontilt.h.

◆ fnInit

FileName ProgValidationNonTilt::fnInit

Definition at line 42 of file validation_nontilt.h.

◆ fnParticles

FileName ProgValidationNonTilt::fnParticles

Definition at line 42 of file validation_nontilt.h.

◆ fnSym

FileName ProgValidationNonTilt::fnSym

Definition at line 42 of file validation_nontilt.h.

◆ mdPartial

MetaDataDb ProgValidationNonTilt::mdPartial

Definition at line 44 of file validation_nontilt.h.

◆ Nprocessors

size_t ProgValidationNonTilt::Nprocessors

Definition at line 46 of file validation_nontilt.h.

◆ rank

size_t ProgValidationNonTilt::rank

Definition at line 46 of file validation_nontilt.h.

◆ significance_noise

double ProgValidationNonTilt::significance_noise

Definition at line 50 of file validation_nontilt.h.

◆ useSignificant

bool ProgValidationNonTilt::useSignificant

Definition at line 48 of file validation_nontilt.h.