| 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 |
|
|---|
| 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 Euclidean 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 |
|
|---|
| 81 | float64_t arm_euclidean_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | * @brief Bray-Curtis distance between two vectors
|
|---|
| 85 | * @param[in] pA First vector
|
|---|
| 86 | * @param[in] pB Second vector
|
|---|
| 87 | * @param[in] blockSize vector length
|
|---|
| 88 | * @return distance
|
|---|
| 89 | *
|
|---|
| 90 | */
|
|---|
| 91 | float32_t arm_braycurtis_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | * @brief Canberra distance between two vectors
|
|---|
| 95 | *
|
|---|
| 96 | * This function may divide by zero when samples pA[i] and pB[i] are both zero.
|
|---|
| 97 | * The result of the computation will be correct. So the division per zero may be
|
|---|
| 98 | * ignored.
|
|---|
| 99 | *
|
|---|
| 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_canberra_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | /**
|
|---|
| 110 | * @brief Chebyshev 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_chebyshev_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 121 | * @brief Chebyshev distance between two vectors
|
|---|
| 122 | * @param[in] pA First vector
|
|---|
| 123 | * @param[in] pB Second vector
|
|---|
| 124 | * @param[in] blockSize vector length
|
|---|
| 125 | * @return distance
|
|---|
| 126 | *
|
|---|
| 127 | */
|
|---|
| 128 | float64_t arm_chebyshev_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | /**
|
|---|
| 132 | * @brief Cityblock (Manhattan) distance between two vectors
|
|---|
| 133 | * @param[in] pA First vector
|
|---|
| 134 | * @param[in] pB Second vector
|
|---|
| 135 | * @param[in] blockSize vector length
|
|---|
| 136 | * @return distance
|
|---|
| 137 | *
|
|---|
| 138 | */
|
|---|
| 139 | float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
|
|---|
| 140 |
|
|---|
| 141 | /**
|
|---|
| 142 | * @brief Cityblock (Manhattan) distance between two vectors
|
|---|
| 143 | * @param[in] pA First vector
|
|---|
| 144 | * @param[in] pB Second vector
|
|---|
| 145 | * @param[in] blockSize vector length
|
|---|
| 146 | * @return distance
|
|---|
| 147 | *
|
|---|
| 148 | */
|
|---|
| 149 | float64_t arm_cityblock_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
|
|---|
| 150 |
|
|---|
| 151 | /**
|
|---|
| 152 | * @brief Correlation distance between two vectors
|
|---|
| 153 | *
|
|---|
| 154 | * The input vectors are modified in place !
|
|---|
| 155 | *
|
|---|
| 156 | * @param[in] pA First vector
|
|---|
| 157 | * @param[in] pB Second vector
|
|---|
| 158 | * @param[in] blockSize vector length
|
|---|
| 159 | * @return distance
|
|---|
| 160 | *
|
|---|
| 161 | */
|
|---|
| 162 | float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize);
|
|---|
| 163 |
|
|---|
| 164 | /**
|
|---|
| 165 | * @brief Cosine distance between two vectors
|
|---|
| 166 | *
|
|---|
| 167 | * @param[in] pA First vector
|
|---|
| 168 | * @param[in] pB Second vector
|
|---|
| 169 | * @param[in] blockSize vector length
|
|---|
| 170 | * @return distance
|
|---|
| 171 | *
|
|---|
| 172 | */
|
|---|
| 173 |
|
|---|
| 174 | float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
|
|---|
| 175 |
|
|---|
| 176 | /**
|
|---|
| 177 | * @brief Cosine distance between two vectors
|
|---|
| 178 | *
|
|---|
| 179 | * @param[in] pA First vector
|
|---|
| 180 | * @param[in] pB Second vector
|
|---|
| 181 | * @param[in] blockSize vector length
|
|---|
| 182 | * @return distance
|
|---|
| 183 | *
|
|---|
| 184 | */
|
|---|
| 185 |
|
|---|
| 186 | float64_t arm_cosine_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize);
|
|---|
| 187 |
|
|---|
| 188 | /**
|
|---|
| 189 | * @brief Jensen-Shannon distance between two vectors
|
|---|
| 190 | *
|
|---|
| 191 | * This function is assuming that elements of second vector are > 0
|
|---|
| 192 | * and 0 only when the corresponding element of first vector is 0.
|
|---|
| 193 | * Otherwise the result of the computation does not make sense
|
|---|
| 194 | * and for speed reasons, the cases returning NaN or Infinity are not
|
|---|
| 195 | * managed.
|
|---|
| 196 | *
|
|---|
| 197 | * When the function is computing x log (x / y) with x 0 and y 0,
|
|---|
| 198 | * it will compute the right value (0) but a division per zero will occur
|
|---|
| 199 | * and shoudl be ignored in client code.
|
|---|
| 200 | *
|
|---|
| 201 | * @param[in] pA First vector
|
|---|
| 202 | * @param[in] pB Second vector
|
|---|
| 203 | * @param[in] blockSize vector length
|
|---|
| 204 | * @return distance
|
|---|
| 205 | *
|
|---|
| 206 | */
|
|---|
| 207 |
|
|---|
| 208 | float32_t arm_jensenshannon_distance_f32(const float32_t *pA,const float32_t *pB,uint32_t blockSize);
|
|---|
| 209 |
|
|---|
| 210 | /**
|
|---|
| 211 | * @brief Minkowski distance between two vectors
|
|---|
| 212 | *
|
|---|
| 213 | * @param[in] pA First vector
|
|---|
| 214 | * @param[in] pB Second vector
|
|---|
| 215 | * @param[in] n Norm order (>= 2)
|
|---|
| 216 | * @param[in] blockSize vector length
|
|---|
| 217 | * @return distance
|
|---|
| 218 | *
|
|---|
| 219 | */
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | float32_t arm_minkowski_distance_f32(const float32_t *pA,const float32_t *pB, int32_t order, uint32_t blockSize);
|
|---|
| 224 |
|
|---|
| 225 | /**
|
|---|
| 226 | * @brief Dice distance between two vectors
|
|---|
| 227 | *
|
|---|
| 228 | * @param[in] pA First vector of packed booleans
|
|---|
| 229 | * @param[in] pB Second vector of packed booleans
|
|---|
| 230 | * @param[in] order Distance order
|
|---|
| 231 | * @param[in] blockSize Number of samples
|
|---|
| 232 | * @return distance
|
|---|
| 233 | *
|
|---|
| 234 | */
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 238 |
|
|---|
| 239 | /**
|
|---|
| 240 | * @brief Hamming distance between two vectors
|
|---|
| 241 | *
|
|---|
| 242 | * @param[in] pA First vector of packed booleans
|
|---|
| 243 | * @param[in] pB Second vector of packed booleans
|
|---|
| 244 | * @param[in] numberOfBools Number of booleans
|
|---|
| 245 | * @return distance
|
|---|
| 246 | *
|
|---|
| 247 | */
|
|---|
| 248 |
|
|---|
| 249 | float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * @brief Jaccard distance between two vectors
|
|---|
| 253 | *
|
|---|
| 254 | * @param[in] pA First vector of packed booleans
|
|---|
| 255 | * @param[in] pB Second vector of packed booleans
|
|---|
| 256 | * @param[in] numberOfBools Number of booleans
|
|---|
| 257 | * @return distance
|
|---|
| 258 | *
|
|---|
| 259 | */
|
|---|
| 260 |
|
|---|
| 261 | float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 262 |
|
|---|
| 263 | /**
|
|---|
| 264 | * @brief Kulsinski distance between two vectors
|
|---|
| 265 | *
|
|---|
| 266 | * @param[in] pA First vector of packed booleans
|
|---|
| 267 | * @param[in] pB Second vector of packed booleans
|
|---|
| 268 | * @param[in] numberOfBools Number of booleans
|
|---|
| 269 | * @return distance
|
|---|
| 270 | *
|
|---|
| 271 | */
|
|---|
| 272 |
|
|---|
| 273 | float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 274 |
|
|---|
| 275 | /**
|
|---|
| 276 | * @brief Roger Stanimoto distance between two vectors
|
|---|
| 277 | *
|
|---|
| 278 | * @param[in] pA First vector of packed booleans
|
|---|
| 279 | * @param[in] pB Second vector of packed booleans
|
|---|
| 280 | * @param[in] numberOfBools Number of booleans
|
|---|
| 281 | * @return distance
|
|---|
| 282 | *
|
|---|
| 283 | */
|
|---|
| 284 |
|
|---|
| 285 | float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 286 |
|
|---|
| 287 | /**
|
|---|
| 288 | * @brief Russell-Rao distance between two vectors
|
|---|
| 289 | *
|
|---|
| 290 | * @param[in] pA First vector of packed booleans
|
|---|
| 291 | * @param[in] pB Second vector of packed booleans
|
|---|
| 292 | * @param[in] numberOfBools Number of booleans
|
|---|
| 293 | * @return distance
|
|---|
| 294 | *
|
|---|
| 295 | */
|
|---|
| 296 |
|
|---|
| 297 | float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 298 |
|
|---|
| 299 | /**
|
|---|
| 300 | * @brief Sokal-Michener distance between two vectors
|
|---|
| 301 | *
|
|---|
| 302 | * @param[in] pA First vector of packed booleans
|
|---|
| 303 | * @param[in] pB Second vector of packed booleans
|
|---|
| 304 | * @param[in] numberOfBools Number of booleans
|
|---|
| 305 | * @return distance
|
|---|
| 306 | *
|
|---|
| 307 | */
|
|---|
| 308 |
|
|---|
| 309 | float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 310 |
|
|---|
| 311 | /**
|
|---|
| 312 | * @brief Sokal-Sneath distance between two vectors
|
|---|
| 313 | *
|
|---|
| 314 | * @param[in] pA First vector of packed booleans
|
|---|
| 315 | * @param[in] pB Second vector of packed booleans
|
|---|
| 316 | * @param[in] numberOfBools Number of booleans
|
|---|
| 317 | * @return distance
|
|---|
| 318 | *
|
|---|
| 319 | */
|
|---|
| 320 |
|
|---|
| 321 | float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 322 |
|
|---|
| 323 | /**
|
|---|
| 324 | * @brief Yule distance between two vectors
|
|---|
| 325 | *
|
|---|
| 326 | * @param[in] pA First vector of packed booleans
|
|---|
| 327 | * @param[in] pB Second vector of packed booleans
|
|---|
| 328 | * @param[in] numberOfBools Number of booleans
|
|---|
| 329 | * @return distance
|
|---|
| 330 | *
|
|---|
| 331 | */
|
|---|
| 332 |
|
|---|
| 333 | float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 | #ifdef __cplusplus
|
|---|
| 338 | }
|
|---|
| 339 | #endif
|
|---|
| 340 |
|
|---|
| 341 | #endif /* ifndef _DISTANCE_FUNCTIONS_H_ */
|
|---|