GaussianMixture.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef _GaussianMixture_h_
  2. #define _GaussianMixture_h_
  3. /* GaussianMixture.h
  4. *
  5. * Copyright (C) 2010-2018 David Weenink
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. djmw 20101021 initial version
  22. djmw 20110306 Latest modification.
  23. */
  24. #include "ClassificationTable.h"
  25. #include "Matrix.h"
  26. #include "SSCP.h"
  27. #include "TableOfReal_extensions.h"
  28. #include "GaussianMixture_def.h"
  29. /*
  30. Constraints for a Gaussian mixture:
  31. all covariances have the same 'dimension' parameter
  32. */
  33. autoGaussianMixture GaussianMixture_create (integer numberOfComponents, integer dimension, integer storage);
  34. /* Start each function with expand and end with unExpand */
  35. void GaussianMixture_expandPCA (GaussianMixture me);
  36. void GaussianMixture_unExpandPCA (GaussianMixture me);
  37. void GaussianMixture_drawConcentrationEllipses (GaussianMixture me, Graphics g,
  38. double scale, int confidence, char32 *label, int pcaDirections, integer d1, integer d2,
  39. double xmin, double xmax, double ymin, double ymax, int fontSize, int garnish);
  40. void GaussianMixture_PCA_drawConcentrationEllipses (GaussianMixture me, PCA him, Graphics g,
  41. double scale, int confidence, char32 *label, integer d1, integer d2,
  42. double xmin, double xmax, double ymin, double ymax, int fontSize, int garnish);
  43. void GaussianMixture_drawMarginalPdf (GaussianMixture me, Graphics g, integer d, double xmin,
  44. double xmax, double ymin, double ymax, integer npoints, integer nbins, int garnish);
  45. void GaussianMixture_PCA_drawMarginalPdf (GaussianMixture me, PCA him, Graphics g, integer d,
  46. double xmin, double xmax, double ymin, double ymax, integer npoints, integer nbins, int garnish);
  47. autoGaussianMixture TableOfReal_to_GaussianMixture_fromRowLabels (TableOfReal me, integer storage);
  48. void GaussianMixture_initialGuess (GaussianMixture me, TableOfReal thee, double nSigmas, double ru_range);
  49. /*
  50. Give an initial guess for the centroids and covariances of the GaussianMixture based on the data in the table.
  51. Position centroids on the nSigma-ellips in the pc1-pc2 plane with some random variation and the covariances as
  52. a scaled down version of the total covariance.
  53. The randomly varied position of a centroid on the ellipse is parametrized as:
  54. x = a * (1 + randomUniform (-ru_range, ru_range)) * cos (alpha)
  55. y = b * (1 + randomUniform (-ru_range, ru_range)) * sin (alpha).
  56. where a and b are the axes of the ellipse and 0<= alpha <= 2pi.
  57. */
  58. #define GaussianMixture_LIKELIHOOD 0
  59. #define GaussianMixture_MML 1
  60. #define GaussianMixture_BIC 2
  61. #define GaussianMixture_AIC 3
  62. #define GaussianMixture_AICC 4
  63. #define GaussianMixture_CD_LIKELIHOOD 5
  64. conststring32 GaussianMixture_criterionText (int criterion);
  65. autoGaussianMixture TableOfReal_to_GaussianMixture (TableOfReal me, integer numberOfComponents, double delta_lnp, integer maxNumberOfIterations, double lambda, int storage, int criterion);
  66. void GaussianMixture_TableOfReal_improveLikelihood (GaussianMixture me, TableOfReal thee, double delta_lnp, integer maxNumberOfIterations, double lambda, int criterion);
  67. autoGaussianMixture GaussianMixture_TableOfReal_to_GaussianMixture_CEMM (GaussianMixture me, TableOfReal thee, integer minNumberOfComponents, double delta_l, integer maxNumberOfIterations, double lambda, int criterion);
  68. void GaussianMixture_splitComponent (GaussianMixture me, integer component);
  69. autoClassificationTable GaussianMixture_TableOfReal_to_ClassificationTable (GaussianMixture me, TableOfReal thee);
  70. autoTableOfReal GaussianMixture_TableOfReal_to_TableOfReal_BHEPNormalityTests (GaussianMixture me, TableOfReal thee, double h);
  71. double GaussianMixture_TableOfReal_getLikelihoodValue (GaussianMixture me, TableOfReal thee, int criterion);
  72. double GaussianMixture_getProbabilityAtPosition (GaussianMixture me, constVEC v);
  73. double GaussianMixture_getProbabilityAtPosition_string (GaussianMixture me, conststring32 pos);
  74. double GaussianMixture_getMarginalProbabilityAtPosition (GaussianMixture me, constVEC pos, double x);
  75. autoCorrelation GaussianMixture_TableOfReal_to_Correlation (GaussianMixture me, TableOfReal thee);
  76. /* Correlation between components based on the data in the table */
  77. autoCovariance GaussianMixture_to_Covariance_total (GaussianMixture me);
  78. autoCovariance GaussianMixture_to_Covariance_between (GaussianMixture me);
  79. autoCovariance GaussianMixture_to_Covariance_within (GaussianMixture me);
  80. autoCovariance GaussianMixture_extractComponent(GaussianMixture me, integer component);
  81. autoTableOfReal GaussianMixture_extractCentroids (GaussianMixture me);
  82. autoTableOfReal GaussianMixture_extractMixingProbabilities (GaussianMixture me);
  83. autoPCA GaussianMixture_to_PCA (GaussianMixture me);
  84. autoMatrix GaussianMixture_PCA_to_Matrix_density (GaussianMixture me, PCA pca, integer d1, integer d2, double xmin, double xmax, integer nx, double ymin, double ymax, integer ny);
  85. void GaussianMixture_PCA_getIntervalsAlongDirections (GaussianMixture me, PCA thee, integer d1, integer d2, double nsigmas, double *xmin, double *xmax, double *ymin, double *ymax);
  86. void GaussianMixture_PCA_getIntervalAlongDirection (GaussianMixture me, PCA thee, integer d, double nsigmas, double *xmin, double *xmax);
  87. void GaussianMixture_getIntervalAlongDirection (GaussianMixture me, integer d, double nsigmas, double *xmin, double *xmax);
  88. void GaussianMixture_getIntervalsAlongDirections (GaussianMixture me, integer d1, integer d2, double nsigmas, double *xmin, double *xmax, double *ymin, double *ymax);
  89. /* with on demand expand of pca ! */
  90. int GaussianMixture_generateOneVector_inline (GaussianMixture me, VEC c, char32 **covname, VEC buf);
  91. autoTableOfReal GaussianMixture_to_TableOfReal_randomSampling (GaussianMixture me, integer numberOfPoints);
  92. #endif /* _GaussianMixture_h_ */