Xmipp  v3.23.11-Nereus
lpp.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Oscar Hueros Fernandez o.hueros@gmail.com (2013)
4  *
5  * Universidad San Pablo CEU
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 
26 #include "lpp.h"
27 
28 void LPP::setSpecificParameters(int k, double sigma)
29 {
30  this->k=k;
31  this->sigma=sigma;
32 }
38 {
39  // Compute the distance to the k nearest neighbors
41  computeDistanceToNeighbours(*X, k, D2, distance, false);
42 
43  // Compute similarity matrix
44  computeSimilarityMatrix(D2,sigma,true,true);
45 
46  // Compute graph laplacian
49 
50  Matrix2D<double> DP, LP;
53 
54  // Compute eigenvalues and eigenvectors resolving the generalized eigenvector problem
55  Matrix2D<double> Peigvec, eigvector;
56  Matrix1D<double> Deigval;
57  generalizedEigs(LP, DP, Deigval, Peigvec);
58 
59  // Sort the eigenvalues in ascending order
60  Matrix1D<int> idx;
61  Deigval.indexSort(idx);
62 
63  // Sort the eigenvalues in descending order and get the smallest eigenvectors
64  eigvector.resizeNoCopy(MAT_YSIZE(Peigvec),outputDim);
65  for (size_t j=0; j<outputDim; ++j)
66  {
67  int idxj=VEC_ELEM(idx,j)-1;
68  for (int i=0; i<MAT_YSIZE(Peigvec); ++i)
69  MAT_ELEM(eigvector,i,j)=MAT_ELEM(Peigvec,i,idxj);
70  }
71 
72  // Compute the result of the reduce dimensionality method
73  Y=*X * eigvector;
74  if (fnMapping!="")
75  eigvector.write(fnMapping);
76 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
void computeSimilarityMatrix(Matrix2D< double > &D2, double sigma, bool skipZeros, bool normalize)
Matrix2D< double > Y
Output data.
Definition: dimred_tools.h:147
void indexSort(Matrix1D< int > &indx) const
Definition: matrix1d.cpp:861
Matrix2D< double > * X
Pointer to input data.
Definition: dimred_tools.h:141
void computeGraphLaplacian(const Matrix2D< double > &G, Matrix2D< double > &L)
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void resizeNoCopy(int Ydim, int Xdim)
Definition: matrix2d.h:534
size_t outputDim
Output dim.
Definition: dimred_tools.h:144
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
double sigma
Definition: lpp.h:41
void computeDistanceToNeighbours(const Matrix2D< double > &X, int K, Matrix2D< double > &distance, DimRedDistance2 f, bool computeSqrt)
int k
Definition: lpp.h:40
void generalizedEigs(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix1D< double > &D, Matrix2D< double > &P)
Definition: matrix2d.cpp:267
void reduceDimensionality()
Reduce dimensionality.
Definition: lpp.cpp:37
#define j
DimRedDistance2 distance
Distance function.
Definition: dimred_tools.h:150
void setSpecificParameters(int k=12, double sigma=1.)
Set specific parameters.
Definition: lpp.cpp:28
#define DP(x)
FileName fnMapping
Save mapping.
Definition: dimred_tools.h:153
void write(const FileName &fn) const
Definition: matrix2d.cpp:113
void matrixOperation_XtAX_symmetric(const Matrix2D< double > &X, const Matrix2D< double > &A, Matrix2D< double > &B)
Definition: matrix2d.cpp:513