distance_functions.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /******************************************************************************
  2. * @file distance_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 _DISTANCE_FUNCTIONS_H_
  26. #define _DISTANCE_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/statistics_functions.h"
  32. #include "dsp/basic_math_functions.h"
  33. #include "dsp/fast_math_functions.h"
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #endif
  38. /**
  39. * @defgroup groupDistance Distance functions
  40. *
  41. * Distance functions for use with clustering algorithms.
  42. * There are distance functions for float vectors and boolean vectors.
  43. *
  44. */
  45. /* 6.14 bug */
  46. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) && (__ARMCC_VERSION < 6150001)
  47. __attribute__((weak)) float __powisf2(float a, int b);
  48. #endif
  49. /**
  50. * @brief Euclidean distance between two vectors
  51. * @param[in] pA First vector
  52. * @param[in] pB Second vector
  53. * @param[in] blockSize vector length
  54. * @return distance
  55. *
  56. */
  57. float32_t arm_euclidean_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  58. /**
  59. * @brief Bray-Curtis distance between two vectors
  60. * @param[in] pA First vector
  61. * @param[in] pB Second vector
  62. * @param[in] blockSize vector length
  63. * @return distance
  64. *
  65. */
  66. float32_t arm_braycurtis_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  67. /**
  68. * @brief Canberra distance between two vectors
  69. *
  70. * This function may divide by zero when samples pA[i] and pB[i] are both zero.
  71. * The result of the computation will be correct. So the division per zero may be
  72. * ignored.
  73. *
  74. * @param[in] pA First vector
  75. * @param[in] pB Second vector
  76. * @param[in] blockSize vector length
  77. * @return distance
  78. *
  79. */
  80. float32_t arm_canberra_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  81. /**
  82. * @brief Chebyshev distance between two vectors
  83. * @param[in] pA First vector
  84. * @param[in] pB Second vector
  85. * @param[in] blockSize vector length
  86. * @return distance
  87. *
  88. */
  89. float32_t arm_chebyshev_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  90. /**
  91. * @brief Cityblock (Manhattan) distance between two vectors
  92. * @param[in] pA First vector
  93. * @param[in] pB Second vector
  94. * @param[in] blockSize vector length
  95. * @return distance
  96. *
  97. */
  98. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  99. /**
  100. * @brief Correlation distance between two vectors
  101. *
  102. * The input vectors are modified in place !
  103. *
  104. * @param[in] pA First vector
  105. * @param[in] pB Second vector
  106. * @param[in] blockSize vector length
  107. * @return distance
  108. *
  109. */
  110. float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize);
  111. /**
  112. * @brief Cosine distance between two vectors
  113. *
  114. * @param[in] pA First vector
  115. * @param[in] pB Second vector
  116. * @param[in] blockSize vector length
  117. * @return distance
  118. *
  119. */
  120. float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  121. /**
  122. * @brief Jensen-Shannon distance between two vectors
  123. *
  124. * This function is assuming that elements of second vector are > 0
  125. * and 0 only when the corresponding element of first vector is 0.
  126. * Otherwise the result of the computation does not make sense
  127. * and for speed reasons, the cases returning NaN or Infinity are not
  128. * managed.
  129. *
  130. * When the function is computing x log (x / y) with x 0 and y 0,
  131. * it will compute the right value (0) but a division per zero will occur
  132. * and shoudl be ignored in client code.
  133. *
  134. * @param[in] pA First vector
  135. * @param[in] pB Second vector
  136. * @param[in] blockSize vector length
  137. * @return distance
  138. *
  139. */
  140. float32_t arm_jensenshannon_distance_f32(const float32_t *pA,const float32_t *pB,uint32_t blockSize);
  141. /**
  142. * @brief Minkowski distance between two vectors
  143. *
  144. * @param[in] pA First vector
  145. * @param[in] pB Second vector
  146. * @param[in] n Norm order (>= 2)
  147. * @param[in] blockSize vector length
  148. * @return distance
  149. *
  150. */
  151. float32_t arm_minkowski_distance_f32(const float32_t *pA,const float32_t *pB, int32_t order, uint32_t blockSize);
  152. /**
  153. * @brief Dice distance between two vectors
  154. *
  155. * @param[in] pA First vector of packed booleans
  156. * @param[in] pB Second vector of packed booleans
  157. * @param[in] order Distance order
  158. * @param[in] blockSize Number of samples
  159. * @return distance
  160. *
  161. */
  162. float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  163. /**
  164. * @brief Hamming distance between two vectors
  165. *
  166. * @param[in] pA First vector of packed booleans
  167. * @param[in] pB Second vector of packed booleans
  168. * @param[in] numberOfBools Number of booleans
  169. * @return distance
  170. *
  171. */
  172. float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  173. /**
  174. * @brief Jaccard distance between two vectors
  175. *
  176. * @param[in] pA First vector of packed booleans
  177. * @param[in] pB Second vector of packed booleans
  178. * @param[in] numberOfBools Number of booleans
  179. * @return distance
  180. *
  181. */
  182. float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  183. /**
  184. * @brief Kulsinski distance between two vectors
  185. *
  186. * @param[in] pA First vector of packed booleans
  187. * @param[in] pB Second vector of packed booleans
  188. * @param[in] numberOfBools Number of booleans
  189. * @return distance
  190. *
  191. */
  192. float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  193. /**
  194. * @brief Roger Stanimoto distance between two vectors
  195. *
  196. * @param[in] pA First vector of packed booleans
  197. * @param[in] pB Second vector of packed booleans
  198. * @param[in] numberOfBools Number of booleans
  199. * @return distance
  200. *
  201. */
  202. float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  203. /**
  204. * @brief Russell-Rao distance between two vectors
  205. *
  206. * @param[in] pA First vector of packed booleans
  207. * @param[in] pB Second vector of packed booleans
  208. * @param[in] numberOfBools Number of booleans
  209. * @return distance
  210. *
  211. */
  212. float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  213. /**
  214. * @brief Sokal-Michener distance between two vectors
  215. *
  216. * @param[in] pA First vector of packed booleans
  217. * @param[in] pB Second vector of packed booleans
  218. * @param[in] numberOfBools Number of booleans
  219. * @return distance
  220. *
  221. */
  222. float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  223. /**
  224. * @brief Sokal-Sneath distance between two vectors
  225. *
  226. * @param[in] pA First vector of packed booleans
  227. * @param[in] pB Second vector of packed booleans
  228. * @param[in] numberOfBools Number of booleans
  229. * @return distance
  230. *
  231. */
  232. float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  233. /**
  234. * @brief Yule distance between two vectors
  235. *
  236. * @param[in] pA First vector of packed booleans
  237. * @param[in] pB Second vector of packed booleans
  238. * @param[in] numberOfBools Number of booleans
  239. * @return distance
  240. *
  241. */
  242. float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. #endif /* ifndef _DISTANCE_FUNCTIONS_H_ */