arm_entropy_f64.c 1.7 KB

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