svm_functions_f16.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. * @return none.
  115. *
  116. */
  117. void arm_svm_linear_init_f16(arm_svm_linear_instance_f16 *S,
  118. uint32_t nbOfSupportVectors,
  119. uint32_t vectorDimension,
  120. float16_t intercept,
  121. const float16_t *dualCoefficients,
  122. const float16_t *supportVectors,
  123. const int32_t *classes);
  124. /**
  125. * @brief SVM linear prediction
  126. * @param[in] S Pointer to an instance of the linear SVM structure.
  127. * @param[in] in Pointer to input vector
  128. * @param[out] pResult Decision value
  129. * @return none.
  130. *
  131. */
  132. void arm_svm_linear_predict_f16(const arm_svm_linear_instance_f16 *S,
  133. const float16_t * in,
  134. int32_t * pResult);
  135. /**
  136. * @brief SVM polynomial instance init function
  137. * @param[in] S points to an instance of the polynomial SVM structure.
  138. * @param[in] nbOfSupportVectors Number of support vectors
  139. * @param[in] vectorDimension Dimension of vector space
  140. * @param[in] intercept Intercept
  141. * @param[in] dualCoefficients Array of dual coefficients
  142. * @param[in] supportVectors Array of support vectors
  143. * @param[in] classes Array of 2 classes ID
  144. * @param[in] degree Polynomial degree
  145. * @param[in] coef0 coeff0 (scikit-learn terminology)
  146. * @param[in] gamma gamma (scikit-learn terminology)
  147. * @return none.
  148. *
  149. */
  150. void arm_svm_polynomial_init_f16(arm_svm_polynomial_instance_f16 *S,
  151. uint32_t nbOfSupportVectors,
  152. uint32_t vectorDimension,
  153. float16_t intercept,
  154. const float16_t *dualCoefficients,
  155. const float16_t *supportVectors,
  156. const int32_t *classes,
  157. int32_t degree,
  158. float16_t coef0,
  159. float16_t gamma
  160. );
  161. /**
  162. * @brief SVM polynomial prediction
  163. * @param[in] S Pointer to an instance of the polynomial SVM structure.
  164. * @param[in] in Pointer to input vector
  165. * @param[out] pResult Decision value
  166. * @return none.
  167. *
  168. */
  169. void arm_svm_polynomial_predict_f16(const arm_svm_polynomial_instance_f16 *S,
  170. const float16_t * in,
  171. int32_t * pResult);
  172. /**
  173. * @brief SVM radial basis function instance init function
  174. * @param[in] S points to an instance of the polynomial SVM structure.
  175. * @param[in] nbOfSupportVectors Number of support vectors
  176. * @param[in] vectorDimension Dimension of vector space
  177. * @param[in] intercept Intercept
  178. * @param[in] dualCoefficients Array of dual coefficients
  179. * @param[in] supportVectors Array of support vectors
  180. * @param[in] classes Array of 2 classes ID
  181. * @param[in] gamma gamma (scikit-learn terminology)
  182. * @return none.
  183. *
  184. */
  185. void arm_svm_rbf_init_f16(arm_svm_rbf_instance_f16 *S,
  186. uint32_t nbOfSupportVectors,
  187. uint32_t vectorDimension,
  188. float16_t intercept,
  189. const float16_t *dualCoefficients,
  190. const float16_t *supportVectors,
  191. const int32_t *classes,
  192. float16_t gamma
  193. );
  194. /**
  195. * @brief SVM rbf prediction
  196. * @param[in] S Pointer to an instance of the rbf SVM structure.
  197. * @param[in] in Pointer to input vector
  198. * @param[out] pResult decision value
  199. * @return none.
  200. *
  201. */
  202. void arm_svm_rbf_predict_f16(const arm_svm_rbf_instance_f16 *S,
  203. const float16_t * in,
  204. int32_t * pResult);
  205. /**
  206. * @brief SVM sigmoid instance init function
  207. * @param[in] S points to an instance of the rbf SVM structure.
  208. * @param[in] nbOfSupportVectors Number of support vectors
  209. * @param[in] vectorDimension Dimension of vector space
  210. * @param[in] intercept Intercept
  211. * @param[in] dualCoefficients Array of dual coefficients
  212. * @param[in] supportVectors Array of support vectors
  213. * @param[in] classes Array of 2 classes ID
  214. * @param[in] coef0 coeff0 (scikit-learn terminology)
  215. * @param[in] gamma gamma (scikit-learn terminology)
  216. * @return none.
  217. *
  218. */
  219. void arm_svm_sigmoid_init_f16(arm_svm_sigmoid_instance_f16 *S,
  220. uint32_t nbOfSupportVectors,
  221. uint32_t vectorDimension,
  222. float16_t intercept,
  223. const float16_t *dualCoefficients,
  224. const float16_t *supportVectors,
  225. const int32_t *classes,
  226. float16_t coef0,
  227. float16_t gamma
  228. );
  229. /**
  230. * @brief SVM sigmoid prediction
  231. * @param[in] S Pointer to an instance of the rbf SVM structure.
  232. * @param[in] in Pointer to input vector
  233. * @param[out] pResult Decision value
  234. * @return none.
  235. *
  236. */
  237. void arm_svm_sigmoid_predict_f16(const arm_svm_sigmoid_instance_f16 *S,
  238. const float16_t * in,
  239. int32_t * pResult);
  240. #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
  241. #ifdef __cplusplus
  242. }
  243. #endif
  244. #endif /* ifndef _SVM_FUNCTIONS_F16_H_ */