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

#include <ahc_classifier.h>

Collaboration diagram for AHCClassifier:
Collaboration graph
[legend]

Public Member Functions

void clusterData (const Matrix2D< double > &X, int numberOfClusters=2, int distance=2, int linkageType=1)
 
void clusterWithDistance (const Matrix2D< double > &D, int numberOfClusters=2, int linkageType=1)
 

Public Attributes

Matrix1D< int > clusterAssigned
 
std::vector< std::vector< int > > cluster
 

Detailed Description

AHC classifier class.

Definition at line 38 of file ahc_classifier.h.

Member Function Documentation

◆ clusterData()

void AHCClassifier::clusterData ( const Matrix2D< double > &  X,
int  numberOfClusters = 2,
int  distance = 2,
int  linkageType = 1 
)

Cluster data. X is the data to classify, each row is an observation. Columns are features of that observation.

For the distances see http://www.alglib.net/translator/man/manual.cpp.html#sub_clusterizersetpoints 0 Chebyshev distance (L-inf norm) 1 city block distance (L1 norm) 2 Euclidean distance (L2 norm) 10 Pearson correlation: dist(a,b) = 1-corr(a,b) 11 Absolute Pearson correlation: dist(a,b) = 1-|corr(a,b)| 12 Uncentered Pearson correlation (cosine of the angle): dist(a,b) = a'b/(|a||b|) 13 Absolute uncentered Pearson correlation dist(a,b) = |a'b|/(|a||b|) 20 Spearman rank correlation: dist(a,b) = 1-rankcorr(a,b) 21 Absolute Spearman rank correlation dist(a,b) = 1-|rankcorr(a,b)|

For linkage: 0 complete linkage (default algorithm) 1 single linkage 2 unweighted average linkage 3 weighted average linkage

Definition at line 31 of file ahc_classifier.cpp.

32 {
34  try
35  {
36  // See example at http://www.alglib.net/translator/man/manual.cpp.html#example_clst_ahc
39 
42 
43  // Run Hierarchical Clustering
45  clusterizersetahcalgo(s, linkageType);
47  clusterizerrunahc(s, rep);
48 
49  // Now get K clusters
51  clusterizergetkclusters(rep, numberOfClusters, cidx, cz);
52  }
53  catch (alglib::ap_error e)
54  {
56  }
57 
58  // Collect results
61  VEC_ELEM(clusterAssigned,i)=cidx[i];
62 
63  std::vector<int> dummy;
64  cluster.clear();
65  for (int k=0; k<numberOfClusters; ++k)
66  cluster.push_back(dummy);
68  cluster[VEC_ELEM(clusterAssigned,i)].push_back(i);
69 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
std::string msg
Definition: ap.h:904
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void clusterizergetkclusters(const ahcreport &rep, const ae_int_t k, integer_1d_array &cidx, integer_1d_array &cz)
#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 clusterizersetahcalgo(const clusterizerstate &s, const ae_int_t algo)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
Matrix1D< int > clusterAssigned
std::vector< std::vector< int > > cluster
void clusterizercreate(clusterizerstate &s)
double dummy
TYPE distance(struct Point_T *p, struct Point_T *q)
Definition: point.cpp:28
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void clusterizersetpoints(const clusterizerstate &s, const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nfeatures, const ae_int_t disttype)
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
void clusterizerrunahc(const clusterizerstate &s, ahcreport &rep)
void setcontent(ae_int_t irows, ae_int_t icols, const double *pContent)
Definition: ap.cpp:6660
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89

◆ clusterWithDistance()

void AHCClassifier::clusterWithDistance ( const Matrix2D< double > &  D,
int  numberOfClusters = 2,
int  linkageType = 1 
)

Cluster given a distance matrix. X is the data to classify, each row is an observation. Columns are features of that observation.

For linkage: 0 complete linkage (default algorithm) 1 single linkage 2 unweighted average linkage 3 weighted average linkage

Definition at line 71 of file ahc_classifier.cpp.

72 {
74  try
75  {
76  // See example at https://www.tol-project.org/svn/tolp/OfficialTolArchiveNetwork/AlgLib/CppTools/source/alglib/manual.cpp.html#example_clst_kclusters
79 
82 
83  // Run Hierarchical Clustering
85  clusterizersetahcalgo(s, linkageType);
86  clusterizersetdistances(s, d, true);
87  clusterizerrunahc(s, rep);
88 
89  // Now get K clusters
91  clusterizergetkclusters(rep, numberOfClusters, cidx, cz);
92  }
93  catch (alglib::ap_error e)
94  {
96  }
97 
98  // Collect results
101  VEC_ELEM(clusterAssigned,i)=cidx[i];
102 
103  std::vector<int> dummy;
104  cluster.clear();
105  for (int k=0; k<numberOfClusters; ++k)
106  cluster.push_back(dummy);
108  cluster[VEC_ELEM(clusterAssigned,i)].push_back(i);
109 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
std::string msg
Definition: ap.h:904
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void clusterizergetkclusters(const ahcreport &rep, const ae_int_t k, integer_1d_array &cidx, integer_1d_array &cz)
#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
doublereal * d
void clusterizersetahcalgo(const clusterizerstate &s, const ae_int_t algo)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
Matrix1D< int > clusterAssigned
std::vector< std::vector< int > > cluster
void clusterizercreate(clusterizerstate &s)
double dummy
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
void clusterizerrunahc(const clusterizerstate &s, ahcreport &rep)
void setcontent(ae_int_t irows, ae_int_t icols, const double *pContent)
Definition: ap.cpp:6660
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89
void clusterizersetdistances(const clusterizerstate &s, const real_2d_array &d, const ae_int_t npoints, const bool isupper)

Member Data Documentation

◆ cluster

std::vector< std::vector<int> > AHCClassifier::cluster

There are as many elements in the vector as clusters. Each vector in the cluster contains the list of individuals assigned to this cluster.

Definition at line 49 of file ahc_classifier.h.

◆ clusterAssigned

Matrix1D<int> AHCClassifier::clusterAssigned

The i-th location is the number of the cluster of the i-th element in the input data. The length of this vector is the number of individuals.

Definition at line 44 of file ahc_classifier.h.


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