statistics_functions.h 17 KB

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