Xmipp  v3.23.11-Nereus
basic_pca.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sorzano (coss@cnb.csic.es)
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 /* This file contains functions related to the SAMPLING Transform */
26 
27 #ifndef _CORE_BASICPCA_HH
28 #define _CORE_BASICPCA_HH
29 
30 #include <vector>
31 #include "core/multidim_array.h"
32 
33 
63 {
64 public:
65  // Set of images assigned to the class
66  std::vector< MultidimArray<float> > v;
67 
68  // Set of basis functions
69  std::vector< MultidimArray<double> > PCAbasis;
70 
71  // The average of the vectors
73 
74  // Set of basis functions
76 
77  // Indexes to access in a sorted way
79 
80  // Matrix for the Eigen values
82 public:
84  inline void clear()
85  {
86  v.clear();
87  PCAbasis.clear();
88  Zscore.clear();
89  idx.clear();
90  avg.clear();
91  }
92 
94  inline void reserve(int newSize)
95  {
96  v.reserve(newSize);
97  }
98 
100  inline void addVector(const MultidimArray<float> &_v)
101  {
102  v.push_back(_v);
103  }
104 
107  MultidimArray<double> &stddev);
108 
110  void subtractAvg();
111 
118  void gramSchmidt();
119 
121  void standardarizeVariables();
122 
124  void learnPCABasis(size_t NPCA, size_t Niter);
125 
128 
130  void reconsFromPCA(const Matrix2D<double> &CtY, std::vector< MultidimArray<float> > &recons);
131 
136  void evaluateZScore(int NPCA, int Niter, bool trained=false,
137  const char* filename="temp.txt", int numdesc=0);
138 
140  inline double getZscore(int n)
141  {
142  return Zscore(n);
143  }
144 
146  inline double getSortedZscore(int n)
147  {
148  return Zscore(idx(n)-1);
149  }
150 
152  inline int getSorted(int n)
153  {
154  return idx(n)-1;
155  }
156 };
157 
159 class PCAonline {
160 public:
165  double zn;
166  double xxt;
167  int N;
168  double maxzn;
169 public:
171  PCAonline();
172 
177 
180  return c1;
181  }
182 
185  return zn;
186  }
187 };
189 #endif
void addVector(const MultidimArray< float > &_v)
Add vector.
Definition: basic_pca.h:100
void projectOnPCABasis(Matrix2D< double > &CtY)
Project on basis.
Definition: basic_pca.cpp:119
int getSorted(int n)
Definition: basic_pca.h:152
double getZscore(int n)
Definition: basic_pca.h:140
static double * y
std::vector< MultidimArray< float > > v
Definition: basic_pca.h:66
void subtractAvg()
Subtract average.
Definition: basic_pca.cpp:33
MultidimArray< double > & getCurrentPCA()
Get principal component.
Definition: basic_pca.h:179
MultidimArray< int > idx
Definition: basic_pca.h:78
void computeStatistics(MultidimArray< double > &avg, MultidimArray< double > &stddev)
Compute Statistics.
Definition: basic_pca.cpp:348
void standardarizeVariables()
Standardarize variables.
Definition: basic_pca.cpp:61
MultidimArray< double > Zscore
Definition: basic_pca.h:75
void evaluateZScore(int NPCA, int Niter, bool trained=false, const char *filename="temp.txt", int numdesc=0)
Definition: basic_pca.cpp:384
double getCurrentProjection()
Get current projection.
Definition: basic_pca.h:184
void reserve(int newSize)
Resize.
Definition: basic_pca.h:94
double maxzn
Definition: basic_pca.h:168
MultidimArray< double > ycentered
Definition: basic_pca.h:164
std::vector< MultidimArray< double > > PCAbasis
Definition: basic_pca.h:69
double xxt
Definition: basic_pca.h:166
Matrix1D< double > w
Definition: basic_pca.h:81
double getSortedZscore(int n)
Definition: basic_pca.h:146
MultidimArray< double > ysum
Definition: basic_pca.h:161
void reconsFromPCA(const Matrix2D< double > &CtY, std::vector< MultidimArray< float > > &recons)
Reconstruct from PCA basis.
Definition: basic_pca.cpp:153
void clear()
Clear.
Definition: basic_pca.h:84
void learnPCABasis(size_t NPCA, size_t Niter)
Learn basis.
Definition: basic_pca.cpp:170
MultidimArray< double > avg
Definition: basic_pca.h:72
int * n
MultidimArray< double > yxt
Definition: basic_pca.h:162
MultidimArray< double > c1
Definition: basic_pca.h:163
double zn
Definition: basic_pca.h:165