You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 regels
2.7 KiB

  1. /* The MIT License
  2. Copyright (c) 2016 Genome Research Ltd.
  3. Author: Petr Danecek <pd3@sanger.ac.uk>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. /*
  21. Simple hierarchical clustering
  22. */
  23. #ifndef __HCLUST_H__
  24. #define __HCLUST_H__
  25. #include <stdio.h>
  26. typedef struct _hclust_t hclust_t;
  27. typedef struct
  28. {
  29. float dist;
  30. int nmemb, *memb;
  31. }
  32. cluster_t;
  33. #define PDIST(mat,a,b) (mat)[((a)>(b)?((a)*((a)-1)/2+(b)):((b)*((b)-1)/2+(a)))]
  34. /*
  35. * hclust_init() - init and run clustering
  36. * @n: number of elements
  37. * @pdist: pairwise distances. The array will be modified by hclust and
  38. * must exist until hclust_destroy() is called
  39. */
  40. hclust_t *hclust_init(int n, float *pdist);
  41. void hclust_destroy(hclust_t *clust);
  42. /*
  43. * hclust_create_list() - returns a list of clusters
  44. * @min_inter_dist: minimum inter-cluster distance. If smaller, elements are considered
  45. * homogenous, belonging to the same cluster.
  46. * @max_intra_dist: maximum intra-cluster distance allowed. If smaller than 0,
  47. * the threshold can be heuristically lowered, otherwise considered
  48. * a fixed cutoff. The pointer will be filled to the cutoff actually used.
  49. */
  50. cluster_t *hclust_create_list(hclust_t *clust, float min_inter_dist, float *max_intra_dist, int *nclust);
  51. void hclust_destroy_list(cluster_t *clust, int nclust);
  52. /*
  53. * Access debugging data used in the decision making process. Note that this
  54. * must be called immediately after hclust_create_list because other calls,
  55. * such as hclust_create_dot(), invalidate the temporary data structures.
  56. */
  57. char **hclust_explain(hclust_t *clust, int *nlines);
  58. char *hclust_create_dot(hclust_t *clust, char **labels, float th);
  59. #endif