/ Drivers / CMSIS / DSP / Source / StatisticsFunctions / arm_entropy_f64.c
arm_entropy_f64.c
 1  /* ----------------------------------------------------------------------
 2   * Project:      CMSIS DSP Library
 3   * Title:        arm_logsumexp_f64.c
 4   * Description:  LogSumExp
 5   *
 6   * $Date:        23 April 2021
 7   * $Revision:    V1.9.0
 8   *
 9   * Target Processor: Cortex-M and Cortex-A cores
10   * -------------------------------------------------------------------- */
11  /*
12   * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13   *
14   * SPDX-License-Identifier: Apache-2.0
15   *
16   * Licensed under the Apache License, Version 2.0 (the License); you may
17   * not use this file except in compliance with the License.
18   * You may obtain a copy of the License at
19   *
20   * www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   * See the License for the specific language governing permissions and
26   * limitations under the License.
27   */
28  
29  #include "dsp/statistics_functions.h"
30  #include <limits.h>
31  #include <math.h>
32  
33  /**
34   * @addtogroup Entropy
35   * @{
36   */
37  
38  /**
39   * @brief Entropy
40   *
41   * @param[in]  pSrcA        Array of input values.
42   * @param[in]  blockSize    Number of samples in the input array.
43   * @return     Entropy      -Sum(p ln p)
44   *
45   */
46  
47  float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize)
48  {
49      const float64_t *pIn;
50      uint32_t blkCnt;
51      float64_t accum, p;
52   
53      pIn = pSrcA;
54      blkCnt = blockSize;
55  
56      accum = 0.0f;
57  
58      while(blkCnt > 0)
59      {
60          p = *pIn++;
61  
62          accum += p * log(p);
63         
64          blkCnt--;
65      
66      }
67  
68      return(-accum);
69  }
70  
71  /**
72   * @} end of Entropy group
73   */