Xmipp  v3.23.11-Nereus
laplacianEigenmaps.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano coss@cnb.csic.es (2013)
4  * Daniel Albuerne Gonzalez d.albuerne@usp.ceu.es
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #include "laplacianEigenmaps.h"
28 
29 void LaplacianEigenmap::setSpecificParameters(double sigma, size_t numberOfNeighbours)
30 {
31  this->sigma=sigma;
32  this->numberOfNeighbours=numberOfNeighbours;
33 }
34 
36 {
37  Matrix2D<double> G,L,D;
38  Matrix1D<double> mappedX;
39  //Construct neighborhood graph
41  //Compute Gaussian kernel(heat kernel based weights)
42  computeSimilarityMatrix(G,sigma,true,true);
43  //Compute Laplacian
45  //Construct diagonal weight matrix
46  D.initZeros(MAT_YSIZE(G),MAT_YSIZE(G));
48  MAT_ELEM(D,i,i)+=MAT_ELEM(G,i,j);
49  //Construct eigenmaps
50  generalizedEigs(L,D,mappedX,Y);
51  keepColumns(Y,1,(int)outputDim);
52 }
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
Definition: matrix2d.h:104
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
void computeSimilarityMatrix(Matrix2D< double > &D2, double sigma, bool skipZeros, bool normalize)
Matrix2D< double > Y
Output data.
Definition: dimred_tools.h:147
Matrix2D< double > * X
Pointer to input data.
Definition: dimred_tools.h:141
void computeGraphLaplacian(const Matrix2D< double > &G, Matrix2D< double > &L)
#define i
size_t outputDim
Output dim.
Definition: dimred_tools.h:144
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
void computeDistanceToNeighbours(const Matrix2D< double > &X, int K, Matrix2D< double > &distance, DimRedDistance2 f, bool computeSqrt)
void generalizedEigs(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix1D< double > &D, Matrix2D< double > &P)
Definition: matrix2d.cpp:267
#define j
void setSpecificParameters(double sigma=1.0, size_t numberOfNeighbours=7)
Set specific parameters.
DimRedDistance2 distance
Distance function.
Definition: dimred_tools.h:150
void reduceDimensionality()
Reduce dimensionality.
void keepColumns(Matrix2D< double > &A, int j0, int jF)
Definition: matrix2d.cpp:551
void initZeros()
Definition: matrix2d.h:626