1
2 /* ----------------------------------------------------------------------
3 * Project: CMSIS DSP Library
4 * Title: arm_rogerstanimoto_distance.c
5 * Description: Roger Stanimoto distance between two vectors
6 *
7 *
8 * Target Processor: Cortex-M cores
9 * -------------------------------------------------------------------- */
10 /*
11 * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
12 *
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the License); you may
16 * not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
23 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 */
27
28 #include "arm_math.h"
29 #include <limits.h>
30 #include <math.h>
31
32
33
34 extern void arm_boolean_distance_TT_FF_TF_FT(const uint32_t *pA
35 , const uint32_t *pB
36 , uint32_t numberOfBools
37 , uint32_t *cTT
38 , uint32_t *cFF
39 , uint32_t *cTF
40 , uint32_t *cFT
41 );
42
43
44 /**
45 @addtogroup BoolDist
46 @{
47 */
48
49 /**
50 * @brief Roger Stanimoto distance between two vectors
51 *
52 * @param[in] pA First vector of packed booleans
53 * @param[in] pB Second vector of packed booleans
54 * @param[in] numberOfBools Number of booleans
55 * @return distance
56 *
57 */
58
arm_rogerstanimoto_distance(const uint32_t * pA,const uint32_t * pB,uint32_t numberOfBools)59 float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools)
60 {
61 uint32_t ctt=0,cff=0,ctf=0,cft=0,r;
62
63 arm_boolean_distance_TT_FF_TF_FT(pA, pB, numberOfBools, &ctt,&cff, &ctf, &cft);
64
65 r = 2*(ctf + cft);
66
67 return(1.0*r / (r + ctt + cff));
68 }
69
70
71 /**
72 * @} end of BoolDist group
73 */
74