You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
/* ----------------------------------------------------------------------
|
|
* Project: CMSIS DSP Library
|
|
* Title: arm_svm_polynomial_predict_f32.c
|
|
* Description: SVM Polynomial Classifier
|
|
*
|
|
*
|
|
* Target Processor: Cortex-M and Cortex-A cores
|
|
* -------------------------------------------------------------------- */
|
|
/*
|
|
* Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
|
* not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "svmDef.hpp"
|
|
|
|
#define STEP(x) (x) <= 0 ? 0 : 1
|
|
|
|
static float32_t arm_exponent_f32(float32_t x, int32_t nb)
|
|
{
|
|
float32_t r = x;
|
|
nb --;
|
|
while(nb > 0)
|
|
{
|
|
r = r * x;
|
|
nb--;
|
|
}
|
|
return(r);
|
|
}
|
|
|
|
void arm_svm_polynomial_predict_f32(
|
|
const arm_svm_polynomial_instance_f32 *S,
|
|
const float32_t * in,
|
|
float32_t *pResult)
|
|
{
|
|
float32_t sum=S->intercept;
|
|
float32_t dot=0;
|
|
uint32_t i,j;
|
|
const float32_t *pSupport = S->supportVectors;
|
|
|
|
for(i=0; i < S->nbOfSupportVectors; i++)
|
|
{
|
|
dot=0;
|
|
for(j=0; j < S->vectorDimension; j++)
|
|
{
|
|
dot = dot + in[j]* *pSupport++;
|
|
}
|
|
sum += S->dualCoefficients[i] * arm_exponent_f32(S->gamma * dot + S->coef0, S->degree);
|
|
}
|
|
|
|
/*
|
|
Original CMSIS-DSP is returning the class.
|
|
Here we are returning the value and the class is computed by the client.
|
|
|
|
*/
|
|
*pResult=sum;
|
|
}
|