svm_functions_f16.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /******************************************************************************
  2. * @file svm_functions_f16.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _SVM_FUNCTIONS_F16_H_
  26. #define _SVM_FUNCTIONS_F16_H_
  27. #include "arm_math_types_f16.h"
  28. #include "arm_math_memory.h"
  29. #include "dsp/none.h"
  30. #include "dsp/utils.h"
  31. #include "dsp/svm_defines.h"
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. #if defined(ARM_FLOAT16_SUPPORTED)
  37. #define STEP(x) (x) <= 0 ? 0 : 1
  38. /**
  39. * @defgroup groupSVM SVM Functions
  40. * This set of functions is implementing SVM classification on 2 classes.
  41. * The training must be done from scikit-learn. The parameters can be easily
  42. * generated from the scikit-learn object. Some examples are given in
  43. * DSP/Testing/PatternGeneration/SVM.py
  44. *
  45. * If more than 2 classes are needed, the functions in this folder
  46. * will have to be used, as building blocks, to do multi-class classification.
  47. *
  48. * No multi-class classification is provided in this SVM folder.
  49. *
  50. */
  51. /**
  52. * @brief Instance structure for linear SVM prediction function.
  53. */
  54. typedef struct
  55. {
  56. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  57. uint32_t vectorDimension; /**< Dimension of vector space */
  58. float16_t intercept; /**< Intercept */
  59. const float16_t *dualCoefficients; /**< Dual coefficients */
  60. const float16_t *supportVectors; /**< Support vectors */
  61. const int32_t *classes; /**< The two SVM classes */
  62. } arm_svm_linear_instance_f16;
  63. /**
  64. * @brief Instance structure for polynomial SVM prediction function.
  65. */
  66. typedef struct
  67. {
  68. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  69. uint32_t vectorDimension; /**< Dimension of vector space */
  70. float16_t intercept; /**< Intercept */
  71. const float16_t *dualCoefficients; /**< Dual coefficients */
  72. const float16_t *supportVectors; /**< Support vectors */
  73. const int32_t *classes; /**< The two SVM classes */
  74. int32_t degree; /**< Polynomial degree */
  75. float16_t coef0; /**< Polynomial constant */
  76. float16_t gamma; /**< Gamma factor */
  77. } arm_svm_polynomial_instance_f16;
  78. /**
  79. * @brief Instance structure for rbf SVM prediction function.
  80. */
  81. typedef struct
  82. {
  83. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  84. uint32_t vectorDimension; /**< Dimension of vector space */
  85. float16_t intercept; /**< Intercept */
  86. const float16_t *dualCoefficients; /**< Dual coefficients */
  87. const float16_t *supportVectors; /**< Support vectors */
  88. const int32_t *classes; /**< The two SVM classes */
  89. float16_t gamma; /**< Gamma factor */
  90. } arm_svm_rbf_instance_f16;
  91. /**
  92. * @brief Instance structure for sigmoid SVM prediction function.
  93. */
  94. typedef struct
  95. {
  96. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  97. uint32_t vectorDimension; /**< Dimension of vector space */
  98. float16_t intercept; /**< Intercept */
  99. const float16_t *dualCoefficients; /**< Dual coefficients */
  100. const float16_t *supportVectors; /**< Support vectors */
  101. const int32_t *classes; /**< The two SVM classes */
  102. float16_t coef0; /**< Independent constant */
  103. float16_t gamma; /**< Gamma factor */
  104. } arm_svm_sigmoid_instance_f16;
  105. /**
  106. * @brief SVM linear instance init function
  107. * @param[in] S Parameters for SVM functions
  108. * @param[in] nbOfSupportVectors Number of support vectors
  109. * @param[in] vectorDimension Dimension of vector space
  110. * @param[in] intercept Intercept
  111. * @param[in] dualCoefficients Array of dual coefficients
  112. * @param[in] supportVectors Array of support vectors
  113. * @param[in] classes Array of 2 classes ID
  114. */
  115. void arm_svm_linear_init_f16(arm_svm_linear_instance_f16 *S,
  116. uint32_t nbOfSupportVectors,
  117. uint32_t vectorDimension,
  118. float16_t intercept,
  119. const float16_t *dualCoefficients,
  120. const float16_t *supportVectors,
  121. const int32_t *classes);
  122. /**
  123. * @brief SVM linear prediction
  124. * @param[in] S Pointer to an instance of the linear SVM structure.
  125. * @param[in] in Pointer to input vector
  126. * @param[out] pResult Decision value
  127. */
  128. void arm_svm_linear_predict_f16(const arm_svm_linear_instance_f16 *S,
  129. const float16_t * in,
  130. int32_t * pResult);
  131. /**
  132. * @brief SVM polynomial instance init function
  133. * @param[in] S points to an instance of the polynomial SVM structure.
  134. * @param[in] nbOfSupportVectors Number of support vectors
  135. * @param[in] vectorDimension Dimension of vector space
  136. * @param[in] intercept Intercept
  137. * @param[in] dualCoefficients Array of dual coefficients
  138. * @param[in] supportVectors Array of support vectors
  139. * @param[in] classes Array of 2 classes ID
  140. * @param[in] degree Polynomial degree
  141. * @param[in] coef0 coeff0 (scikit-learn terminology)
  142. * @param[in] gamma gamma (scikit-learn terminology)
  143. */
  144. void arm_svm_polynomial_init_f16(arm_svm_polynomial_instance_f16 *S,
  145. uint32_t nbOfSupportVectors,
  146. uint32_t vectorDimension,
  147. float16_t intercept,
  148. const float16_t *dualCoefficients,
  149. const float16_t *supportVectors,
  150. const int32_t *classes,
  151. int32_t degree,
  152. float16_t coef0,
  153. float16_t gamma
  154. );
  155. /**
  156. * @brief SVM polynomial prediction
  157. * @param[in] S Pointer to an instance of the polynomial SVM structure.
  158. * @param[in] in Pointer to input vector
  159. * @param[out] pResult Decision value
  160. */
  161. void arm_svm_polynomial_predict_f16(const arm_svm_polynomial_instance_f16 *S,
  162. const float16_t * in,
  163. int32_t * pResult);
  164. /**
  165. * @brief SVM radial basis function instance init function
  166. * @param[in] S points to an instance of the polynomial SVM structure.
  167. * @param[in] nbOfSupportVectors Number of support vectors
  168. * @param[in] vectorDimension Dimension of vector space
  169. * @param[in] intercept Intercept
  170. * @param[in] dualCoefficients Array of dual coefficients
  171. * @param[in] supportVectors Array of support vectors
  172. * @param[in] classes Array of 2 classes ID
  173. * @param[in] gamma gamma (scikit-learn terminology)
  174. */
  175. void arm_svm_rbf_init_f16(arm_svm_rbf_instance_f16 *S,
  176. uint32_t nbOfSupportVectors,
  177. uint32_t vectorDimension,
  178. float16_t intercept,
  179. const float16_t *dualCoefficients,
  180. const float16_t *supportVectors,
  181. const int32_t *classes,
  182. float16_t gamma
  183. );
  184. /**
  185. * @brief SVM rbf prediction
  186. * @param[in] S Pointer to an instance of the rbf SVM structure.
  187. * @param[in] in Pointer to input vector
  188. * @param[out] pResult decision value
  189. */
  190. void arm_svm_rbf_predict_f16(const arm_svm_rbf_instance_f16 *S,
  191. const float16_t * in,
  192. int32_t * pResult);
  193. /**
  194. * @brief SVM sigmoid instance init function
  195. * @param[in] S points to an instance of the rbf SVM structure.
  196. * @param[in] nbOfSupportVectors Number of support vectors
  197. * @param[in] vectorDimension Dimension of vector space
  198. * @param[in] intercept Intercept
  199. * @param[in] dualCoefficients Array of dual coefficients
  200. * @param[in] supportVectors Array of support vectors
  201. * @param[in] classes Array of 2 classes ID
  202. * @param[in] coef0 coeff0 (scikit-learn terminology)
  203. * @param[in] gamma gamma (scikit-learn terminology)
  204. */
  205. void arm_svm_sigmoid_init_f16(arm_svm_sigmoid_instance_f16 *S,
  206. uint32_t nbOfSupportVectors,
  207. uint32_t vectorDimension,
  208. float16_t intercept,
  209. const float16_t *dualCoefficients,
  210. const float16_t *supportVectors,
  211. const int32_t *classes,
  212. float16_t coef0,
  213. float16_t gamma
  214. );
  215. /**
  216. * @brief SVM sigmoid prediction
  217. * @param[in] S Pointer to an instance of the rbf SVM structure.
  218. * @param[in] in Pointer to input vector
  219. * @param[out] pResult Decision value
  220. */
  221. void arm_svm_sigmoid_predict_f16(const arm_svm_sigmoid_instance_f16 *S,
  222. const float16_t * in,
  223. int32_t * pResult);
  224. #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif /* ifndef _SVM_FUNCTIONS_F16_H_ */