1.5.1
CCC
 
cluster.cpp File Reference
#include "geoslib_old_f.h"
#include "Basic/Law.hpp"
#include "Basic/Memory.hpp"
#include <limits.h>

Macros

#define DBL_MAXIMUM   1.e30
 
#define DATA(iech, ivar)   (data[(iech) * nvar + (ivar)])
 
#define DATA1(iech, ivar)   (data1[(iech) * nvar + (ivar)])
 
#define DATA2(iech, ivar)   (data2[(iech) * nvar + (ivar)])
 
#define CDATA(icl, ivar)   (cdata[(icl) * nvar + (ivar)])
 
#define DISTMATRIX(i, j)   (distmatrix[(i) * nech + (j)])
 

Functions

static double st_distance (int nvar, const double *data1, const double *data2, int index1, int index2)
 
static void st_randomassign (int nclusters, int nech, int *clusterid)
 
static void st_printclusterlist (int nclusters, int nech, int *clusterid)
 
static void st_printclustercount (int nclusters, int nech, const int *clusterid)
 
static void st_getclustermeans (const double *data, int nvar, int nech, int nclusters, const int *clusterid, double *cdata, int *cmask)
 
static void st_getclustermedian (const double *data, int nvar, int nech, int nclusters, const int *clusterid, double *cdata, double *cache)
 
static double * st_get_distmatrix (double *data, int nvar, int nech)
 
static void st_getclustermedoids (int nech, int nclusters, const double *distmatrix, const int *clusterid, int *centroids, double *errors)
 
double * kclusters (double *data, int nvar, int nech, int nclusters, int npass, int mode, int verbose)
 
int * kmedoids (double *data, int nvar, int nech, int nclusters, int npass, int verbose)
 

Macro Definition Documentation

◆ CDATA

#define CDATA (   icl,
  ivar 
)    (cdata[(icl) * nvar + (ivar)])

◆ DATA

#define DATA (   iech,
  ivar 
)    (data[(iech) * nvar + (ivar)])

◆ DATA1

#define DATA1 (   iech,
  ivar 
)    (data1[(iech) * nvar + (ivar)])

◆ DATA2

#define DATA2 (   iech,
  ivar 
)    (data2[(iech) * nvar + (ivar)])

◆ DBL_MAXIMUM

#define DBL_MAXIMUM   1.e30

◆ DISTMATRIX

#define DISTMATRIX (   i,
 
)    (distmatrix[(i) * nech + (j)])

Function Documentation

◆ kclusters()

double* kclusters ( double *  data,
int  nvar,
int  nech,
int  nclusters,
int  npass,
int  mode,
int  verbose 
)

Perform k-means clustering on a given set of variables. The number of clusters is given in input

Returns
Array of cluster coordinates
Parameters
[in]dataArray of values
[in]nvarNumber of samples
[in]nechNumber of variables
[in]nclustersNumber if clusters
[in]npassNumber of times clustering is performed
[in]mode0 for k-means and 1 for k-medians
[in]verboseVerbose option

◆ kmedoids()

int* kmedoids ( double *  data,
int  nvar,
int  nech,
int  nclusters,
int  npass,
int  verbose 
)

Perform k-medoids clustering on a given set of variables. The number of clusters is given in input

Returns
Array of cluster indices
Parameters
[in]dataArray of values
[in]nvarNumber of samples
[in]nechNumber of variables
[in]nclustersNumber if clusters
[in]npassNumber of times clustering is performed
[in]verboseVerbose option

◆ st_distance()

static double st_distance ( int  nvar,
const double *  data1,
const double *  data2,
int  index1,
int  index2 
)
static

Calculate the distance between two samples

Parameters
[in]nvarNumber of variables
[in]data1Array of values for first part
[in]data2Array of values for second part
[in]index1Rank of the first sample
[in]index2Rank of the second sample

◆ st_get_distmatrix()

static double* st_get_distmatrix ( double *  data,
int  nvar,
int  nech 
)
static

Evaluate the distance matrix

Parameters
[in]dataArray of values
[in]nvarNumber of samples
[in]nechNumber of variables

◆ st_getclustermeans()

static void st_getclustermeans ( const double *  data,
int  nvar,
int  nech,
int  nclusters,
const int *  clusterid,
double *  cdata,
int *  cmask 
)
static

Find the center of a cluster

Parameters
[in]nclustersNumber if clusters
[in]nvarNumber of samples
[in]nechNumber of variables
[in]dataArray of values
[in]clusteridArray of cluster number for each sample
[out]cdataArray containing the centroids
[out]cmaskArray containing the number of sample per cluster

◆ st_getclustermedian()

static void st_getclustermedian ( const double *  data,
int  nvar,
int  nech,
int  nclusters,
const int *  clusterid,
double *  cdata,
double *  cache 
)
static

Find the median of a cluster

Parameters
[in]nclustersNumber if clusters
[in]nvarNumber of samples
[in]nechNumber of variables
[in]dataArray of values
[in]clusteridArray of cluster number for each sample
[out]cdataArray containing the centroids
[out]cacheArray for storing data of a cluster

◆ st_getclustermedoids()

static void st_getclustermedoids ( int  nech,
int  nclusters,
const double *  distmatrix,
const int *  clusterid,
int *  centroids,
double *  errors 
)
static

Find the center of a cluster

Parameters
[in]distmatrixMatrix of distances
[in]nechNumber of variables
[in]nclustersNumber if clusters
[in]clusteridArray of cluster number for each sample
[out]centroidsArray of centroids
[out]errorsArray containing within-cluster distances

◆ st_printclustercount()

static void st_printclustercount ( int  nclusters,
int  nech,
const int *  clusterid 
)
static

Print the number of samples per cluster

Parameters
[in]nclustersNumber if clusters
[in]nechNumber of samples
[in]clusteridArray of cluster number for each sample

◆ st_printclusterlist()

static void st_printclusterlist ( int  nclusters,
int  nech,
int *  clusterid 
)
static

Print the list of cluster per sample

Parameters
[in]nclustersNumber if clusters
[in]nechNumber of samples
[in]clusteridArray of cluster number for each sample

◆ st_randomassign()

static void st_randomassign ( int  nclusters,
int  nech,
int *  clusterid 
)
static

Initial random assignment of samples to clusters

Parameters
[in]nclustersNumber if clusters
[in]nechNumber of samples
[out]clusteridArray of cluster number for each sample