| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- #include "SVMF32.h"
- #include <stdio.h>
- #include "Error.h"
- void SVMF32::test_svm_linear_predict_f32()
- {
- int32_t result;
- arm_svm_linear_predict_f32(&this->linear,inp,&result);
-
- }
- void SVMF32::test_svm_polynomial_predict_f32()
- {
- int32_t result;
- arm_svm_polynomial_predict_f32(&this->poly,inp,&result);
-
- }
- void SVMF32::test_svm_rbf_predict_f32()
- {
- int32_t result;
- arm_svm_rbf_predict_f32(&this->rbf,inp,&result);
-
- }
- void SVMF32::test_svm_sigmoid_predict_f32()
- {
- int32_t result;
- arm_svm_sigmoid_predict_f32(&this->sigmoid,inp,&result);
-
- }
- void SVMF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& testparams,Client::PatternMgr *mgr)
- {
-
- int kind;
- int nbp,nbi;
- const float32_t *paramsp;
- std::vector<Testing::param_t>::iterator it = testparams.begin();
- this->vecDim = *it++;
- this->nbSupportVectors = *it++;
- switch(id)
- {
- case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
- {
- samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
- params.reload(SVMF32::PARAMS_LINEAR_F32_ID,mgr);
- dims.reload(SVMF32::DIMS_LINEAR_S16_ID,mgr);
- int16_t *dimsp=dims.ptr();
- nbi = dimsp[2*this->nbLinear];
- nbp = dimsp[2*this->nbLinear + 1];
- paramsp = params.ptr() + nbp;
- inp=samples.ptr() + nbi;
- kind = SVMF32::LINEAR;
- }
- break;
- case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
- {
-
- samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
- params.reload(SVMF32::PARAMS_POLY_F32_ID,mgr);
- dims.reload(SVMF32::DIMS_POLY_S16_ID,mgr);
- int16_t *dimsp=dims.ptr();
- nbi = dimsp[2*this->nbPoly];
- nbp = dimsp[2*this->nbPoly + 1];
- paramsp = params.ptr() + nbp;
- inp=samples.ptr() + nbi;
- kind = SVMF32::POLY;
- }
- break;
- case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
- {
-
- samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
- params.reload(SVMF32::PARAMS_RBF_F32_ID,mgr);
- dims.reload(SVMF32::DIMS_RBF_S16_ID,mgr);
- int16_t *dimsp=dims.ptr();
- nbi = dimsp[2*this->nbRBF];
- nbp = dimsp[2*this->nbRBF + 1];
- paramsp = params.ptr() + nbp;
- inp=samples.ptr() + nbi;
- kind = SVMF32::RBF;
- }
- break;
- case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
- {
- samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
- params.reload(SVMF32::PARAMS_SIGMOID_F32_ID,mgr);
- dims.reload(SVMF32::DIMS_SIGMOID_S16_ID,mgr);
- int16_t *dimsp=dims.ptr();
- nbi = dimsp[2*this->nbSigmoid];
- nbp = dimsp[2*this->nbSigmoid + 1];
- paramsp = params.ptr() + nbp;
- inp=samples.ptr() + nbi;
- kind = SVMF32::SIGMOID;
- }
- break;
- }
-
-
- this->classes[0] = 0;
- this->classes[1] = 1;
- this->intercept=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors];
- this->supportVectors=paramsp;
- this->dualCoefs=paramsp + (this->vecDim*this->nbSupportVectors);
- switch(kind)
- {
-
- case SVMF32::POLY:
- this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
- this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
- this->degree=(int)paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 3];
- break;
- case SVMF32::RBF:
- this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1];
- break;
- case SVMF32::SIGMOID:
- this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
- this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
- break;
- }
-
- switch(id)
- {
- case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
- {
-
- arm_svm_linear_init_f32(&linear,
- this->nbSupportVectors,
- this->vecDim,
- this->intercept,
- this->dualCoefs,
- this->supportVectors,
- this->classes);
- }
- break;
- case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
- {
-
- arm_svm_polynomial_init_f32(&poly,
- this->nbSupportVectors,
- this->vecDim,
- this->intercept,
- this->dualCoefs,
- this->supportVectors,
- this->classes,
- this->degree,
- this->coef0,
- this->gamma
- );
- }
- break;
- case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
- {
-
- arm_svm_rbf_init_f32(&rbf,
- this->nbSupportVectors,
- this->vecDim,
- this->intercept,
- this->dualCoefs,
- this->supportVectors,
- this->classes,
- this->gamma
- );
- }
- break;
- case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
- {
-
- arm_svm_sigmoid_init_f32(&sigmoid,
- this->nbSupportVectors,
- this->vecDim,
- this->intercept,
- this->dualCoefs,
- this->supportVectors,
- this->classes,
- this->coef0,
- this->gamma
- );
- }
- break;
- }
-
- }
- void SVMF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
- {
- switch(id)
- {
- case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
- nbLinear++;
- break;
- case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
- nbPoly++;
- break;
- case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
- nbRBF++;
- break;
- case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
- nbSigmoid++;
- break;
- }
- }
|