statistics_functions.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /******************************************************************************
  2. * @file statistics_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.9.0
  5. * @date 20. July 2020
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef _STATISTICS_FUNCTIONS_H_
  25. #define _STATISTICS_FUNCTIONS_H_
  26. #include "arm_math_types.h"
  27. #include "arm_math_memory.h"
  28. #include "dsp/none.h"
  29. #include "dsp/utils.h"
  30. #include "dsp/basic_math_functions.h"
  31. #include "dsp/fast_math_functions.h"
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. /**
  37. * @defgroup groupStats Statistics Functions
  38. */
  39. /**
  40. * @brief Computation of the LogSumExp
  41. *
  42. * In probabilistic computations, the dynamic of the probability values can be very
  43. * wide because they come from gaussian functions.
  44. * To avoid underflow and overflow issues, the values are represented by their log.
  45. * In this representation, multiplying the original exp values is easy : their logs are added.
  46. * But adding the original exp values is requiring some special handling and it is the
  47. * goal of the LogSumExp function.
  48. *
  49. * If the values are x1...xn, the function is computing:
  50. *
  51. * ln(exp(x1) + ... + exp(xn)) and the computation is done in such a way that
  52. * rounding issues are minimised.
  53. *
  54. * The max xm of the values is extracted and the function is computing:
  55. * xm + ln(exp(x1 - xm) + ... + exp(xn - xm))
  56. *
  57. * @param[in] *in Pointer to an array of input values.
  58. * @param[in] blockSize Number of samples in the input array.
  59. * @return LogSumExp
  60. *
  61. */
  62. float32_t arm_logsumexp_f32(const float32_t *in, uint32_t blockSize);
  63. /**
  64. * @brief Dot product with log arithmetic
  65. *
  66. * Vectors are containing the log of the samples
  67. *
  68. * @param[in] pSrcA points to the first input vector
  69. * @param[in] pSrcB points to the second input vector
  70. * @param[in] blockSize number of samples in each vector
  71. * @param[in] pTmpBuffer temporary buffer of length blockSize
  72. * @return The log of the dot product .
  73. *
  74. */
  75. float32_t arm_logsumexp_dot_prod_f32(const float32_t * pSrcA,
  76. const float32_t * pSrcB,
  77. uint32_t blockSize,
  78. float32_t *pTmpBuffer);
  79. /**
  80. * @brief Entropy
  81. *
  82. * @param[in] pSrcA Array of input values.
  83. * @param[in] blockSize Number of samples in the input array.
  84. * @return Entropy -Sum(p ln p)
  85. *
  86. */
  87. float32_t arm_entropy_f32(const float32_t * pSrcA,uint32_t blockSize);
  88. /**
  89. * @brief Entropy
  90. *
  91. * @param[in] pSrcA Array of input values.
  92. * @param[in] blockSize Number of samples in the input array.
  93. * @return Entropy -Sum(p ln p)
  94. *
  95. */
  96. float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize);
  97. /**
  98. * @brief Kullback-Leibler
  99. *
  100. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  101. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  102. * @param[in] blockSize Number of samples in the input array.
  103. * @return Kullback-Leibler Divergence D(A || B)
  104. *
  105. */
  106. float32_t arm_kullback_leibler_f32(const float32_t * pSrcA
  107. ,const float32_t * pSrcB
  108. ,uint32_t blockSize);
  109. /**
  110. * @brief Kullback-Leibler
  111. *
  112. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  113. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  114. * @param[in] blockSize Number of samples in the input array.
  115. * @return Kullback-Leibler Divergence D(A || B)
  116. *
  117. */
  118. float64_t arm_kullback_leibler_f64(const float64_t * pSrcA,
  119. const float64_t * pSrcB,
  120. uint32_t blockSize);
  121. /**
  122. * @brief Sum of the squares of the elements of a Q31 vector.
  123. * @param[in] pSrc is input pointer
  124. * @param[in] blockSize is the number of samples to process
  125. * @param[out] pResult is output value.
  126. */
  127. void arm_power_q31(
  128. const q31_t * pSrc,
  129. uint32_t blockSize,
  130. q63_t * pResult);
  131. /**
  132. * @brief Sum of the squares of the elements of a floating-point vector.
  133. * @param[in] pSrc is input pointer
  134. * @param[in] blockSize is the number of samples to process
  135. * @param[out] pResult is output value.
  136. */
  137. void arm_power_f32(
  138. const float32_t * pSrc,
  139. uint32_t blockSize,
  140. float32_t * pResult);
  141. /**
  142. * @brief Sum of the squares of the elements of a Q15 vector.
  143. * @param[in] pSrc is input pointer
  144. * @param[in] blockSize is the number of samples to process
  145. * @param[out] pResult is output value.
  146. */
  147. void arm_power_q15(
  148. const q15_t * pSrc,
  149. uint32_t blockSize,
  150. q63_t * pResult);
  151. /**
  152. * @brief Sum of the squares of the elements of a Q7 vector.
  153. * @param[in] pSrc is input pointer
  154. * @param[in] blockSize is the number of samples to process
  155. * @param[out] pResult is output value.
  156. */
  157. void arm_power_q7(
  158. const q7_t * pSrc,
  159. uint32_t blockSize,
  160. q31_t * pResult);
  161. /**
  162. * @brief Mean value of a Q7 vector.
  163. * @param[in] pSrc is input pointer
  164. * @param[in] blockSize is the number of samples to process
  165. * @param[out] pResult is output value.
  166. */
  167. void arm_mean_q7(
  168. const q7_t * pSrc,
  169. uint32_t blockSize,
  170. q7_t * pResult);
  171. /**
  172. * @brief Mean value of a Q15 vector.
  173. * @param[in] pSrc is input pointer
  174. * @param[in] blockSize is the number of samples to process
  175. * @param[out] pResult is output value.
  176. */
  177. void arm_mean_q15(
  178. const q15_t * pSrc,
  179. uint32_t blockSize,
  180. q15_t * pResult);
  181. /**
  182. * @brief Mean value of a Q31 vector.
  183. * @param[in] pSrc is input pointer
  184. * @param[in] blockSize is the number of samples to process
  185. * @param[out] pResult is output value.
  186. */
  187. void arm_mean_q31(
  188. const q31_t * pSrc,
  189. uint32_t blockSize,
  190. q31_t * pResult);
  191. /**
  192. * @brief Mean value of a floating-point vector.
  193. * @param[in] pSrc is input pointer
  194. * @param[in] blockSize is the number of samples to process
  195. * @param[out] pResult is output value.
  196. */
  197. void arm_mean_f32(
  198. const float32_t * pSrc,
  199. uint32_t blockSize,
  200. float32_t * pResult);
  201. /**
  202. * @brief Variance of the elements of a floating-point vector.
  203. * @param[in] pSrc is input pointer
  204. * @param[in] blockSize is the number of samples to process
  205. * @param[out] pResult is output value.
  206. */
  207. void arm_var_f32(
  208. const float32_t * pSrc,
  209. uint32_t blockSize,
  210. float32_t * pResult);
  211. /**
  212. * @brief Variance of the elements of a Q31 vector.
  213. * @param[in] pSrc is input pointer
  214. * @param[in] blockSize is the number of samples to process
  215. * @param[out] pResult is output value.
  216. */
  217. void arm_var_q31(
  218. const q31_t * pSrc,
  219. uint32_t blockSize,
  220. q31_t * pResult);
  221. /**
  222. * @brief Variance of the elements of a Q15 vector.
  223. * @param[in] pSrc is input pointer
  224. * @param[in] blockSize is the number of samples to process
  225. * @param[out] pResult is output value.
  226. */
  227. void arm_var_q15(
  228. const q15_t * pSrc,
  229. uint32_t blockSize,
  230. q15_t * pResult);
  231. /**
  232. * @brief Root Mean Square of the elements of a floating-point vector.
  233. * @param[in] pSrc is input pointer
  234. * @param[in] blockSize is the number of samples to process
  235. * @param[out] pResult is output value.
  236. */
  237. void arm_rms_f32(
  238. const float32_t * pSrc,
  239. uint32_t blockSize,
  240. float32_t * pResult);
  241. /**
  242. * @brief Root Mean Square of the elements of a Q31 vector.
  243. * @param[in] pSrc is input pointer
  244. * @param[in] blockSize is the number of samples to process
  245. * @param[out] pResult is output value.
  246. */
  247. void arm_rms_q31(
  248. const q31_t * pSrc,
  249. uint32_t blockSize,
  250. q31_t * pResult);
  251. /**
  252. * @brief Root Mean Square of the elements of a Q15 vector.
  253. * @param[in] pSrc is input pointer
  254. * @param[in] blockSize is the number of samples to process
  255. * @param[out] pResult is output value.
  256. */
  257. void arm_rms_q15(
  258. const q15_t * pSrc,
  259. uint32_t blockSize,
  260. q15_t * pResult);
  261. /**
  262. * @brief Standard deviation of the elements of a floating-point vector.
  263. * @param[in] pSrc is input pointer
  264. * @param[in] blockSize is the number of samples to process
  265. * @param[out] pResult is output value.
  266. */
  267. void arm_std_f32(
  268. const float32_t * pSrc,
  269. uint32_t blockSize,
  270. float32_t * pResult);
  271. /**
  272. * @brief Standard deviation of the elements of a Q31 vector.
  273. * @param[in] pSrc is input pointer
  274. * @param[in] blockSize is the number of samples to process
  275. * @param[out] pResult is output value.
  276. */
  277. void arm_std_q31(
  278. const q31_t * pSrc,
  279. uint32_t blockSize,
  280. q31_t * pResult);
  281. /**
  282. * @brief Standard deviation of the elements of a Q15 vector.
  283. * @param[in] pSrc is input pointer
  284. * @param[in] blockSize is the number of samples to process
  285. * @param[out] pResult is output value.
  286. */
  287. void arm_std_q15(
  288. const q15_t * pSrc,
  289. uint32_t blockSize,
  290. q15_t * pResult);
  291. /**
  292. * @brief Minimum value of a Q7 vector.
  293. * @param[in] pSrc is input pointer
  294. * @param[in] blockSize is the number of samples to process
  295. * @param[out] result is output pointer
  296. * @param[in] index is the array index of the minimum value in the input buffer.
  297. */
  298. void arm_min_q7(
  299. const q7_t * pSrc,
  300. uint32_t blockSize,
  301. q7_t * result,
  302. uint32_t * index);
  303. /**
  304. * @brief Minimum value of a Q15 vector.
  305. * @param[in] pSrc is input pointer
  306. * @param[in] blockSize is the number of samples to process
  307. * @param[out] pResult is output pointer
  308. * @param[in] pIndex is the array index of the minimum value in the input buffer.
  309. */
  310. void arm_min_q15(
  311. const q15_t * pSrc,
  312. uint32_t blockSize,
  313. q15_t * pResult,
  314. uint32_t * pIndex);
  315. /**
  316. * @brief Minimum value of a Q31 vector.
  317. * @param[in] pSrc is input pointer
  318. * @param[in] blockSize is the number of samples to process
  319. * @param[out] pResult is output pointer
  320. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  321. */
  322. void arm_min_q31(
  323. const q31_t * pSrc,
  324. uint32_t blockSize,
  325. q31_t * pResult,
  326. uint32_t * pIndex);
  327. /**
  328. * @brief Minimum value of a floating-point vector.
  329. * @param[in] pSrc is input pointer
  330. * @param[in] blockSize is the number of samples to process
  331. * @param[out] pResult is output pointer
  332. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  333. */
  334. void arm_min_f32(
  335. const float32_t * pSrc,
  336. uint32_t blockSize,
  337. float32_t * pResult,
  338. uint32_t * pIndex);
  339. /**
  340. * @brief Maximum value of a Q7 vector.
  341. * @param[in] pSrc points to the input buffer
  342. * @param[in] blockSize length of the input vector
  343. * @param[out] pResult maximum value returned here
  344. * @param[out] pIndex index of maximum value returned here
  345. */
  346. void arm_max_q7(
  347. const q7_t * pSrc,
  348. uint32_t blockSize,
  349. q7_t * pResult,
  350. uint32_t * pIndex);
  351. /**
  352. * @brief Maximum value of a Q15 vector.
  353. * @param[in] pSrc points to the input buffer
  354. * @param[in] blockSize length of the input vector
  355. * @param[out] pResult maximum value returned here
  356. * @param[out] pIndex index of maximum value returned here
  357. */
  358. void arm_max_q15(
  359. const q15_t * pSrc,
  360. uint32_t blockSize,
  361. q15_t * pResult,
  362. uint32_t * pIndex);
  363. /**
  364. * @brief Maximum value of a Q31 vector.
  365. * @param[in] pSrc points to the input buffer
  366. * @param[in] blockSize length of the input vector
  367. * @param[out] pResult maximum value returned here
  368. * @param[out] pIndex index of maximum value returned here
  369. */
  370. void arm_max_q31(
  371. const q31_t * pSrc,
  372. uint32_t blockSize,
  373. q31_t * pResult,
  374. uint32_t * pIndex);
  375. /**
  376. * @brief Maximum value of a floating-point vector.
  377. * @param[in] pSrc points to the input buffer
  378. * @param[in] blockSize length of the input vector
  379. * @param[out] pResult maximum value returned here
  380. * @param[out] pIndex index of maximum value returned here
  381. */
  382. void arm_max_f32(
  383. const float32_t * pSrc,
  384. uint32_t blockSize,
  385. float32_t * pResult,
  386. uint32_t * pIndex);
  387. /**
  388. @brief Maximum value of a floating-point vector.
  389. @param[in] pSrc points to the input vector
  390. @param[in] blockSize number of samples in input vector
  391. @param[out] pResult maximum value returned here
  392. @return none
  393. */
  394. void arm_max_no_idx_f32(
  395. const float32_t *pSrc,
  396. uint32_t blockSize,
  397. float32_t *pResult);
  398. #ifdef __cplusplus
  399. }
  400. #endif
  401. #endif /* ifndef _STATISTICS_FUNCTIONS_H_ */