Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ModelML2D Class Reference

#include <ml2d.h>

Public Member Functions

 ModelML2D ()
 
 ModelML2D (int n_ref)
 
void initData ()
 
void setNRef (int n_ref)
 
void combineModel (const ModelML2D &model, int sign)
 
void addModel (const ModelML2D &model)
 
void substractModel (const ModelML2D &model)
 
void update ()
 
void print (int tabs=0) const
 Just for debugging now. More...
 

Public Attributes

int n_ref
 
std::vector< Image< double > > Iref
 
std::vector< Image< double > > WsumMref
 
double sigma_noise
 
double wsum_sigma_noise
 
double sigma_offset
 
double wsum_sigma_offset
 
std::vector< double > sumwsc
 
std::vector< double > sumw_mirror
 
std::vector< double > alpha_k
 
std::vector< double > mirror_fraction
 
std::vector< double > scale
 
double sumw_allrefs
 
double sumw_allrefs2
 
double avePmax
 
double sumfracweight
 
double LL
 
int dim
 
bool do_student
 
bool do_student_sigma_trick
 
bool do_norm
 

Detailed Description

Definition at line 79 of file ml2d.h.

Constructor & Destructor Documentation

◆ ModelML2D() [1/2]

ModelML2D::ModelML2D ( )

Definition at line 317 of file ml2d.cpp.

318 {
319  initData();
320 }//close default constructor
void initData()
Definition: ml2d.cpp:328

◆ ModelML2D() [2/2]

ModelML2D::ModelML2D ( int  n_ref)

Definition at line 322 of file ml2d.cpp.

323 {
324  initData();
325  setNRef(n_ref);
326 }//close constructor
int n_ref
Definition: ml2d.h:83
void setNRef(int n_ref)
Definition: ml2d.cpp:342
void initData()
Definition: ml2d.cpp:328

Member Function Documentation

◆ addModel()

void ModelML2D::addModel ( const ModelML2D model)

Definition at line 404 of file ml2d.cpp.

405 {
406  combineModel(model, 1);
407 }//close function addModel
void combineModel(const ModelML2D &model, int sign)
Definition: ml2d.cpp:360

◆ combineModel()

void ModelML2D::combineModel ( const ModelML2D model,
int  sign 
)

Definition at line 360 of file ml2d.cpp.

361 {
362  if (n_ref != model.n_ref)
363  REPORT_ERROR(ERR_VALUE_INCORRECT, "Can not add models with different 'n_ref'");
364 
365 #define COMBINE(var) var += sign * model.var
371  COMBINE(LL);
372 
374  double sumweight = 0., w1 = 0., w2 = 0.;
375 
376  for (int refno = 0; refno < n_ref; refno++)
377  {
378  w1 = WsumMref[refno].weight();
379  w2 = sign * model.WsumMref[refno].weight();
380  tmp = model.WsumMref[refno]();
381  tmp *= sign;
382  WsumMref[refno]() += tmp;
383  sumweight = w1 + w2;
384 
385  if (sumweight > 0.)
386  {
387  Iref[refno].setWeight(sumweight);
388  WsumMref[refno].setWeight(sumweight);
389  COMBINE(sumw_mirror[refno]);
390  COMBINE(sumwsc[refno]);
391  }
392  else
393  {
394  Iref[refno]().initZeros();
395  WsumMref[refno]().initZeros();
396  Iref[refno].setWeight(0);
397  WsumMref[refno].setWeight(0.);
398  sumw_mirror[refno] = 0.;
399  sumwsc[refno] = 0.;
400  }
401  }
402 }//close function combineModel
double LL
Definition: ml2d.h:99
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
double sign
int n_ref
Definition: ml2d.h:83
double sumw_allrefs
Definition: ml2d.h:95
#define COMBINE(var)
double wsum_sigma_offset
Definition: ml2d.h:89
double sumw_allrefs2
Definition: ml2d.h:95
std::vector< double > sumwsc
Definition: ml2d.h:91
std::vector< Image< double > > Iref
Definition: ml2d.h:85
double sumfracweight
Definition: ml2d.h:97
std::vector< double > sumw_mirror
Definition: ml2d.h:91
std::vector< Image< double > > WsumMref
Definition: ml2d.h:85
Incorrect value received.
Definition: xmipp_error.h:195
double wsum_sigma_noise
Definition: ml2d.h:87

◆ initData()

void ModelML2D::initData ( )

Definition at line 328 of file ml2d.cpp.

329 {
330  n_ref = -1;
332  do_student = do_norm = false;
333  do_student_sigma_trick = true;
334  sigma_noise = sigma_offset = LL = avePmax = 0.;
336  sumfracweight = 0.;
337  dim = 0;
338 }//close function initData
double LL
Definition: ml2d.h:99
int dim
Definition: ml2d.h:102
bool do_student_sigma_trick
Definition: ml2d.h:104
int n_ref
Definition: ml2d.h:83
double sumw_allrefs
Definition: ml2d.h:95
double wsum_sigma_offset
Definition: ml2d.h:89
double sumw_allrefs2
Definition: ml2d.h:95
double avePmax
Definition: ml2d.h:97
double sigma_noise
Definition: ml2d.h:87
double sumfracweight
Definition: ml2d.h:97
double sigma_offset
Definition: ml2d.h:89
bool do_student
Definition: ml2d.h:104
bool do_norm
Definition: ml2d.h:104
double wsum_sigma_noise
Definition: ml2d.h:87

◆ print()

void ModelML2D::print ( int  tabs = 0) const

Just for debugging now.

Definition at line 475 of file ml2d.cpp.

476 {
477  String stabs = "";
478  for (int t = 0; t < tabs; ++t)
479  stabs += " ";
480 
481  std::cerr << "======================= Block ==================== " << std::endl;
482 
483  std::cerr << "sumw_allrefs: " << sumw_allrefs << std::endl;
484  std::cerr << "wsum_sigma_offset: " << wsum_sigma_offset << std::endl;
485  std::cerr << "wsum_sigma_noise: " << wsum_sigma_noise << std::endl;
486  std::cerr << "sigma_offset: " << sigma_offset << std::endl;
487  std::cerr << "sigma_noise: " << sigma_noise << std::endl;
488  std::cerr << "LL: " << LL << std::endl;
489 
490  std::stringstream ss1, ss2, ss3, ss4, ss5, ss6, ss7;
491  pp(ss1, "refno:");
492  pp(ss3, "sumw_mirror:");
493  pp(ss4, "alpha_k:");
494  pp(ss5, "mirror_fraction");
495  pp(ss6, "WsumMref.weight");
496  pp(ss7, "Iref.weight");
497 
498  for (int refno = 0; refno < n_ref; refno++)
499  {
500  pp(ss1, refno);
501  pp(ss3, sumw_mirror[refno]);
502  pp(ss4, alpha_k[refno]);
503  pp(ss5, mirror_fraction[refno]);
504  pp(ss6, WsumMref[refno].weight());
505  pp(ss7, Iref[refno].weight());
506  }
507  std::cerr << ss1.str() << std::endl<< ss3.str() << std::endl
508  << ss4.str() << std::endl<< ss5.str() << std::endl << ss6.str() << std::endl << ss7.str()<< std::endl;
509 
510 }//close function print
double LL
Definition: ml2d.h:99
#define pp(s, x)
Definition: ml2d.cpp:473
std::vector< double > mirror_fraction
Definition: ml2d.h:93
int n_ref
Definition: ml2d.h:83
double sumw_allrefs
Definition: ml2d.h:95
double wsum_sigma_offset
Definition: ml2d.h:89
std::vector< double > alpha_k
Definition: ml2d.h:93
double sigma_noise
Definition: ml2d.h:87
std::vector< Image< double > > Iref
Definition: ml2d.h:85
double sigma_offset
Definition: ml2d.h:89
std::string String
Definition: xmipp_strings.h:34
std::vector< double > sumw_mirror
Definition: ml2d.h:91
std::vector< Image< double > > WsumMref
Definition: ml2d.h:85
double wsum_sigma_noise
Definition: ml2d.h:87

◆ setNRef()

void ModelML2D::setNRef ( int  n_ref)

Before call this function model.n_ref should be properly setted.

Definition at line 342 of file ml2d.cpp.

343 {
344  Image<double> Iempty;
345  Iempty().initZeros(dim,dim);
346  Iempty().setXmippOrigin();
347  this->n_ref = n_ref;
348  Iref.resize(n_ref, Iempty);
349  WsumMref.resize(n_ref, Iempty);
350  alpha_k.resize(n_ref, 0.);
351  mirror_fraction.resize(n_ref, 0.);
352  scale.resize(n_ref, 1.);
353  sumw_mirror.resize(n_ref, 0.);
354  sumwsc.resize(n_ref, 0.);
355 
356 }//close function setNRef
int dim
Definition: ml2d.h:102
std::vector< double > mirror_fraction
Definition: ml2d.h:93
int n_ref
Definition: ml2d.h:83
std::vector< double > alpha_k
Definition: ml2d.h:93
std::vector< double > sumwsc
Definition: ml2d.h:91
std::vector< Image< double > > Iref
Definition: ml2d.h:85
std::vector< double > sumw_mirror
Definition: ml2d.h:91
std::vector< Image< double > > WsumMref
Definition: ml2d.h:85
std::vector< double > scale
Definition: ml2d.h:93

◆ substractModel()

void ModelML2D::substractModel ( const ModelML2D model)

Definition at line 409 of file ml2d.cpp.

410 {
411  combineModel(model, -1);
412 }//close function substractModel
void combineModel(const ModelML2D &model, int sign)
Definition: ml2d.cpp:360

◆ update()

void ModelML2D::update ( )

Definition at line 414 of file ml2d.cpp.

415 {
416  if (sumw_allrefs < 0)
417  REPORT_ERROR(ERR_VALUE_INCORRECT, "updateFractions: sumw_allrefs should be greater than 0 ");
418 
419  //update sigma_noise
421  : sumw_allrefs;
422  double sigma_noise2 = wsum_sigma_noise / (sum * dim * dim);
423 
424  if (sigma_noise2 < 0.)
425  REPORT_ERROR(ERR_VALUE_INCORRECT, "sqrt of negative 'sigma_noise2'");
426  sigma_noise = sqrt(sigma_noise2);
427 
428  //update sigma_offset
429  if (wsum_sigma_offset < 0.)
430  REPORT_ERROR(ERR_VALUE_INCORRECT, "sqrt of negative 'wsum_sigma_offset'");
432 
433  //update avePmax
435 
436  double weight, inv_weight;
437 
438 // std::cerr << "DEBUG_JM: sumw_allrefs: " << sumw_allrefs << std::endl;
439 
440  for (int refno = 0; refno < n_ref; ++refno)
441  {
442  weight = WsumMref[refno].weight();
443 
444 // std::cerr << " DEBUG_JM: refno: " << refno << std::endl;
445 
446  if (weight > 0.)
447  {
448  //update weights
449  Iref[refno].setWeight(weight);
450  inv_weight = 1 / weight; //just to speed-up
451  Iref[refno]() = WsumMref[refno]();
452  Iref[refno]() *= inv_weight;
453  //update fractions
454  alpha_k[refno] = weight / sumw_allrefs;
455  mirror_fraction[refno] = sumw_mirror[refno] * inv_weight;
456  scale[refno] = sumwsc[refno] * inv_weight;
457 // std::cerr << " DEBUG_JM: weight: " << weight << std::endl;
458 // std::cerr << " DEBUG_JM: sumw_mirror[refno]: " << sumw_mirror[refno] << std::endl;
459  }
460  else
461  {
462 // std::cerr << " DEBUG_JM: all zeros... " << std::endl;
463  //zero weights
464  Iref[refno].setWeight(0.);
465  Iref[refno]().initZeros(WsumMref[refno]());
466  alpha_k[refno] = 0.;
467  mirror_fraction[refno] = 0.;
468  scale[refno] = 0.;
469  }
470  }
471 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void sqrt(Image< double > &op)
int dim
Definition: ml2d.h:102
bool do_student_sigma_trick
Definition: ml2d.h:104
std::vector< double > mirror_fraction
Definition: ml2d.h:93
int n_ref
Definition: ml2d.h:83
double sumw_allrefs
Definition: ml2d.h:95
double wsum_sigma_offset
Definition: ml2d.h:89
double sumw_allrefs2
Definition: ml2d.h:95
std::vector< double > alpha_k
Definition: ml2d.h:93
double avePmax
Definition: ml2d.h:97
std::vector< double > sumwsc
Definition: ml2d.h:91
double sigma_noise
Definition: ml2d.h:87
std::vector< Image< double > > Iref
Definition: ml2d.h:85
double sumfracweight
Definition: ml2d.h:97
double sigma_offset
Definition: ml2d.h:89
bool do_student
Definition: ml2d.h:104
std::vector< double > sumw_mirror
Definition: ml2d.h:91
std::vector< Image< double > > WsumMref
Definition: ml2d.h:85
Incorrect value received.
Definition: xmipp_error.h:195
std::vector< double > scale
Definition: ml2d.h:93
double wsum_sigma_noise
Definition: ml2d.h:87

Member Data Documentation

◆ alpha_k

std::vector<double> ModelML2D::alpha_k

this is redundant information, since it can be obtained from the sums

Definition at line 93 of file ml2d.h.

◆ avePmax

double ModelML2D::avePmax

Average height of the probability distribution at its maximum

Definition at line 97 of file ml2d.h.

◆ dim

int ModelML2D::dim

Dimension of images

Definition at line 102 of file ml2d.h.

◆ do_norm

bool ModelML2D::do_norm

Definition at line 104 of file ml2d.h.

◆ do_student

bool ModelML2D::do_student

Algorithmic variants

Definition at line 104 of file ml2d.h.

◆ do_student_sigma_trick

bool ModelML2D::do_student_sigma_trick

Definition at line 104 of file ml2d.h.

◆ Iref

std::vector< Image<double> > ModelML2D::Iref

References images

Definition at line 85 of file ml2d.h.

◆ LL

double ModelML2D::LL

the Log Likelihood

Definition at line 99 of file ml2d.h.

◆ mirror_fraction

std::vector<double> ModelML2D::mirror_fraction

Definition at line 93 of file ml2d.h.

◆ n_ref

int ModelML2D::n_ref

Number of reference images

Definition at line 83 of file ml2d.h.

◆ scale

std::vector<double> ModelML2D::scale

Definition at line 93 of file ml2d.h.

◆ sigma_noise

double ModelML2D::sigma_noise

Sigma value for expected pixel noise

Definition at line 87 of file ml2d.h.

◆ sigma_offset

double ModelML2D::sigma_offset

sigma-value for origin offsets and its sum

Definition at line 89 of file ml2d.h.

◆ sumfracweight

double ModelML2D::sumfracweight

Definition at line 97 of file ml2d.h.

◆ sumw_allrefs

double ModelML2D::sumw_allrefs

Sums of weights

Definition at line 95 of file ml2d.h.

◆ sumw_allrefs2

double ModelML2D::sumw_allrefs2

Definition at line 95 of file ml2d.h.

◆ sumw_mirror

std::vector<double> ModelML2D::sumw_mirror

Definition at line 91 of file ml2d.h.

◆ sumwsc

std::vector<double> ModelML2D::sumwsc

Vector containing sum of the weights of each reference and the mirrored ones

Definition at line 91 of file ml2d.h.

◆ wsum_sigma_noise

double ModelML2D::wsum_sigma_noise

Definition at line 87 of file ml2d.h.

◆ wsum_sigma_offset

double ModelML2D::wsum_sigma_offset

Definition at line 89 of file ml2d.h.

◆ WsumMref

std::vector< Image<double> > ModelML2D::WsumMref

Definition at line 85 of file ml2d.h.


The documentation for this class was generated from the following files: