arm_entropy_f64.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "dsp/statistics_functions.h"
  29. #include <limits.h>
  30. #include <math.h>
  31. /**
  32. * @addtogroup Entropy
  33. * @{
  34. */
  35. /**
  36. * @brief Entropy
  37. *
  38. * @param[in] pSrcA Array of input values.
  39. * @param[in] blockSize Number of samples in the input array.
  40. * @return Entropy -Sum(p ln p)
  41. *
  42. */
  43. float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize)
  44. {
  45. const float64_t *pIn;
  46. uint32_t blkCnt;
  47. float64_t accum, p;
  48. pIn = pSrcA;
  49. blkCnt = blockSize;
  50. accum = 0.0;
  51. while(blkCnt > 0)
  52. {
  53. p = *pIn++;
  54. accum += p * log(p);
  55. blkCnt--;
  56. }
  57. return(-accum);
  58. }
  59. /**
  60. * @} end of Entropy group
  61. */