distance_functions.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /******************************************************************************
  2. * @file distance_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 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 Euclidean 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. float64_t arm_euclidean_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
  67. /**
  68. * @brief Bray-Curtis distance between two vectors
  69. * @param[in] pA First vector
  70. * @param[in] pB Second vector
  71. * @param[in] blockSize vector length
  72. * @return distance
  73. *
  74. */
  75. float32_t arm_braycurtis_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  76. /**
  77. * @brief Canberra distance between two vectors
  78. *
  79. * This function may divide by zero when samples pA[i] and pB[i] are both zero.
  80. * The result of the computation will be correct. So the division per zero may be
  81. * ignored.
  82. *
  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_canberra_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  90. /**
  91. * @brief Chebyshev 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_chebyshev_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  99. /**
  100. * @brief Chebyshev distance between two vectors
  101. * @param[in] pA First vector
  102. * @param[in] pB Second vector
  103. * @param[in] blockSize vector length
  104. * @return distance
  105. *
  106. */
  107. float64_t arm_chebyshev_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
  108. /**
  109. * @brief Cityblock (Manhattan) distance between two vectors
  110. * @param[in] pA First vector
  111. * @param[in] pB Second vector
  112. * @param[in] blockSize vector length
  113. * @return distance
  114. *
  115. */
  116. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  117. /**
  118. * @brief Cityblock (Manhattan) distance between two vectors
  119. * @param[in] pA First vector
  120. * @param[in] pB Second vector
  121. * @param[in] blockSize vector length
  122. * @return distance
  123. *
  124. */
  125. float64_t arm_cityblock_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
  126. /**
  127. * @brief Correlation distance between two vectors
  128. *
  129. * The input vectors are modified in place !
  130. *
  131. * @param[in] pA First vector
  132. * @param[in] pB Second vector
  133. * @param[in] blockSize vector length
  134. * @return distance
  135. *
  136. */
  137. float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize);
  138. /**
  139. * @brief Cosine distance between two vectors
  140. *
  141. * @param[in] pA First vector
  142. * @param[in] pB Second vector
  143. * @param[in] blockSize vector length
  144. * @return distance
  145. *
  146. */
  147. float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  148. /**
  149. * @brief Cosine distance between two vectors
  150. *
  151. * @param[in] pA First vector
  152. * @param[in] pB Second vector
  153. * @param[in] blockSize vector length
  154. * @return distance
  155. *
  156. */
  157. float64_t arm_cosine_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
  158. /**
  159. * @brief Jensen-Shannon distance between two vectors
  160. *
  161. * This function is assuming that elements of second vector are > 0
  162. * and 0 only when the corresponding element of first vector is 0.
  163. * Otherwise the result of the computation does not make sense
  164. * and for speed reasons, the cases returning NaN or Infinity are not
  165. * managed.
  166. *
  167. * When the function is computing x log (x / y) with x 0 and y 0,
  168. * it will compute the right value (0) but a division per zero will occur
  169. * and shoudl be ignored in client code.
  170. *
  171. * @param[in] pA First vector
  172. * @param[in] pB Second vector
  173. * @param[in] blockSize vector length
  174. * @return distance
  175. *
  176. */
  177. float32_t arm_jensenshannon_distance_f32(const float32_t *pA,const float32_t *pB,uint32_t blockSize);
  178. /**
  179. * @brief Minkowski distance between two vectors
  180. *
  181. * @param[in] pA First vector
  182. * @param[in] pB Second vector
  183. * @param[in] n Norm order (>= 2)
  184. * @param[in] blockSize vector length
  185. * @return distance
  186. *
  187. */
  188. float32_t arm_minkowski_distance_f32(const float32_t *pA,const float32_t *pB, int32_t order, uint32_t blockSize);
  189. /**
  190. * @brief Dice distance between two vectors
  191. *
  192. * @param[in] pA First vector of packed booleans
  193. * @param[in] pB Second vector of packed booleans
  194. * @param[in] order Distance order
  195. * @param[in] blockSize Number of samples
  196. * @return distance
  197. *
  198. */
  199. float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  200. /**
  201. * @brief Hamming distance between two vectors
  202. *
  203. * @param[in] pA First vector of packed booleans
  204. * @param[in] pB Second vector of packed booleans
  205. * @param[in] numberOfBools Number of booleans
  206. * @return distance
  207. *
  208. */
  209. float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  210. /**
  211. * @brief Jaccard distance between two vectors
  212. *
  213. * @param[in] pA First vector of packed booleans
  214. * @param[in] pB Second vector of packed booleans
  215. * @param[in] numberOfBools Number of booleans
  216. * @return distance
  217. *
  218. */
  219. float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  220. /**
  221. * @brief Kulsinski distance between two vectors
  222. *
  223. * @param[in] pA First vector of packed booleans
  224. * @param[in] pB Second vector of packed booleans
  225. * @param[in] numberOfBools Number of booleans
  226. * @return distance
  227. *
  228. */
  229. float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  230. /**
  231. * @brief Roger Stanimoto distance between two vectors
  232. *
  233. * @param[in] pA First vector of packed booleans
  234. * @param[in] pB Second vector of packed booleans
  235. * @param[in] numberOfBools Number of booleans
  236. * @return distance
  237. *
  238. */
  239. float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  240. /**
  241. * @brief Russell-Rao distance between two vectors
  242. *
  243. * @param[in] pA First vector of packed booleans
  244. * @param[in] pB Second vector of packed booleans
  245. * @param[in] numberOfBools Number of booleans
  246. * @return distance
  247. *
  248. */
  249. float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  250. /**
  251. * @brief Sokal-Michener distance between two vectors
  252. *
  253. * @param[in] pA First vector of packed booleans
  254. * @param[in] pB Second vector of packed booleans
  255. * @param[in] numberOfBools Number of booleans
  256. * @return distance
  257. *
  258. */
  259. float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  260. /**
  261. * @brief Sokal-Sneath distance between two vectors
  262. *
  263. * @param[in] pA First vector of packed booleans
  264. * @param[in] pB Second vector of packed booleans
  265. * @param[in] numberOfBools Number of booleans
  266. * @return distance
  267. *
  268. */
  269. float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  270. /**
  271. * @brief Yule distance between two vectors
  272. *
  273. * @param[in] pA First vector of packed booleans
  274. * @param[in] pB Second vector of packed booleans
  275. * @param[in] numberOfBools Number of booleans
  276. * @return distance
  277. *
  278. */
  279. float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  280. #ifdef __cplusplus
  281. }
  282. #endif
  283. #endif /* ifndef _DISTANCE_FUNCTIONS_H_ */