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

#include <image_rotational_pca.h>

Inheritance diagram for ProgImageRotationalPCA:
Inheritance graph
[legend]
Collaboration diagram for ProgImageRotationalPCA:
Collaboration graph
[legend]

Public Member Functions

 ProgImageRotationalPCA ()
 Empty constructor. More...
 
 ~ProgImageRotationalPCA ()
 Destructor. More...
 
void readParams ()
 Read argument from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Usage. More...
 
void produceSideInfo ()
 Produce side info. More...
 
void writeToHBuffer (int idx, double *dest)
 
void flushHBuffer ()
 
void clearHbuffer ()
 
void applyT ()
 
void applyTt ()
 
int QR ()
 
void run ()
 
virtual void selectPartFromMd (MetaData &MDin)
 
virtual void comunicateMatrix (Matrix2D< double > &W)
 
virtual void createMutexes (size_t Nimgs)
 
virtual void allReduceApplyT (Matrix2D< double > &Wnode_0)
 
virtual void comunicateQrDim (int &qrDim)
 
virtual void mapMatrix (int qrDim)
 
virtual void applySVD ()
 
virtual void copyHtoF (int block)
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fnIn
 
FileName fnRoot
 
int Neigen
 
int Nits
 
double psi_step
 
double max_shift_change
 
double shift_step
 
int maxNimgs
 
int Nthreads
 
int rank
 
std::vector< MetaDataVecMD
 
size_t Nimg
 
int Nangles
 
int Nshifts
 
size_t Xdim
 
int Npixels
 
std::vector< double * > Hbuffer
 
std::vector< double * > HbufferDestination
 
std::unique_ptr< MutexfileMutex
 
std::unique_ptr< MutexthreadMutex
 
Matrix2D< double > H
 
Matrix2D< double > F
 
std::vector< Image< double > > I
 
std::vector< MultidimArray< double > > Iaux
 
std::vector< Matrix2D< double > > A
 
std::vector< Matrix2D< double > > Hblock
 
std::vector< Matrix2D< double > > Wnode
 
Matrix2D< double > Wtranspose
 
MultidimArray< unsigned char > mask
 
std::unique_ptr< ThreadTaskDistributortaskDistributor
 
std::unique_ptr< ThreadManagerthMgr
 
std::vector< size_t > objId
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Static Public Attributes

static const int HbufferMax =20
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Rotational invariant PCA parameters.

Definition at line 41 of file image_rotational_pca.h.

Constructor & Destructor Documentation

◆ ProgImageRotationalPCA()

ProgImageRotationalPCA::ProgImageRotationalPCA ( )

Empty constructor.

Definition at line 34 of file image_rotational_pca.cpp.

35 {
36  rank = 0;
37  verbose = 1;
38 }
int verbose
Verbosity level.

◆ ~ProgImageRotationalPCA()

ProgImageRotationalPCA::~ProgImageRotationalPCA ( )

Destructor.

Definition at line 41 of file image_rotational_pca.cpp.

42 {
43  clearHbuffer();
44 }

Member Function Documentation

◆ allReduceApplyT()

void ProgImageRotationalPCA::allReduceApplyT ( Matrix2D< double > &  Wnode_0)
virtual

Last part of function applyT

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 322 of file image_rotational_pca.cpp.

323 {
324 }

◆ applySVD()

void ProgImageRotationalPCA::applySVD ( )
virtual

Apply SVD

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 531 of file image_rotational_pca.cpp.

532 {
533  // Apply SVD and extract the basis
534  std::cout << "Performing SVD decomposition ..." << std::endl;
535  // SVD of W
536  Matrix2D<double> U,V;
538  svdcmp(Wnode[0],U,S,V);
539 
540  // Keep the first Neigen images from U
542  I().resizeNoCopy(Xdim,Xdim);
543  const MultidimArray<double> &mI=I();
544  FileName fnImg;
545  MetaDataVec MD;
546  for (int eig=0; eig<Neigen; eig++)
547  {
548  int Un=0;
551  DIRECT_MULTIDIM_ELEM(mI,n)=MAT_ELEM(U,Un++,eig);
552  fnImg.compose(eig+1,fnRoot,"stk");
553  I.write(fnImg);
554  size_t id=MD.addObject();
555  MD.setValue(MDL_IMAGE,fnImg,id);
556  MD.setValue(MDL_WEIGHT,VEC_ELEM(S,eig),id);
557  }
558  MD.write(fnRoot+".xmd");
559 }
std::vector< Matrix2D< double > > Wnode
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
MultidimArray< unsigned char > mask
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="")
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
std::vector< Image< double > > I
std::vector< MetaDataVec > MD
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void svdcmp(const Matrix2D< T > &a, Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v)
Definition: matrix2d.cpp:125
int * n
Name of an image (std::string)
< Score 4 for volumes

◆ applyT()

void ProgImageRotationalPCA::applyT ( )

Apply T. W=T(H).

Definition at line 326 of file image_rotational_pca.cpp.

327 {
328  Matrix2D<double> &Wnode_0=Wnode[0];
329  Wnode_0.initZeros(Npixels,MAT_XSIZE(H));
330  taskDistributor->reset();
331  thMgr->run(threadApplyT);
332 
333  // Gather all Wnodes from all threads
334  for (int n=1; n<Nthreads; ++n)
335  Wnode_0 += Wnode[n];
336  allReduceApplyT(Wnode_0);
337  if (IS_MASTER)
338  progress_bar(objId.size());
339 }
std::vector< Matrix2D< double > > Wnode
std::unique_ptr< ThreadManager > thMgr
virtual void allReduceApplyT(Matrix2D< double > &Wnode_0)
#define IS_MASTER
void progress_bar(long rlen)
std::unique_ptr< ThreadTaskDistributor > taskDistributor
std::vector< size_t > objId
void threadApplyT(ThreadArgument &thArg)
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void initZeros()
Definition: matrix2d.h:626
int * n

◆ applyTt()

void ProgImageRotationalPCA::applyTt ( )

Apply Tt. H=Tt(W).

Definition at line 445 of file image_rotational_pca.cpp.

446 {
447  // Compute W transpose to accelerate memory access
448  Matrix2D<double> &W=Wnode[0];
451  MAT_ELEM(Wtranspose,i,j) = MAT_ELEM(W,j,i);
452 
453  taskDistributor->reset();
454  thMgr->run(threadApplyTt);
455  flushHBuffer();
456  if (IS_MASTER)
457  progress_bar(objId.size());
458 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
std::vector< Matrix2D< double > > Wnode
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
std::unique_ptr< ThreadManager > thMgr
#define i
void resizeNoCopy(int Ydim, int Xdim)
Definition: matrix2d.h:534
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define IS_MASTER
void progress_bar(long rlen)
std::unique_ptr< ThreadTaskDistributor > taskDistributor
std::vector< size_t > objId
#define j
void threadApplyTt(ThreadArgument &thArg)
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
Matrix2D< double > Wtranspose

◆ clearHbuffer()

void ProgImageRotationalPCA::clearHbuffer ( )

Clear H buffer

Definition at line 47 of file image_rotational_pca.cpp.

48 {
49  int nmax = Hbuffer.size();
50  for (int n = 0; n < nmax; n++)
51  delete[] Hbuffer[n];
52  Hbuffer.clear();
53 }
int * nmax
std::vector< double * > Hbuffer
int * n

◆ comunicateMatrix()

void ProgImageRotationalPCA::comunicateMatrix ( Matrix2D< double > &  W)
virtual

Comunicate matrix, only meanful for MPI

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 114 of file image_rotational_pca.cpp.

115 {
116 }

◆ comunicateQrDim()

void ProgImageRotationalPCA::comunicateQrDim ( int &  qrDim)
virtual

Comunicate int param

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 517 of file image_rotational_pca.cpp.

518 {
519  std::cout << "Performing QR decomposition ..." << std::endl;
520  qrDim = QR();
521 }

◆ copyHtoF()

void ProgImageRotationalPCA::copyHtoF ( int  block)
virtual

Copy H to F.

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 510 of file image_rotational_pca.cpp.

511 {
512  size_t Hidx=block*MAT_XSIZE(H);
514  MAT_ELEM(F,Hidx+j,i)=MAT_ELEM(H,i,j);
515 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
#define i
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define j
#define MAT_XSIZE(m)
Definition: matrix2d.h:120

◆ createMutexes()

void ProgImageRotationalPCA::createMutexes ( size_t  Nimgs)
virtual

Create mutexes and distributor

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 118 of file image_rotational_pca.cpp.

119 {
120  fileMutex = std::make_unique<Mutex>();
121  threadMutex = std::make_unique<Mutex>();
122  taskDistributor = std::make_unique<ThreadTaskDistributor>(Nimgs, XMIPP_MAX(1,Nimgs/5));
123 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
std::unique_ptr< Mutex > threadMutex
std::unique_ptr< ThreadTaskDistributor > taskDistributor
std::unique_ptr< Mutex > fileMutex

◆ defineParams()

void ProgImageRotationalPCA::defineParams ( )
virtual

Usage.

Reimplemented from XmippProgram.

Definition at line 88 of file image_rotational_pca.cpp.

89 {
91  "Makes a rotational invariant representation of the image collection");
93  " -i <selfile> : Selfile with experimental images");
94  addParamsLine(" --oroot <rootname> : Rootname for output");
95  addParamsLine(" [--eigenvectors <N=200>] : Number of eigenvectors");
96  addParamsLine(" [--iterations <N=2>] : Number of iterations");
98  " [--max_shift_change <r=0>] : Maximum change allowed in shift");
99  addParamsLine(" [--psi_step <ang=1>] : Step in psi in degrees");
100  addParamsLine(" [--shift_step <r=1>] : Step in shift in pixels");
101  addParamsLine(" [--maxImages <N=-1>] : Maximum number of images");
102  addParamsLine(" [--thr <N=1>] : Number of threads");
103  addExampleLine("Typical use (4 nodes with 4 processors):", false);
105  "mpirun -np 4 `which xmipp_mpi_image_rotational_pca` -i images.stk --oroot images_eigen --thr 4");
106 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ flushHBuffer()

void ProgImageRotationalPCA::flushHBuffer ( )

Flush buffer

Definition at line 215 of file image_rotational_pca.cpp.

216 {
217  int nmax=HbufferDestination.size();
218  const Matrix2D<double> &Hblock_0=Hblock[0];
219  fileMutex->lock();
220  for (int n=0; n<nmax; ++n)
221  memcpy(HbufferDestination[n],Hbuffer[n],MAT_XSIZE(Hblock_0)*MAT_YSIZE(Hblock_0)*sizeof(double));
222  fileMutex->unlock();
223  HbufferDestination.clear();
224 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
int * nmax
std::vector< double * > Hbuffer
std::vector< Matrix2D< double > > Hblock
std::vector< double * > HbufferDestination
std::unique_ptr< Mutex > fileMutex
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
int * n

◆ mapMatrix()

void ProgImageRotationalPCA::mapMatrix ( int  qrDim)
virtual

Map matrix

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 523 of file image_rotational_pca.cpp.

524 {
525  FileName(fnRoot+"_matrixH.raw").createEmptyFileWithGivenLength(Nimg*2*Nangles*Nshifts*qrDim*sizeof(double));
526  H.mapToFile(fnRoot+"_matrixH.raw",MAT_XSIZE(F),qrDim);
528  MAT_ELEM(H,i,j)=MAT_ELEM(F,j,i);
529 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
void mapToFile(const FileName &fn, int Ydim, int Xdim, size_t offset=0)
Definition: matrix2d.cpp:1079
void createEmptyFileWithGivenLength(size_t length=0) const
#define i
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define j
#define MAT_XSIZE(m)
Definition: matrix2d.h:120

◆ produceSideInfo()

void ProgImageRotationalPCA::produceSideInfo ( )

Produce side info.

Definition at line 126 of file image_rotational_pca.cpp.

127 {
128  time_config();
129  MetaDataVec MDin(fnIn);
130 
131  if (maxNimgs > 0)
132  selectPartFromMd(MDin);
133 
134  Nimg = MDin.size();
135  size_t Ydim, Zdim, Ndim;
136  getImageSize(MDin, Xdim, Ydim, Zdim, Ndim);
137  Nangles = (int)floor(360.0 / psi_step);
138  Nshifts = (int)((2 * max_shift_change + 1) / shift_step);
139  Nshifts *= Nshifts;
140 
141  // Construct mask
144  double R2 = 0.25 * Xdim * Xdim;
146  A2D_ELEM(mask,i,j)=(i*i+j*j<R2);
147  Npixels = (int) mask.sum();
148 
149  // Thread Manager
150  thMgr = std::make_unique<ThreadManager>(Nthreads, this);
152  Matrix2D<double> dummyMatrix, dummyHblock, dummyW;
153  dummyW.resizeNoCopy(Npixels, Neigen + 2);
154  dummyHblock.resizeNoCopy(2 * Nangles * Nshifts, Neigen + 2);
155  for (int n = 0; n < Nthreads; ++n)
156  {
157  Wnode.push_back(dummyW);
158  Hblock.push_back(dummyHblock);
159  A.push_back(dummyMatrix);
160  I.push_back(dummy);
161  Iaux.push_back(dummy());
162  MD.push_back(MDin);
163  }
164 
165  Matrix2D<double> &W = Wnode[0];
166  FileName fnMatrixF(fnRoot + "_matrixF.raw");
167  FileName fnMatrixH(fnRoot + "_matrixH.raw");
168 
169  if (IS_MASTER)
170  {
171  // F (#images*#shifts*#angles) x (#eigenvectors+2)*(its+1)
172  fnMatrixF.createEmptyFileWithGivenLength(
173  Nimg * 2 * Nangles * Nshifts * (Neigen + 2) * (Nits + 1)
174  * sizeof(double));
175  // H (#images*#shifts*#angles) x (#eigenvectors+2)
176  fnMatrixH.createEmptyFileWithGivenLength(
177  Nimg * 2 * Nangles * Nshifts * (Neigen + 2) * sizeof(double));
178 
179  // Initialize with random numbers between -1 and 1
181  MAT_ELEM(W,i,j)=rnd_unif(-1.0,1.0);
182  }
183 
184  comunicateMatrix(W);
185 
186  F.mapToFile(fnMatrixF, (Neigen + 2) * (Nits + 1),
187  Nimg * 2 * Nangles * Nshifts);
188  H.mapToFile(fnMatrixH, Nimg * 2 * Nangles * Nshifts, Neigen + 2);
189 
190  // Prepare buffer
191  for (int n = 0; n < HbufferMax; n++)
192  Hbuffer.push_back(
193  new double[MAT_XSIZE(dummyHblock) * MAT_YSIZE(dummyHblock)]);
194 
195  // Construct a FileTaskDistributor
196  MDin.findObjects(objId);
197  size_t Nimgs = objId.size();
198  createMutexes(Nimgs);
199 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
std::vector< Matrix2D< double > > Wnode
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define A2D_ELEM(v, i, j)
std::unique_ptr< ThreadManager > thMgr
__host__ __device__ float2 floor(const float2 v)
virtual void createMutexes(size_t Nimgs)
std::vector< Matrix2D< double > > A
std::vector< double * > Hbuffer
virtual void selectPartFromMd(MetaData &MDin)
void mapToFile(const FileName &fn, int Ydim, int Xdim, size_t offset=0)
Definition: matrix2d.cpp:1079
void resizeNoCopy(const MultidimArray< T1 > &v)
std::vector< Matrix2D< double > > Hblock
MultidimArray< unsigned char > mask
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
std::vector< Image< double > > I
std::vector< MetaDataVec > MD
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
void resizeNoCopy(int Ydim, int Xdim)
Definition: matrix2d.h:534
void time_config()
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
double rnd_unif()
#define IS_MASTER
std::vector< size_t > objId
double dummy
#define j
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
int * n
double sum() const
std::vector< MultidimArray< double > > Iaux
virtual void comunicateMatrix(Matrix2D< double > &W)

◆ QR()

int ProgImageRotationalPCA::QR ( )

QR decomposition. In fact, only Q is computed. It returns the number of columns of Q different from 0.

Definition at line 461 of file image_rotational_pca.cpp.

462 {
463  size_t jQ=0;
464  Matrix1D<double> qj1, qj2;
465  int iBlockMax=MAT_XSIZE(F)/4;
466 
467  for (size_t j1=0; j1<MAT_YSIZE(F); j1++)
468  {
469  F.getRow(j1,qj1);
470  // Project twice in the already established subspace
471  // One projection should be enough but Gram-Schmidt suffers
472  // from numerical problems
473  for (int it=0; it<2; it++)
474  {
475  for (size_t j2=0; j2<jQ; j2++)
476  {
477  F.getRow(j2,qj2);
478 
479  // Compute dot product
480  double s12=qj1.dotProduct(qj2);
481 
482  // Subtract the part of qj2 from qj1
483  double *ptr1=&VEC_ELEM(qj1,0);
484  const double *ptr2=&VEC_ELEM(qj2,0);
485  for (int i=0; i<iBlockMax; i++)
486  {
487  (*ptr1++)-=s12*(*ptr2++);
488  (*ptr1++)-=s12*(*ptr2++);
489  (*ptr1++)-=s12*(*ptr2++);
490  (*ptr1++)-=s12*(*ptr2++);
491  }
492  for (size_t i=iBlockMax*4; i<MAT_XSIZE(F); ++i)
493  (*ptr1++)-=s12*(*ptr2++);
494  }
495  }
496 
497  // Keep qj1 in Q if it has enough norm
498  double Rii=qj1.module();
499  if (Rii>1e-14)
500  {
501  // Make qj1 to be unitary and store in Q
502  qj1/=Rii;
503  F.setRow(jQ++,qj1);
504  }
505  }
506  return jQ;
507 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
double module() const
Definition: matrix1d.h:983
#define i
double dotProduct(const Matrix1D< T > &op1) const
Definition: matrix1d.cpp:704
void setRow(size_t i, const Matrix1D< T > &v)
Definition: matrix2d.cpp:910
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void getRow(size_t i, Matrix1D< T > &v) const
Definition: matrix2d.cpp:871

◆ readParams()

void ProgImageRotationalPCA::readParams ( )
virtual

Read argument from command line.

Reimplemented from XmippProgram.

Definition at line 57 of file image_rotational_pca.cpp.

58 {
59  fnIn = getParam("-i");
60  fnRoot = getParam("--oroot");
61  Neigen = getIntParam("--eigenvectors");
62  Nits = getIntParam("--iterations");
63  max_shift_change = getDoubleParam("--max_shift_change");
64  psi_step = getDoubleParam("--psi_step");
65  shift_step = getDoubleParam("--shift_step");
66  maxNimgs = getIntParam("--maxImages");
67  Nthreads = getIntParam("--thr");
68 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgImageRotationalPCA::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 563 of file image_rotational_pca.cpp.

564 {
565  show();
566  produceSideInfo();
567 
568  // Compute matrix F:
569  // Set H pointing to the first block of F
570  applyTt();// H=Tt(W)
571  copyHtoF(0);
572  for (int it=0; it<Nits; it++)
573  {
574  applyT(); // W=T(H)
575  applyTt();// H=Tt(W)
576  copyHtoF(it+1);
577  }
578  H.clear();
579  clearHbuffer();
580 
581  // QR decomposition of matrix F
582  int qrDim;
583 
584  comunicateQrDim(qrDim);
585 
586  if (qrDim==0)
587  REPORT_ERROR(ERR_VALUE_INCORRECT,"No subspace have been found");
588 
589  mapMatrix(qrDim);
590  F.clear();
591 
592  // Apply T
593  for (int n=0; n<Nthreads; ++n)
594  Hblock[n].resizeNoCopy(2*Nangles*Nshifts,qrDim);
595  applyT();
596 
597  // Free memory
598  H.clear();
599  Hblock.clear();
600 
601  applySVD();
602 
603  // Clean files
604  if (IS_MASTER)
605  {
606  unlink((fnRoot+"_matrixH.raw").c_str());
607  unlink((fnRoot+"_matrixF.raw").c_str());
608  }
609 }
void produceSideInfo()
Produce side info.
virtual void copyHtoF(int block)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
std::vector< Matrix2D< double > > Hblock
virtual void comunicateQrDim(int &qrDim)
void clear()
Definition: matrix2d.h:473
#define IS_MASTER
virtual void mapMatrix(int qrDim)
Incorrect value received.
Definition: xmipp_error.h:195
int * n

◆ selectPartFromMd()

void ProgImageRotationalPCA::selectPartFromMd ( MetaData MDin)
virtual

Read input images

Reimplemented in MpiProgImageRotationalPCA.

Definition at line 108 of file image_rotational_pca.cpp.

109 {
110  MetaDataVec MDaux;
111  MDaux.randomize(MDin);
112  MDin.selectPart(MDaux, 0, maxNimgs);
113 }
virtual void selectPart(const MetaData &mdIn, size_t startPosition, size_t numberOfObjects, const MDLabel sortLabel=MDL_OBJID)=0
void randomize(const MetaData &MDin)

◆ show()

void ProgImageRotationalPCA::show ( )

Show.

Definition at line 72 of file image_rotational_pca.cpp.

73 {
74  if (!verbose)
75  return;
76  std::cout << "Input: " << fnIn << std::endl
77  << "Output root: " << fnRoot << std::endl
78  << "Number eigenvectors: " << Neigen << std::endl
79  << "Number iterations: " << Nits << std::endl << "Psi step: "
80  << psi_step << std::endl << "Max shift change: " << max_shift_change
81  << " step: " << shift_step << std::endl << "Max images: "
82  << maxNimgs << std::endl << "Number of threads: " << Nthreads
83  << std::endl;
84 }
int verbose
Verbosity level.

◆ writeToHBuffer()

void ProgImageRotationalPCA::writeToHBuffer ( int  idx,
double *  dest 
)

Write to H buffer

Definition at line 202 of file image_rotational_pca.cpp.

203 {
204  threadMutex->lock();
205  int n=HbufferDestination.size();
206  const Matrix2D<double> &Hblock_idx=Hblock[idx];
207  // COSS std::cout << "Copying block " << idx << " into " << n << "(" << Hbuffer.size() << ")" << std::endl;
208  memcpy(Hbuffer[n],&MAT_ELEM(Hblock_idx,0,0),MAT_XSIZE(Hblock_idx)*MAT_YSIZE(Hblock_idx)*sizeof(double));
209  HbufferDestination.push_back(dest);
210  if (n==(HbufferMax-1))
211  flushHBuffer();
212  threadMutex->unlock();
213 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
std::vector< double * > Hbuffer
std::vector< Matrix2D< double > > Hblock
std::unique_ptr< Mutex > threadMutex
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
std::vector< double * > HbufferDestination
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
int * n

Member Data Documentation

◆ A

std::vector< Matrix2D<double> > ProgImageRotationalPCA::A

Definition at line 100 of file image_rotational_pca.h.

◆ F

Matrix2D<double> ProgImageRotationalPCA::F

Definition at line 93 of file image_rotational_pca.h.

◆ fileMutex

std::unique_ptr<Mutex> ProgImageRotationalPCA::fileMutex

Definition at line 87 of file image_rotational_pca.h.

◆ fnIn

FileName ProgImageRotationalPCA::fnIn

Input selfile

Definition at line 45 of file image_rotational_pca.h.

◆ fnRoot

FileName ProgImageRotationalPCA::fnRoot

Output root

Definition at line 47 of file image_rotational_pca.h.

◆ H

Matrix2D<double> ProgImageRotationalPCA::H

Definition at line 91 of file image_rotational_pca.h.

◆ Hblock

std::vector< Matrix2D<double> > ProgImageRotationalPCA::Hblock

Definition at line 102 of file image_rotational_pca.h.

◆ Hbuffer

std::vector<double *> ProgImageRotationalPCA::Hbuffer

Definition at line 81 of file image_rotational_pca.h.

◆ HbufferDestination

std::vector<double *> ProgImageRotationalPCA::HbufferDestination

Definition at line 83 of file image_rotational_pca.h.

◆ HbufferMax

const int ProgImageRotationalPCA::HbufferMax =20
static

Definition at line 85 of file image_rotational_pca.h.

◆ I

std::vector< Image<double> > ProgImageRotationalPCA::I

Definition at line 96 of file image_rotational_pca.h.

◆ Iaux

std::vector< MultidimArray<double> > ProgImageRotationalPCA::Iaux

Definition at line 98 of file image_rotational_pca.h.

◆ mask

MultidimArray< unsigned char > ProgImageRotationalPCA::mask

Definition at line 108 of file image_rotational_pca.h.

◆ max_shift_change

double ProgImageRotationalPCA::max_shift_change

Maximum shift change

Definition at line 55 of file image_rotational_pca.h.

◆ maxNimgs

int ProgImageRotationalPCA::maxNimgs

Maximum number of images

Definition at line 59 of file image_rotational_pca.h.

◆ MD

std::vector<MetaDataVec> ProgImageRotationalPCA::MD

Definition at line 67 of file image_rotational_pca.h.

◆ Nangles

int ProgImageRotationalPCA::Nangles

Definition at line 71 of file image_rotational_pca.h.

◆ Neigen

int ProgImageRotationalPCA::Neigen

Number of eigenvectors

Definition at line 49 of file image_rotational_pca.h.

◆ Nimg

size_t ProgImageRotationalPCA::Nimg

Definition at line 69 of file image_rotational_pca.h.

◆ Nits

int ProgImageRotationalPCA::Nits

Number of iterations

Definition at line 51 of file image_rotational_pca.h.

◆ Npixels

int ProgImageRotationalPCA::Npixels

Definition at line 77 of file image_rotational_pca.h.

◆ Nshifts

int ProgImageRotationalPCA::Nshifts

Definition at line 73 of file image_rotational_pca.h.

◆ Nthreads

int ProgImageRotationalPCA::Nthreads

Number of threads

Definition at line 61 of file image_rotational_pca.h.

◆ objId

std::vector<size_t> ProgImageRotationalPCA::objId

Definition at line 114 of file image_rotational_pca.h.

◆ psi_step

double ProgImageRotationalPCA::psi_step

Psi step

Definition at line 53 of file image_rotational_pca.h.

◆ rank

int ProgImageRotationalPCA::rank

Rank, used later for MPI

Definition at line 63 of file image_rotational_pca.h.

◆ shift_step

double ProgImageRotationalPCA::shift_step

Shift step

Definition at line 57 of file image_rotational_pca.h.

◆ taskDistributor

std::unique_ptr<ThreadTaskDistributor> ProgImageRotationalPCA::taskDistributor

Definition at line 110 of file image_rotational_pca.h.

◆ thMgr

std::unique_ptr<ThreadManager> ProgImageRotationalPCA::thMgr

Definition at line 112 of file image_rotational_pca.h.

◆ threadMutex

std::unique_ptr<Mutex> ProgImageRotationalPCA::threadMutex

Definition at line 89 of file image_rotational_pca.h.

◆ Wnode

std::vector< Matrix2D<double> > ProgImageRotationalPCA::Wnode

Definition at line 104 of file image_rotational_pca.h.

◆ Wtranspose

Matrix2D<double> ProgImageRotationalPCA::Wtranspose

Definition at line 106 of file image_rotational_pca.h.

◆ Xdim

size_t ProgImageRotationalPCA::Xdim

Definition at line 75 of file image_rotational_pca.h.


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