bayes_functions.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /******************************************************************************
  2. * @file bayes_functions.h
  3. * @brief Public header file for NMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: RISC-V Cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. * Copyright (c) 2019 Nuclei Limited. 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. #ifndef BAYES_FUNCTIONS_H_
  27. #define BAYES_FUNCTIONS_H_
  28. #include "riscv_math_types.h"
  29. #include "riscv_math_memory.h"
  30. #include "dsp/none.h"
  31. #include "dsp/utils.h"
  32. #include "dsp/statistics_functions.h"
  33. /**
  34. * @defgroup groupBayes Bayesian estimators
  35. *
  36. * Implement the naive gaussian Bayes estimator.
  37. * The training must be done from scikit-learn.
  38. *
  39. * The parameters can be easily
  40. * generated from the scikit-learn object. Some examples are given in
  41. * DSP/Testing/PatternGeneration/Bayes.py
  42. */
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif
  47. /**
  48. * @brief Instance structure for Naive Gaussian Bayesian estimator.
  49. */
  50. typedef struct
  51. {
  52. uint32_t vectorDimension; /**< Dimension of vector space */
  53. uint32_t numberOfClasses; /**< Number of different classes */
  54. const float32_t *theta; /**< Mean values for the Gaussians */
  55. const float32_t *sigma; /**< Variances for the Gaussians */
  56. const float32_t *classPriors; /**< Class prior probabilities */
  57. float32_t epsilon; /**< Additive value to variances */
  58. } riscv_gaussian_naive_bayes_instance_f32;
  59. /**
  60. * @brief Naive Gaussian Bayesian Estimator
  61. *
  62. * @param[in] S points to a naive bayes instance structure
  63. * @param[in] in points to the elements of the input vector.
  64. * @param[out] *pOutputProbabilities points to a buffer of length numberOfClasses containing estimated probabilities
  65. * @param[out] *pBufferB points to a temporary buffer of length numberOfClasses
  66. * @return The predicted class
  67. */
  68. uint32_t riscv_gaussian_naive_bayes_predict_f32(const riscv_gaussian_naive_bayes_instance_f32 *S,
  69. const float32_t * in,
  70. float32_t *pOutputProbabilities,
  71. float32_t *pBufferB);
  72. #ifdef __cplusplus
  73. }
  74. #endif
  75. #endif /* ifndef _BAYES_FUNCTIONS_H_ */