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

#include <hessianLLE.h>

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

Public Member Functions

void setSpecificParameters (int kNeighbours=12)
 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 kNeighbours
 
- 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 Hessian LLE dimensionality reduction

Definition at line 34 of file hessianLLE.h.

Member Function Documentation

◆ reduceDimensionality()

void HessianLLE::reduceDimensionality ( )
virtual

Reduce dimensionality.

Implements DimRedAlgorithm.

Definition at line 31 of file hessianLLE.cpp.

32 {
33  Matrix2D<int> neighboursMatrix;
34  Matrix2D<double> distanceNeighboursMatrix;
35 
36  kNearestNeighbours(*X, kNeighbours, neighboursMatrix, distanceNeighboursMatrix);
37 
38  size_t sizeY = MAT_YSIZE(*X);
39  size_t dp = outputDim * (outputDim+1)/2;
40  Matrix2D<double> weightMatrix, thisX, U, V, Vpr, Yi, Yi_complete, Yt, R, Pii;
41  Matrix1D<double> D, vector;
42 
43  weightMatrix.initZeros(dp*sizeY,sizeY);
44 
45  for(size_t index=0; index<MAT_YSIZE(*X);++index)
46  {
47  extractNearestNeighbours(*X, neighboursMatrix, index, thisX);
48  subtractColumnMeans(thisX);
49  thisX = thisX.transpose();
50  svdcmp(thisX, U, D, Vpr); // thisX = U * D * Vpr^t
51 
52  // Copy the first columns of Vpr onto V
53  V.resizeNoCopy(MAT_YSIZE(Vpr),outputDim);
54  for (size_t y=0; y<MAT_YSIZE(V); ++y)
55  memcpy(&MAT_ELEM(V,y,0),&MAT_ELEM(Vpr,y,0),outputDim*sizeof(double));
56 
57  //Basically, the above is applying PCA to the neighborhood of Xi.
58  //The PCA mapping that is found (and that is contained in V) is an
59  //approximation for the tangent space at Xi.
60 
61  //Build Hessian estimator
62  buildYiHessianEstimator(V,Yi,outputDim,dp);
63  completeYt(V, Yi, Yt);
65 
66  //Get the transpose of the last columns
67  size_t indexExtra = outputDim+1;
68  size_t Ydim = MAT_XSIZE(Yt)-indexExtra;
69  Pii.resizeNoCopy(Ydim,MAT_YSIZE(Yt));
71  MAT_ELEM(Pii,i,j) = MAT_ELEM(Yt,j,indexExtra+i);
72 
73  //Double check weights sum to 1
74  for (size_t j=0; j<dp; j++)
75  {
76  Pii.getRow(j,vector);
77  double sum = vector.sum();
78  if(sum > 0.0001)
79  vector*=1.0/sum;
80 
81  //Fill weight matrix
82  for(int k = 0; k<kNeighbours; k++){
83  size_t neighbourElem = MAT_ELEM(neighboursMatrix,index,k);
84  MAT_ELEM(weightMatrix,index*dp+j,neighbourElem) = VEC_ELEM(vector,k);
85  }
86  }
87  }
89  matrixOperation_AtA(weightMatrix,G);
90 
92  eigsBetween(G,1,outputDim,v,Y);
93  Y*=sqrt(sizeY);
94 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
void subtractColumnMeans(Matrix2D< double > &A)
Definition: matrix2d.cpp:230
void eigsBetween(const Matrix2D< double > &A, size_t I1, size_t I2, Matrix1D< double > &D, Matrix2D< double > &P)
Definition: matrix2d.cpp:324
Matrix2D< double > Y
Output data.
Definition: dimred_tools.h:147
void kNearestNeighbours(const Matrix2D< double > &X, int K, Matrix2D< int > &idx, Matrix2D< double > &distance, DimRedDistance2 f, bool computeSqrt)
void sqrt(Image< double > &op)
static double * y
Matrix2D< double > * X
Pointer to input data.
Definition: dimred_tools.h:141
void extractNearestNeighbours(const Matrix2D< double > &X, Matrix2D< int > &idx, int i, Matrix2D< double > &Xi)
void matrixOperation_AtA(const Matrix2D< double > &A, Matrix2D< double > &B)
Definition: matrix2d.cpp:436
#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
size_t outputDim
Output dim.
Definition: dimred_tools.h:144
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
void orthogonalizeColumnsGramSchmidt(Matrix2D< double > &M)
Definition: matrix2d.cpp:560
viol index
double sum(bool average=false) const
Definition: matrix1d.cpp:652
void initZeros()
Definition: matrix1d.h:592
void svdcmp(const Matrix2D< T > &a, Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v)
Definition: matrix2d.cpp:125
#define j
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
int kNeighbours
Definition: hessianLLE.h:37

◆ setSpecificParameters()

void HessianLLE::setSpecificParameters ( int  kNeighbours = 12)

Set specific parameters.

Definition at line 26 of file hessianLLE.cpp.

27 {
28  this->kNeighbours = kNeighbours;
29 }
int kNeighbours
Definition: hessianLLE.h:37

Member Data Documentation

◆ kNeighbours

int HessianLLE::kNeighbours

Definition at line 37 of file hessianLLE.h.


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