Confusion.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _Confusion_h_
  2. #define _Confusion_h_
  3. /* Confusion.h
  4. *
  5. * Copyright (C) 1993-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. #include "TableOfReal.h"
  21. #include "Categories.h"
  22. #include "Graphics.h"
  23. #include "Matrix.h"
  24. Thing_define (Confusion, TableOfReal) {
  25. void v_info ()
  26. override;
  27. };
  28. /*
  29. A Confusion matrix has both row and column labels. Row labels represent the stimulus names,
  30. column labels represent the responses.
  31. */
  32. autoConfusion Confusion_create (integer numberOfStimuli, integer numberOfResponses);
  33. autoConfusion Confusion_createSimple (conststring32 labels);
  34. autoConfusion Confusion_createFromStringses (Strings stimulusLabels, Strings responseLabels);
  35. autoConfusion Categories_to_Confusion (Categories me, Categories thee);
  36. void Confusion_increase (Confusion me, conststring32 stimulus, conststring32 response);
  37. /* Increase the confusion count by one: data['stim']['resp'] += 1; */
  38. double Confusion_getValue (Confusion me, conststring32 stimulus, conststring32 response);
  39. /* data['stim']['resp'] ; */
  40. void Confusion_getEntropies (Confusion me, double *out_h, double *out_hx, double *out_hy,
  41. double *out_hygx, double *out_hxgy, double *out_uygx, double *out_uxgy, double *out_uxy);
  42. /* x is column variable, y is row variable
  43. *out_h entropy of whole table;
  44. *out_hx entropy of x variable
  45. *out_hy entropy of y variable
  46. *out_hygx entropy of y given x
  47. *out_hxgy entropy of x given y
  48. *out_uygx dependency of y on x
  49. *out_uxgy dependency of x on y
  50. *out_uxy symmetrical dependency
  51. */
  52. void Confusion_getFractionCorrect (Confusion me, double *out_fraction, integer *out_numberOfCorrect);
  53. void Confusion_Matrix_draw (Confusion me, Matrix thee, Graphics g, integer index, double lowerPercentage, double xmin, double xmax, double ymin, double ymax, int garnish);
  54. /* 1. Draw my rowLabels centered at ( matrix->z[i][1], matrix->z[i][2]).
  55. 2. Draw arrows and circles according to:
  56. for (i=1; i <= my numberOfRows; i++)
  57. {
  58. if (index != 0 && index != i) continue;
  59. draw circle at i of width: my z[i][i]/rowSum;
  60. for (j=1; j <= my numberOfColumns; j++)
  61. {
  62. if (i != j && 100*my data[i][j]/rowSum > lowerPercentage)
  63. draw arrow from i to j of width: my data[i][j]/rowSum;
  64. }
  65. }
  66. */
  67. autoMatrix Confusion_difference (Confusion me, Confusion thee);
  68. /* return matrix with the difference between the two confusion matrices */
  69. integer Confusion_getNumberOfEntries (Confusion me);
  70. autoConfusion Confusion_groupStimuli (Confusion me, conststring32 labels, conststring32 newLabel, integer newpos);
  71. autoConfusion Confusion_groupResponses (Confusion me, conststring32 labels, conststring32 newLabel, integer newpos);
  72. autoConfusion Confusion_group (Confusion me, conststring32 labels, conststring32 newLabel, integer newpos);
  73. autoConfusion Confusion_condense (Confusion me, conststring32 search, conststring32 replace, integer maximumNumberOfReplaces, bool use_regexp);
  74. /*
  75. Group row and column labels according to search and replace.
  76. */
  77. autoConfusion TableOfReal_to_Confusion (TableOfReal me);
  78. autoTableOfReal Confusion_to_TableOfReal_marginals (Confusion me);
  79. /*
  80. Create a table with one extra row and one extra column with marginals,
  81. i.e., column and row sums.
  82. */
  83. void Confusion_drawAsNumbers (Confusion me, Graphics g, bool marginals, int iformat, int precision);
  84. /* option marginals draw one extra row and column with marginal sums. */
  85. #endif /* _Confusion_h_ */