DataModeler.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #ifndef _DataModeler_h_
  2. #define _DataModeler_h_
  3. /* DataModeler.h
  4. *
  5. * Copyright (C) 2014-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 20140217
  22. */
  23. #define DataModeler_TYPE_POLYNOMIAL 0
  24. #define DataModeler_TYPE_LEGENDRE 1
  25. #define DataModeler_PARAMETER_FREE 0
  26. #define DataModeler_PARAMETER_FIXED 1
  27. #define DataModeler_PARAMETER_UNDEFINED -1
  28. #define DataModeler_DATA_WEIGH_EQUAL 0
  29. #define DataModeler_DATA_WEIGH_SIGMA 1
  30. #define DataModeler_DATA_WEIGH_RELATIVE 2
  31. #define DataModeler_DATA_WEIGH_SQRT 3
  32. #define DataModeler_DATA_WEIGH_SQRT 3
  33. #define DataModeler_DATA_VALID 0
  34. #define DataModeler_DATA_INVALID -1
  35. #define DataModeler_DATA_FROM_FIT 1
  36. #define DataModeler_DATA_FROM_COPY1 2
  37. #define DataModeler_DATA_FROM_COPY2 3
  38. #define DataModeler_DATA_FROM_COPY3 4
  39. #define DataModeler_DATA_FROM_COPY4 5
  40. #define FormantModeler_NOSHIFT_TRACKS 0
  41. #define FormantModeler_UPSHIFT_TRACKS 1
  42. #define FormantModeler_DOWNSHIFT_TRACKS 2
  43. #define FormantModeler_DATA_FROM_LOWER 12
  44. #define FormantModeler_DATA_FROM_UPPER 13
  45. #include "Collection.h"
  46. #include "Pitch.h"
  47. #include "OptimalCeilingTier.h"
  48. #include "Sound_to_Formant.h"
  49. #include "SSCP.h"
  50. #include "Table.h"
  51. #include "DataModeler_def.h"
  52. Thing_define (PitchModeler, DataModeler) {
  53. // void v_info ()
  54. // override;
  55. };
  56. void DataModeler_init (DataModeler me, double xmin, double xmax, integer numberOfDataPoints, integer numberOfParameters, int type);
  57. autoDataModeler DataModeler_create (double xmin, double xmax, integer numberOfDataPoints, integer numberOfParameters, int type);
  58. autoDataModeler DataModeler_createSimple (double xmin, double xmax, integer numberOfDataPoints,
  59. conststring32 parameters, double gaussianNoiseStd, int type);
  60. void DataModeler_setBasisFunctions (DataModeler me, int type);
  61. void DataModeler_draw_inside (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  62. int estimated, integer numberOfParameters, int errorbars, int connectPoints, double barWidth_mm, double horizontalOffset_mm, int drawDots);
  63. void DataModeler_speckle_inside (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  64. int estimated, integer numberOfParameters, int errorbars, double barWidth_mm, double horizontalOffset_mm);
  65. void DataModeler_speckle (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  66. int estimated, integer numberOfParameters, int errorbars, double barWidth_mm, double horizontalOffset_mm, bool garnish);
  67. void DataModeler_drawTrack (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  68. int estimated, integer numberOfParameters, double horizontalOffset_mm, bool garnish);
  69. void DataModeler_drawTrack_inside (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  70. int estimated, integer numberOfParameters, double horizontalOffset_mm);
  71. void DataModeler_drawOutliersMarked_inside (DataModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  72. double numberOfSigmas, int useSigmaY, conststring32 mark, int marksFontSize, double horizontalOffset_mm);
  73. /* Get the y-value of the fitted function at x */
  74. void DataModeler_setTolerance (DataModeler me, double tolerance);
  75. void DataModeler_fit (DataModeler me);
  76. // sigmaY used in fit or not.
  77. void DataModeler_setDataWeighing (DataModeler me, int useSigmaY);
  78. integer DataModeler_getNumberOfFixedParameters (DataModeler me);
  79. void DataModeler_setParameterValue (DataModeler me, integer index, double value, int status);
  80. void DataModeler_setParameterValueFixed (DataModeler me, integer index, double value);
  81. void DataModeler_setParametersFree (DataModeler me, integer fromIndex, integer toIndex);
  82. double DataModeler_getParameterValue (DataModeler me, integer index);
  83. int DataModeler_getParameterStatus (DataModeler me, integer index);
  84. double DataModeler_getParameterStandardDeviation (DataModeler me, integer index);
  85. double DataModeler_getVarianceOfParameters (DataModeler me, integer fromIndex, integer toIndex, integer *numberOfFreeParameters);
  86. void DataModeler_setParameterValuesToZero (DataModeler me, double numberOfSigmas);
  87. double DataModeler_estimateSigmaY (DataModeler me);
  88. void DataModeler_getExtremaY (DataModeler me, double *ymin, double *ymax);
  89. double DataModeler_getModelValueAtX (DataModeler me, double x);
  90. double DataModeler_getModelValueAtIndex (DataModeler me, integer index);
  91. double DataModeler_getWeightedMean (DataModeler me);
  92. integer DataModeler_getNumberOfInvalidDataPoints (DataModeler me);
  93. double DataModeler_getDataPointXValue (DataModeler me, integer index);
  94. double DataModeler_getDataPointYValue (DataModeler me, integer index);
  95. void DataModeler_setDataPointXValue (DataModeler me, integer index, double value);
  96. void DataModeler_setDataPointYValue (DataModeler me, integer index, double value);
  97. void DataModeler_setDataPointValues (DataModeler me, integer index, double xvalue, double yvalue);
  98. int DataModeler_getDataPointStatus (DataModeler me, integer index);
  99. void DataModeler_setDataPointStatus (DataModeler me, integer index, int status);
  100. void DataModeler_setDataPointYSigma (DataModeler me, integer index, double sigma);
  101. double DataModeler_getDataPointYSigma (DataModeler me, integer index);
  102. double DataModeler_getResidualSumOfSquares (DataModeler me, integer *numberOfDataPoints);
  103. void DataModeler_getZScores (DataModeler me, int useSigmaY, double zscores[]);
  104. double DataModeler_getDegreesOfFreedom (DataModeler me);
  105. double DataModeler_getChiSquaredQ (DataModeler me, int useSigmaY, double *out_probability, double *out_ndf);
  106. double DataModeler_getCoefficientOfDetermination (DataModeler me, double *ssreg, double *sstot);
  107. void DataModeler_reportChiSquared (DataModeler me, int weighDataType);
  108. autoFormant Formant_extractPart (Formant me, double tmin, double tmax);
  109. autoCovariance DataModeler_to_Covariance_parameters (DataModeler me);
  110. autoTable DataModeler_to_Table_zscores (DataModeler me, int useSigmaY);
  111. autoFormantModeler FormantModeler_create (double tmin, double tmax, integer numberOfFormants, integer numberOfDataPoints, integer numberOfParameters);
  112. double FormantModeler_indexToTime (FormantModeler me, integer index);
  113. void FormantModeler_fit (FormantModeler me);
  114. void FormantModeler_drawBasisFunction (FormantModeler me, Graphics g, double tmin, double tmax, double fmin, double fmax,
  115. integer iformant, integer iterm, bool scaled, integer numberOfPoints, bool garnish);
  116. void FormantModeler_setDataWeighing (FormantModeler me, integer fromFormant, integer toFormant, int useSigmaY);
  117. void FormantModeler_setParameterValueFixed (FormantModeler me, integer iformant, integer index, double value);
  118. void FormantModeler_setParametersFree (FormantModeler me, integer fromFormant, integer toFormant, integer fromIndex, integer toIndex);
  119. void FormantModeler_setParameterValuesToZero (FormantModeler me, integer fromFormant, integer toFormant, double numberOfSigmas);
  120. void FormantModeler_setTolerance (FormantModeler me, double tolerance);
  121. void FormantModeler_speckle (FormantModeler me, Graphics g, double tmin, double tmax, double fmax,
  122. integer fromTrack, integer toTrack, int estimated, integer numberOfParameters,
  123. int errorBars, double barWidth_mm, double horizontalOffset_mm, bool garnish);
  124. void FormantModeler_drawTracks (FormantModeler me, Graphics g, double tmin, double tmax, double fmax, integer fromTrack, integer toTrack,
  125. int estimated, integer numberOfParameters, double horizontalOffset_mm, bool garnish);
  126. void FormantModeler_drawOutliersMarked (FormantModeler me, Graphics g, double tmin, double tmax, double fmax, integer fromTrack, integer toTrack,
  127. double numberOfSigmas, int useSigmaY, conststring32 mark, int marksFontSize, double horizontalOffset_mm, bool garnish);
  128. void FormantModeler_drawCumulativeChiScores (FormantModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  129. int useSigmaY, bool garnish);
  130. void FormantModeler_drawVariancesOfShiftedTracks (FormantModeler me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  131. int shiftDirection, integer fromFormant, integer toFormant, bool garnish);
  132. void FormantModeler_normalProbabilityPlot (FormantModeler me, Graphics g, integer iformant,
  133. int useSigmaY, integer numberOfQuantiles, double numberOfSigmas, int labelSize, conststring32 label, bool garnish);
  134. autoTable FormantModeler_to_Table_zscores (FormantModeler me, int useSigmaY);
  135. autoCovariance FormantModeler_to_Covariance_parameters (FormantModeler me, integer iformant);
  136. double FormantModeler_getChiSquaredQ (FormantModeler me, integer fromFormant, integer toFormant, int useSigmaY, double *probability, double *ndf);
  137. double FormantModeler_getCoefficientOfDetermination (FormantModeler me, integer fromFormant, integer toFormant);
  138. double FormantModeler_getStandardDeviation (FormantModeler me, integer iformant);
  139. double FormantModeler_getResidualSumOfSquares (FormantModeler me, integer iformant, integer *numberOfDataPoints);
  140. double FormantModeler_getEstimatedValueAtTime (FormantModeler me, integer iformant, double time);
  141. integer FormantModeler_getNumberOfParameters (FormantModeler me, integer iformant);
  142. integer FormantModeler_getNumberOfFixedParameters (FormantModeler me, integer iformant);
  143. double FormantModeler_getParameterStandardDeviation ( FormantModeler me, integer iformant, integer index);
  144. double FormantModeler_getVarianceOfParameters (FormantModeler me, integer fromFormant, integer toFormant, integer fromIndex, integer toIndex,
  145. integer *numberOfFreeParameters);
  146. int FormantModeler_getParameterStatus (FormantModeler me, integer iformant, integer index);
  147. integer FormantModeler_getNumberOfDataPoints (FormantModeler me);
  148. integer FormantModeler_getNumberOfInvalidDataPoints (FormantModeler me, integer iformant);
  149. void FormantModeler_setDataPointStatus (FormantModeler me, integer iformant, integer index, int status);
  150. int FormantModeler_getDataPointStatus (FormantModeler me, integer iformant, integer index);
  151. double FormantModeler_getDataPointValue (FormantModeler me, integer iformant, integer index);
  152. void FormantModeler_setDataPointValue (FormantModeler me, integer iformant, integer index, double value);
  153. double FormantModeler_getDataPointSigma (FormantModeler me, integer iformant, integer index);
  154. void FormantModeler_setDataPointSigma (FormantModeler me, integer iformant, integer index, double sigma);
  155. double FormantModeler_getDegreesOfFreedom (FormantModeler me, integer iformant);
  156. integer FormantModeler_getNumberOfTracks (FormantModeler me);
  157. double FormantModeler_getModelValueAtTime (FormantModeler me, integer iformant, double time);
  158. double FormantModeler_getModelValueAtIndex (FormantModeler me, integer iformant, integer index);
  159. double FormantModeler_getWeightedMean (FormantModeler me, integer iformant);
  160. double FormantModeler_getParameterValue (FormantModeler me, integer iformant, integer iparameter);
  161. autoFormantModeler Formant_to_FormantModeler (Formant me, double tmin, double tmax, integer numberOfFormants,
  162. integer numberOfParametersPerTrack, int bandwidthEstimatesSigma);
  163. autoFormant FormantModeler_to_Formant (FormantModeler me, int estimate, int estimateUndefined);
  164. autoFormantModeler FormantModeler_processOutliers (FormantModeler me, double numberOfSigmas, int useSigmaY);
  165. double FormantModeler_getSmoothnessValue (FormantModeler me, integer fromFormant, integer toFormant,
  166. integer numberOfParametersPerTrack, double power);
  167. double FormantModeler_getAverageDistanceBetweenTracks (FormantModeler me, integer track1, integer track2, int type);
  168. void FormantModeler_reportChiSquared (FormantModeler me, int weighDataType);
  169. integer Formants_getSmoothestInInterval (CollectionOf<structFormant>* me, double tmin, double tmax, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int useBandWidthsForTrackEstimation, int useConstraints, double numberOfSigmas, double power, double minF1, double maxF1, double minF2, double maxF2, double minF3);
  170. double FormantModeler_getFormantsConstraintsFactor (FormantModeler me, double minF1, double maxF1, double minF2, double maxF2, double minF3);
  171. autoFormant Formants_extractSmoothestPart (CollectionOf<structFormant>* me, double tmin, double tmax, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int useBandWidthsForTrackEstimation, double numberOfSigmas, double power);
  172. autoFormant Formants_extractSmoothestPart_withFormantsConstraints (CollectionOf<structFormant>* me, double tmin, double tmax, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int useBandWidthsForTrackEstimation, double numberOfSigmas, double power, double minF1, double maxF1, double minF2, double maxF2, double minF3);
  173. autoDataModeler FormantModeler_extractDataModeler (FormantModeler me, integer iformant);
  174. autoPitchModeler Pitch_to_PitchModeler (Pitch me, double tmin, double tmax, integer numberOfParameters);
  175. void PitchModeler_draw (PitchModeler me, Graphics g, double tmin, double tmax, double fmin, double fmax, integer numberOfParameters, bool garnish);
  176. autoDataModeler Table_to_DataModeler (Table me, double xmin, double xmax,
  177. integer xcolumn, integer ycolumn, integer scolumn, integer numberOfParameters, int type);
  178. autoFormant Sound_to_Formant_interval (Sound me, double startTime, double endTime,
  179. double windowLength, double timeStep, double minFreq, double maxFreq, integer numberOfFrequencySteps,
  180. double preemphasisFrequency, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int weighData,
  181. double numberOfSigmas, double power, bool useConstraints, double minF1, double maxF1, double minF2, double maxF2, double minF3,
  182. double *out_optimalCeiling
  183. );
  184. autoFormant Sound_to_Formant_interval_robust (Sound me, double startTime, double endTime,
  185. double windowLength, double timeStep, double minFreq, double maxFreq, integer numberOfFrequencySteps,
  186. double preemphasisFrequency, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int weighData,
  187. double numberOfSigmas, double power, bool useConstraints, double minF1, double maxF1, double minF2, double maxF2, double minF3,
  188. double *out_optimalCeiling
  189. );
  190. double Sound_getOptimalFormantCeiling (Sound me, double startTime, double endTime,
  191. double windowLength, double timeStep, double minFreq, double maxFreq, integer numberOfFrequencySteps,
  192. double preemphasisFrequency, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int weighData,
  193. double numberOfSigmas, double power
  194. );
  195. autoOptimalCeilingTier Sound_to_OptimalCeilingTier (Sound me,
  196. double windowLength, double timeStep, double minCeiling, double maxCeiling, integer numberOfFrequencySteps,
  197. double preemphasisFrequency, double smoothingWindow, integer numberOfFormantTracks, integer numberOfParametersPerTrack, int weighData,
  198. double numberOfSigmas, double power
  199. );
  200. #endif /* _DataModeler_h_ */