cluster.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /******************************************************************************/
  2. /* The C Clustering Library.
  3. * Copyright (C) 2002 Michiel Jan Laurens de Hoon.
  4. *
  5. * This library was written at the Laboratory of DNA Information Analysis,
  6. * Human Genome Center, Institute of Medical Science, University of Tokyo,
  7. * 4-6-1 Shirokanedai, Minato-ku, Tokyo 108-8639, Japan.
  8. * Contact: mdehoon 'AT' gsc.riken.jp
  9. *
  10. * Permission to use, copy, modify, and distribute this software and its
  11. * documentation with or without modifications and for any purpose and
  12. * without fee is hereby granted, provided that any copyright notices
  13. * appear in all copies and that both those copyright notices and this
  14. * permission notice appear in supporting documentation, and that the
  15. * names of the contributors or copyright holders not be used in
  16. * advertising or publicity pertaining to distribution of the software
  17. * without specific prior permission.
  18. *
  19. * THE CONTRIBUTORS AND COPYRIGHT HOLDERS OF THIS SOFTWARE DISCLAIM ALL
  20. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
  22. * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT
  23. * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  24. * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  25. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  26. * OR PERFORMANCE OF THIS SOFTWARE.
  27. *
  28. */
  29. #ifndef TreeClusterINCLUDE
  30. #define TreeClusterINCLUDE
  31. #ifndef min
  32. #define min(x, y) ((x) < (y) ? (x) : (y))
  33. #endif
  34. #ifndef max
  35. #define max(x, y) ((x) > (y) ? (x) : (y))
  36. #endif
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #ifdef WINDOWS
  40. # include <windows.h>
  41. #endif
  42. #endif
  43. #define CLUSTERVERSION "1.49"
  44. /* Chapter 2 */
  45. double clusterdistance (int nrows, int ncolumns, double** data, int** mask,
  46. double weight[], int n1, int n2, int index1[], int index2[], char dist,
  47. char method, int transpose);
  48. double** distancematrix (int ngenes, int ndata, double** data,
  49. int** mask, double* weight, char dist, int transpose);
  50. /* Chapter 3 */
  51. int getclustercentroids(int nclusters, int nrows, int ncolumns,
  52. double** data, int** mask, int clusterid[], double** cdata, int** cmask,
  53. int transpose, char method);
  54. void getclustermedoids(int nclusters, int nelements, double** distance,
  55. int clusterid[], int centroids[], double errors[]);
  56. void kcluster (int nclusters, int ngenes, int ndata, double** data,
  57. int** mask, double weight[], int transpose, int npass, char method, char dist,
  58. int clusterid[], double* error, int* ifound);
  59. void kmedoids (int nclusters, int nelements, double** distance,
  60. int npass, int clusterid[], double* error, int* ifound);
  61. /* Chapter 4 */
  62. typedef struct {int left; int right; double distance;} Node;
  63. /*
  64. * A Node struct describes a single node in a tree created by hierarchical
  65. * clustering. The tree can be represented by an array of n Node structs,
  66. * where n is the number of elements minus one. The integers left and right
  67. * in each Node struct refer to the two elements or subnodes that are joined
  68. * in this node. The original elements are numbered 0..nelements-1, and the
  69. * nodes -1..-(nelements-1). For each node, distance contains the distance
  70. * between the two subnodes that were joined.
  71. */
  72. Node* treecluster (int nrows, int ncolumns, double** data, int** mask,
  73. double *weight, int transpose, char dist, char method, double** distmatrix);
  74. void cuttree (int nelements, Node* tree, int nclusters, int clusterid[]);
  75. /* Chapter 5 */
  76. void somcluster (int nrows, int ncolumns, double** data, int** mask,
  77. const double weight[], int transpose, int nxnodes, int nynodes,
  78. double inittau, int niter, char dist, double*** celldata,
  79. int clusterid[][2]);
  80. /* Chapter 6 */
  81. int pca(int m, int n, double** u, double** v, double* w);
  82. /* Utility routines, currently undocumented */
  83. void sort(int n, const double data[], int index[]);
  84. double mean(int n, double x[]);
  85. double median (int n, double x[]);
  86. double* calculate_weights(int nrows, int ncolumns, double** data, int** mask,
  87. double weights[], int transpose, char dist, double cutoff, double exponent);
  88. #ifdef __cplusplus
  89. } //extern "C"
  90. #endif
  91. #endif