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

#include <lpp.h>

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

Public Member Functions

void setSpecificParameters (int k=12, double sigma=1.)
 Set specific parameters. More...
 
void reduceDimensionality ()
 Reduce dimensionality. More...
 
- Public Member Functions inherited from DimRedAlgorithm
 DimRedAlgorithm ()
 Empty constructor. More...
 
void setInputData (Matrix2D< double > &X)
 Set input data. More...
 
void setOutputDimensionality (size_t outputDim)
 Set output dimensionality. More...
 
const Matrix2D< double > & getReducedData ()
 Get reduced data. More...
 

Public Attributes

int k
 
double sigma
 
- Public Attributes inherited from DimRedAlgorithm
Matrix2D< double > * X
 Pointer to input data. More...
 
size_t outputDim
 Output dim. More...
 
Matrix2D< double > Y
 Output data. More...
 
DimRedDistance2 distance
 Distance function. More...
 
FileName fnMapping
 Save mapping. More...
 

Detailed Description

Class for making a LPP dimensionality reduction

Definition at line 37 of file lpp.h.

Member Function Documentation

◆ reduceDimensionality()

void LPP::reduceDimensionality ( )
virtual

Reduce dimensionality.

Reduce dimensionality method based on the Locality Preserving Projections (LPP) algorithm. These are linear projective maps that arise by solving a variational problem that optimally preserves the neighborhood structure of the data set.

Implements DimRedAlgorithm.

Definition at line 37 of file lpp.cpp.

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
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
#define j
DimRedDistance2 distance
Distance function.
Definition: dimred_tools.h:150
#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

◆ setSpecificParameters()

void LPP::setSpecificParameters ( int  k = 12,
double  sigma = 1. 
)

Set specific parameters.

Definition at line 28 of file lpp.cpp.

29 {
30  this->k=k;
31  this->sigma=sigma;
32 }
double sigma
Definition: lpp.h:41
int k
Definition: lpp.h:40

Member Data Documentation

◆ k

int LPP::k

Definition at line 40 of file lpp.h.

◆ sigma

double LPP::sigma

Definition at line 41 of file lpp.h.


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