• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 
27 #ifndef _SVM_FUNCTIONS_F16_H_
28 #define _SVM_FUNCTIONS_F16_H_
29 
30 #include "arm_math_types_f16.h"
31 #include "arm_math_memory.h"
32 
33 #include "dsp/none.h"
34 #include "dsp/utils.h"
35 #include "dsp/svm_defines.h"
36 
37 
38 #ifdef   __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #if defined(ARM_FLOAT16_SUPPORTED)
44 
45 #define STEP(x) (x) <= 0 ? 0 : 1
46 
47 /**
48  * @defgroup groupSVM SVM Functions
49  * This set of functions is implementing SVM classification on 2 classes.
50  * The training must be done from scikit-learn. The parameters can be easily
51  * generated from the scikit-learn object. Some examples are given in
52  * DSP/Testing/PatternGeneration/SVM.py
53  *
54  * If more than 2 classes are needed, the functions in this folder
55  * will have to be used, as building blocks, to do multi-class classification.
56  *
57  * No multi-class classification is provided in this SVM folder.
58  *
59  */
60 
61 
62 
63 /**
64  * @brief Instance structure for linear 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 } arm_svm_linear_instance_f16;
75 
76 
77 /**
78  * @brief Instance structure for polynomial SVM prediction function.
79  */
80 typedef struct
81 {
82   uint32_t        nbOfSupportVectors;     /**< Number of support vectors */
83   uint32_t        vectorDimension;        /**< Dimension of vector space */
84   float16_t       intercept;              /**< Intercept */
85   const float16_t *dualCoefficients;      /**< Dual coefficients */
86   const float16_t *supportVectors;        /**< Support vectors */
87   const int32_t   *classes;               /**< The two SVM classes */
88   int32_t         degree;                 /**< Polynomial degree */
89   float16_t       coef0;                  /**< Polynomial constant */
90   float16_t       gamma;                  /**< Gamma factor */
91 } arm_svm_polynomial_instance_f16;
92 
93 /**
94  * @brief Instance structure for rbf SVM prediction function.
95  */
96 typedef struct
97 {
98   uint32_t        nbOfSupportVectors;     /**< Number of support vectors */
99   uint32_t        vectorDimension;        /**< Dimension of vector space */
100   float16_t       intercept;              /**< Intercept */
101   const float16_t *dualCoefficients;      /**< Dual coefficients */
102   const float16_t *supportVectors;        /**< Support vectors */
103   const int32_t   *classes;               /**< The two SVM classes */
104   float16_t       gamma;                  /**< Gamma factor */
105 } arm_svm_rbf_instance_f16;
106 
107 /**
108  * @brief Instance structure for sigmoid SVM prediction function.
109  */
110 typedef struct
111 {
112   uint32_t        nbOfSupportVectors;     /**< Number of support vectors */
113   uint32_t        vectorDimension;        /**< Dimension of vector space */
114   float16_t       intercept;              /**< Intercept */
115   const float16_t *dualCoefficients;      /**< Dual coefficients */
116   const float16_t *supportVectors;        /**< Support vectors */
117   const int32_t   *classes;               /**< The two SVM classes */
118   float16_t       coef0;                  /**< Independent constant */
119   float16_t       gamma;                  /**< Gamma factor */
120 } arm_svm_sigmoid_instance_f16;
121 
122 /**
123  * @brief        SVM linear instance init function
124  * @param[in]    S                      Parameters for SVM functions
125  * @param[in]    nbOfSupportVectors     Number of support vectors
126  * @param[in]    vectorDimension        Dimension of vector space
127  * @param[in]    intercept              Intercept
128  * @param[in]    dualCoefficients       Array of dual coefficients
129  * @param[in]    supportVectors         Array of support vectors
130  * @param[in]    classes                Array of 2 classes ID
131  * @return none.
132  *
133  */
134 
135 
136 void arm_svm_linear_init_f16(arm_svm_linear_instance_f16 *S,
137   uint32_t nbOfSupportVectors,
138   uint32_t vectorDimension,
139   float16_t intercept,
140   const float16_t *dualCoefficients,
141   const float16_t *supportVectors,
142   const int32_t  *classes);
143 
144 /**
145  * @brief SVM linear prediction
146  * @param[in]    S          Pointer to an instance of the linear SVM structure.
147  * @param[in]    in         Pointer to input vector
148  * @param[out]   pResult    Decision value
149  * @return none.
150  *
151  */
152 
153 void arm_svm_linear_predict_f16(const arm_svm_linear_instance_f16 *S,
154    const float16_t * in,
155    int32_t * pResult);
156 
157 
158 /**
159  * @brief        SVM polynomial instance init function
160  * @param[in]    S                      points to an instance of the polynomial SVM structure.
161  * @param[in]    nbOfSupportVectors     Number of support vectors
162  * @param[in]    vectorDimension        Dimension of vector space
163  * @param[in]    intercept              Intercept
164  * @param[in]    dualCoefficients       Array of dual coefficients
165  * @param[in]    supportVectors         Array of support vectors
166  * @param[in]    classes                Array of 2 classes ID
167  * @param[in]    degree                 Polynomial degree
168  * @param[in]    coef0                  coeff0 (scikit-learn terminology)
169  * @param[in]    gamma                  gamma (scikit-learn terminology)
170  * @return none.
171  *
172  */
173 
174 
175 void arm_svm_polynomial_init_f16(arm_svm_polynomial_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   int32_t      degree,
183   float16_t coef0,
184   float16_t gamma
185   );
186 
187 /**
188  * @brief SVM polynomial prediction
189  * @param[in]    S          Pointer to an instance of the polynomial SVM structure.
190  * @param[in]    in         Pointer to input vector
191  * @param[out]   pResult    Decision value
192  * @return none.
193  *
194  */
195 void arm_svm_polynomial_predict_f16(const arm_svm_polynomial_instance_f16 *S,
196    const float16_t * in,
197    int32_t * pResult);
198 
199 
200 /**
201  * @brief        SVM radial basis function instance init function
202  * @param[in]    S                      points to an instance of the polynomial SVM structure.
203  * @param[in]    nbOfSupportVectors     Number of support vectors
204  * @param[in]    vectorDimension        Dimension of vector space
205  * @param[in]    intercept              Intercept
206  * @param[in]    dualCoefficients       Array of dual coefficients
207  * @param[in]    supportVectors         Array of support vectors
208  * @param[in]    classes                Array of 2 classes ID
209  * @param[in]    gamma                  gamma (scikit-learn terminology)
210  * @return none.
211  *
212  */
213 
214 void arm_svm_rbf_init_f16(arm_svm_rbf_instance_f16 *S,
215   uint32_t nbOfSupportVectors,
216   uint32_t vectorDimension,
217   float16_t intercept,
218   const float16_t *dualCoefficients,
219   const float16_t *supportVectors,
220   const int32_t   *classes,
221   float16_t gamma
222   );
223 
224 /**
225  * @brief SVM rbf prediction
226  * @param[in]    S         Pointer to an instance of the rbf SVM structure.
227  * @param[in]    in        Pointer to input vector
228  * @param[out]   pResult   decision value
229  * @return none.
230  *
231  */
232 void arm_svm_rbf_predict_f16(const arm_svm_rbf_instance_f16 *S,
233    const float16_t * in,
234    int32_t * pResult);
235 
236 /**
237  * @brief        SVM sigmoid instance init function
238  * @param[in]    S                      points to an instance of the rbf SVM structure.
239  * @param[in]    nbOfSupportVectors     Number of support vectors
240  * @param[in]    vectorDimension        Dimension of vector space
241  * @param[in]    intercept              Intercept
242  * @param[in]    dualCoefficients       Array of dual coefficients
243  * @param[in]    supportVectors         Array of support vectors
244  * @param[in]    classes                Array of 2 classes ID
245  * @param[in]    coef0                  coeff0 (scikit-learn terminology)
246  * @param[in]    gamma                  gamma (scikit-learn terminology)
247  * @return none.
248  *
249  */
250 
251 void arm_svm_sigmoid_init_f16(arm_svm_sigmoid_instance_f16 *S,
252   uint32_t nbOfSupportVectors,
253   uint32_t vectorDimension,
254   float16_t intercept,
255   const float16_t *dualCoefficients,
256   const float16_t *supportVectors,
257   const int32_t   *classes,
258   float16_t coef0,
259   float16_t gamma
260   );
261 
262 /**
263  * @brief SVM sigmoid prediction
264  * @param[in]    S        Pointer to an instance of the rbf SVM structure.
265  * @param[in]    in       Pointer to input vector
266  * @param[out]   pResult  Decision value
267  * @return none.
268  *
269  */
270 void arm_svm_sigmoid_predict_f16(const arm_svm_sigmoid_instance_f16 *S,
271    const float16_t * in,
272    int32_t * pResult);
273 
274 
275 
276 #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
277 #ifdef   __cplusplus
278 }
279 #endif
280 
281 #endif /* ifndef _SVM_FUNCTIONS_F16_H_ */
282