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