arm_svm_example_f32_8c-example.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>arm_svm_example_f32.c</title>
  7. <title>CMSIS-DSP: arm_svm_example_f32.c</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <link href="cmsis.css" rel="stylesheet" type="text/css" />
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <script type="text/javascript" src="printComponentTabs.js"></script>
  13. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  14. <script type="text/javascript" src="resize.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/search.js"></script>
  22. <script type="text/javascript">
  23. $(document).ready(function() { searchBox.OnSelectItem(0); });
  24. </script>
  25. </head>
  26. <body>
  27. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  28. <div id="titlearea">
  29. <table cellspacing="0" cellpadding="0">
  30. <tbody>
  31. <tr style="height: 46px;">
  32. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  33. <td style="padding-left: 0.5em;">
  34. <div id="projectname">CMSIS-DSP
  35. &#160;<span id="projectnumber">Version 1.8.0</span>
  36. </div>
  37. <div id="projectbrief">CMSIS DSP Software Library</div>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. <!-- end header part -->
  44. <div id="CMSISnav" class="tabs1">
  45. <ul class="tablist">
  46. <script type="text/javascript">
  47. <!--
  48. writeComponentTabs.call(this);
  49. //-->
  50. </script>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.6 -->
  54. <script type="text/javascript">
  55. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  56. </script>
  57. <div id="navrow1" class="tabs">
  58. <ul class="tablist">
  59. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  60. <li><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
  61. <li><a href="modules.html"><span>Reference</span></a></li>
  62. <li>
  63. <div id="MSearchBox" class="MSearchBoxInactive">
  64. <span class="left">
  65. <img id="MSearchSelect" src="search/mag_sel.png"
  66. onmouseover="return searchBox.OnSearchSelectShow()"
  67. onmouseout="return searchBox.OnSearchSelectHide()"
  68. alt=""/>
  69. <input type="text" id="MSearchField" value="Search" accesskey="S"
  70. onfocus="searchBox.OnSearchFieldFocus(true)"
  71. onblur="searchBox.OnSearchFieldFocus(false)"
  72. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  73. </span><span class="right">
  74. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  75. </span>
  76. </div>
  77. </li>
  78. </ul>
  79. </div>
  80. </div><!-- top -->
  81. <div id="side-nav" class="ui-resizable side-nav-resizable">
  82. <div id="nav-tree">
  83. <div id="nav-tree-contents">
  84. <div id="nav-sync" class="sync"></div>
  85. </div>
  86. </div>
  87. <div id="splitbar" style="-moz-user-select:none;"
  88. class="ui-resizable-handle">
  89. </div>
  90. </div>
  91. <script type="text/javascript">
  92. $(document).ready(function(){initNavTree('arm_svm_example_f32_8c-example.html','');});
  93. </script>
  94. <div id="doc-content">
  95. <!-- window showing the filter options -->
  96. <div id="MSearchSelectWindow"
  97. onmouseover="return searchBox.OnSearchSelectShow()"
  98. onmouseout="return searchBox.OnSearchSelectHide()"
  99. onkeydown="return searchBox.OnSearchSelectKey(event)">
  100. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(11)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  101. <!-- iframe showing the search results (closed by default) -->
  102. <div id="MSearchResultsWindow">
  103. <iframe src="javascript:void(0)" frameborder="0"
  104. name="MSearchResults" id="MSearchResults">
  105. </iframe>
  106. </div>
  107. <div class="header">
  108. <div class="headertitle">
  109. <div class="title">arm_svm_example_f32.c</div> </div>
  110. </div><!--header-->
  111. <div class="contents">
  112. <div class="fragment"><div class="line"><span class="comment">/* ----------------------------------------------------------------------</span></div>
  113. <div class="line"><span class="comment">* Copyright (C) 2019-2020 ARM Limited. All rights reserved.</span></div>
  114. <div class="line"><span class="comment">*</span></div>
  115. <div class="line"><span class="comment">* $Date: 09. December 2019</span></div>
  116. <div class="line"><span class="comment">* $Revision: V1.0.0</span></div>
  117. <div class="line"><span class="comment">*</span></div>
  118. <div class="line"><span class="comment">* Project: CMSIS DSP Library</span></div>
  119. <div class="line"><span class="comment">* Title: arm_svm_example_f32.c</span></div>
  120. <div class="line"><span class="comment">*</span></div>
  121. <div class="line"><span class="comment">* Description: Example code demonstrating how to use SVM functions.</span></div>
  122. <div class="line"><span class="comment">*</span></div>
  123. <div class="line"><span class="comment">* Target Processor: Cortex-M/Cortex-A</span></div>
  124. <div class="line"><span class="comment">*</span></div>
  125. <div class="line"><span class="comment">* Redistribution and use in source and binary forms, with or without</span></div>
  126. <div class="line"><span class="comment">* modification, are permitted provided that the following conditions</span></div>
  127. <div class="line"><span class="comment">* are met:</span></div>
  128. <div class="line"><span class="comment">* - Redistributions of source code must retain the above copyright</span></div>
  129. <div class="line"><span class="comment">* notice, this list of conditions and the following disclaimer.</span></div>
  130. <div class="line"><span class="comment">* - Redistributions in binary form must reproduce the above copyright</span></div>
  131. <div class="line"><span class="comment">* notice, this list of conditions and the following disclaimer in</span></div>
  132. <div class="line"><span class="comment">* the documentation and/or other materials provided with the</span></div>
  133. <div class="line"><span class="comment">* distribution.</span></div>
  134. <div class="line"><span class="comment">* - Neither the name of ARM LIMITED nor the names of its contributors</span></div>
  135. <div class="line"><span class="comment">* may be used to endorse or promote products derived from this</span></div>
  136. <div class="line"><span class="comment">* software without specific prior written permission.</span></div>
  137. <div class="line"><span class="comment">*</span></div>
  138. <div class="line"><span class="comment">* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span></div>
  139. <div class="line"><span class="comment">* &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span></div>
  140. <div class="line"><span class="comment">* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</span></div>
  141. <div class="line"><span class="comment">* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE</span></div>
  142. <div class="line"><span class="comment">* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</span></div>
  143. <div class="line"><span class="comment">* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span></div>
  144. <div class="line"><span class="comment">* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span></div>
  145. <div class="line"><span class="comment">* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span></div>
  146. <div class="line"><span class="comment">* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span></div>
  147. <div class="line"><span class="comment">* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN</span></div>
  148. <div class="line"><span class="comment">* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span></div>
  149. <div class="line"><span class="comment">* POSSIBILITY OF SUCH DAMAGE.</span></div>
  150. <div class="line"><span class="comment">* -------------------------------------------------------------------- */</span></div>
  151. <div class="line"></div>
  152. <div class="line"><span class="preprocessor">#include &lt;math.h&gt;</span></div>
  153. <div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
  154. <div class="line"><span class="preprocessor">#include &quot;<a class="code" href="arm__math_8h.html">arm_math.h</a>&quot;</span></div>
  155. <div class="line"></div>
  156. <div class="line"><span class="comment">/* </span></div>
  157. <div class="line"><span class="comment"> The polynomial SVM instance containing all parameters.</span></div>
  158. <div class="line"><span class="comment"> Those parameters can be generated with the python library scikit-learn.</span></div>
  159. <div class="line"><span class="comment"> */</span></div>
  160. <div class="line"><a name="_a0"></a><a class="code" href="structarm__svm__polynomial__instance__f32.html">arm_svm_polynomial_instance_f32</a> <a name="a1"></a><a class="code" href="arm__svm__example__f32_8c.html#a1510c63c4febec3a2a58a2397e2b738d">params</a>;</div>
  161. <div class="line"></div>
  162. <div class="line"><span class="comment">/*</span></div>
  163. <div class="line"><span class="comment"> Parameters generated by a training of the SVM classifier</span></div>
  164. <div class="line"><span class="comment"> using scikit-learn and some random input data.</span></div>
  165. <div class="line"><span class="comment"> */</span></div>
  166. <div class="line"><span class="preprocessor">#define NB_SUPPORT_VECTORS 11</span></div>
  167. <div class="line"><span class="preprocessor"></span></div>
  168. <div class="line"><span class="comment">/*</span></div>
  169. <div class="line"><span class="comment"> Dimension of the vector space. A vector is your feature.</span></div>
  170. <div class="line"><span class="comment"> It could, for instance, be the pixels of a picture or the FFT of a signal.</span></div>
  171. <div class="line"><span class="comment"> */</span></div>
  172. <div class="line"><span class="preprocessor">#define VECTOR_DIMENSION 2</span></div>
  173. <div class="line"><span class="preprocessor"></span></div>
  174. <div class="line"><span class="keyword">const</span> <a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715">float32_t</a> <a name="a2"></a><a class="code" href="arm__svm__example__f32_8c.html#a6bee216b9b7e7b8d18687cd692e26a8a">dualCoefficients</a>[<a name="a3"></a><a class="code" href="arm__svm__example__f32_8c.html#a991d9a139527d1a747541de078ca21c7">NB_SUPPORT_VECTORS</a>]={-0.01628988f, -0.0971605f,</div>
  175. <div class="line"> -0.02707579f, 0.0249406f, 0.00223095f, 0.04117345f,</div>
  176. <div class="line"> 0.0262687f, 0.00800358f, 0.00581823f, 0.02346904f, 0.00862162f}; <span class="comment">/* Dual coefficients */</span></div>
  177. <div class="line"></div>
  178. <div class="line"><span class="keyword">const</span> <a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715">float32_t</a> <a name="a4"></a><a class="code" href="arm__svm__example__f32_8c.html#ac636d66272348052cde1083e5a0c3c60">supportVectors</a>[<a class="code" href="arm__svm__example__f32_8c.html#a991d9a139527d1a747541de078ca21c7">NB_SUPPORT_VECTORS</a>*<a name="a5"></a><a class="code" href="arm__svm__example__f32_8c.html#a98d2e2076140b796ee1cb5f3e77248a7">VECTOR_DIMENSION</a>]={ 1.2510991f, 0.47782799f,</div>
  179. <div class="line"> -0.32711859f, -1.49880648f, -0.08905047f, 1.31907242f,</div>
  180. <div class="line"> 1.14059333f, 2.63443767f, -2.62561524f, 1.02120701f,</div>
  181. <div class="line"> -1.2361353f, -2.53145187f,</div>
  182. <div class="line"> 2.28308122f, -1.58185875f, 2.73955981f, 0.35759327f,</div>
  183. <div class="line"> 0.56662986f, 2.79702016f,</div>
  184. <div class="line"> -2.51380816f, 1.29295364f, -0.56658669f, -2.81944734f}; <span class="comment">/* Support vectors */</span></div>
  185. <div class="line"></div>
  186. <div class="line"><span class="comment">/*</span></div>
  187. <div class="line"><span class="comment"> Class A is identified with value 0.</span></div>
  188. <div class="line"><span class="comment"> Class B is identified with value 1.</span></div>
  189. <div class="line"><span class="comment"> </span></div>
  190. <div class="line"><span class="comment"> This array is used by the SVM functions to do a conversion and ease the comparison</span></div>
  191. <div class="line"><span class="comment"> with the Python code where different values could be used.</span></div>
  192. <div class="line"><span class="comment"> */</span></div>
  193. <div class="line"><span class="keyword">const</span> int32_t <a name="a6"></a><a class="code" href="arm__svm__example__f32_8c.html#ae76f66a144055c576e6895e411417b63">classes</a>[2]={0,1};</div>
  194. <div class="line"></div>
  195. <div class="line"></div>
  196. <div class="line">int32_t <a name="a7"></a><a class="code" href="arm__svm__example__f32_8c.html#a52d2cba30e6946c95578be946ac12a65">main</a>(<span class="keywordtype">void</span>)</div>
  197. <div class="line">{</div>
  198. <div class="line"> <span class="comment">/* Array of input data */</span></div>
  199. <div class="line"> <a class="code" href="arm__math_8h.html#a4611b605e45ab401f02cab15c5e38715">float32_t</a> in[<a class="code" href="arm__svm__example__f32_8c.html#a98d2e2076140b796ee1cb5f3e77248a7">VECTOR_DIMENSION</a>];</div>
  200. <div class="line"></div>
  201. <div class="line"> <span class="comment">/* Result of the classifier */</span></div>
  202. <div class="line"> int32_t result;</div>
  203. <div class="line"> </div>
  204. <div class="line"></div>
  205. <div class="line"> <span class="comment">/*</span></div>
  206. <div class="line"><span class="comment"> Initialization of the SVM instance parameters.</span></div>
  207. <div class="line"><span class="comment"> Additional parameters (intercept, degree, coef0 and gamma) are also coming from Python.</span></div>
  208. <div class="line"><span class="comment"> */</span></div>
  209. <div class="line"> <a name="a8"></a><a class="code" href="group__groupSVM.html#gad004464aae8fdecfc985a02a0de6b0af">arm_svm_polynomial_init_f32</a>(&amp;params,</div>
  210. <div class="line"> <a class="code" href="arm__svm__example__f32_8c.html#a991d9a139527d1a747541de078ca21c7">NB_SUPPORT_VECTORS</a>,</div>
  211. <div class="line"> <a class="code" href="arm__svm__example__f32_8c.html#a98d2e2076140b796ee1cb5f3e77248a7">VECTOR_DIMENSION</a>,</div>
  212. <div class="line"> -1.661719f, <span class="comment">/* Intercept */</span></div>
  213. <div class="line"> <a class="code" href="arm__svm__example__f32_8c.html#a6bee216b9b7e7b8d18687cd692e26a8a">dualCoefficients</a>,</div>
  214. <div class="line"> <a class="code" href="arm__svm__example__f32_8c.html#ac636d66272348052cde1083e5a0c3c60">supportVectors</a>,</div>
  215. <div class="line"> <a class="code" href="arm__svm__example__f32_8c.html#ae76f66a144055c576e6895e411417b63">classes</a>,</div>
  216. <div class="line"> 3, <span class="comment">/* degree */</span></div>
  217. <div class="line"> 1.100000f, <span class="comment">/* Coef0 */</span></div>
  218. <div class="line"> 0.500000f <span class="comment">/* Gamma */</span></div>
  219. <div class="line"> );</div>
  220. <div class="line"></div>
  221. <div class="line"></div>
  222. <div class="line"> <span class="comment">/*</span></div>
  223. <div class="line"><span class="comment"> Input data.</span></div>
  224. <div class="line"><span class="comment"> It is corresponding to a point inside the first class.</span></div>
  225. <div class="line"><span class="comment"> */</span></div>
  226. <div class="line"> in[0] = 0.4f;</div>
  227. <div class="line"> in[1] = 0.1f;</div>
  228. <div class="line"></div>
  229. <div class="line"> <a name="a9"></a><a class="code" href="group__groupSVM.html#ga5719f32544ecc1b568aaba7f5d237df8">arm_svm_polynomial_predict_f32</a>(&amp;params, in, &amp;result);</div>
  230. <div class="line"></div>
  231. <div class="line"> <span class="comment">/* Result should be 0 : First class */</span></div>
  232. <div class="line"><span class="preprocessor">#if defined(SEMIHOSTING)</span></div>
  233. <div class="line"><span class="preprocessor"></span> printf(<span class="stringliteral">&quot;Result = %d\n&quot;</span>, result);</div>
  234. <div class="line"><span class="preprocessor">#endif</span></div>
  235. <div class="line"><span class="preprocessor"></span></div>
  236. <div class="line"> <span class="comment">/*</span></div>
  237. <div class="line"><span class="comment"> This input vector is corresponding to a point inside the second class.</span></div>
  238. <div class="line"><span class="comment"> */</span></div>
  239. <div class="line"> in[0] = 3.0f;</div>
  240. <div class="line"> in[1] = 0.0f;</div>
  241. <div class="line"></div>
  242. <div class="line"> <a class="code" href="group__groupSVM.html#ga5719f32544ecc1b568aaba7f5d237df8">arm_svm_polynomial_predict_f32</a>(&amp;params, in, &amp;result);</div>
  243. <div class="line"> </div>
  244. <div class="line"> <span class="comment">/* Result should be 1 : Second class */</span></div>
  245. <div class="line"><span class="preprocessor">#if defined(SEMIHOSTING)</span></div>
  246. <div class="line"><span class="preprocessor"></span> printf(<span class="stringliteral">&quot;Result = %d\n&quot;</span>, result);</div>
  247. <div class="line"><span class="preprocessor">#endif</span></div>
  248. <div class="line"><span class="preprocessor"></span></div>
  249. <div class="line"><span class="preprocessor">#if !defined(SEMIHOSTING)</span></div>
  250. <div class="line"><span class="preprocessor"></span> <span class="keywordflow">while</span> (1); <span class="comment">/* main function does not return */</span></div>
  251. <div class="line"><span class="preprocessor">#endif</span></div>
  252. <div class="line"><span class="preprocessor"></span>}</div>
  253. <div class="line"></div>
  254. <div class="line"></div>
  255. <div class="line"></div>
  256. </div><!-- fragment --> </div><!-- contents -->
  257. </div><!-- doc-content -->
  258. <!-- start footer part -->
  259. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  260. <ul>
  261. <li class="footer">Generated on Thu Apr 9 2020 15:49:21 for CMSIS-DSP Version 1.8.0 by Arm Ltd. All rights reserved.
  262. <!--
  263. <a href="http://www.doxygen.org/index.html">
  264. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
  265. -->
  266. </li>
  267. </ul>
  268. </div>
  269. </body>
  270. </html>