CMSIS-DSP  
CMSIS DSP Software Library
 
Loading...
Searching...
No Matches
Bayesian estimators

Functions

uint32_t arm_gaussian_naive_bayes_predict_f16 (const arm_gaussian_naive_bayes_instance_f16 *S, const float16_t *in, float16_t *pOutputProbabilities, float16_t *pBufferB)
 Naive Gaussian Bayesian Estimator.
 
uint32_t arm_gaussian_naive_bayes_predict_f32 (const arm_gaussian_naive_bayes_instance_f32 *S, const float32_t *in, float32_t *pOutputProbabilities, float32_t *pBufferB)
 Naive Gaussian Bayesian Estimator.
 
void arm_sefr_init_f32 (arm_sefr_instance_f32 *S, uint32_t vectorDimension, uint32_t numberOfClasses, float32_t *pWeights, float32_t *pBias)
 Initialization of a SEFR classifier instance.
 
arm_status arm_sefr_lda_f32 (const arm_sefr_instance_f32 *S, const float32_t *pSrc, const uint32_t *pLabels, uint32_t numSamples, float32_t *pTmp)
 SEFR LDA stage.
 
uint32_t arm_sefr_predict_f32 (const arm_sefr_instance_f32 *S, const float32_t *pIn, float32_t *pScores)
 SEFR prediction.
 
arm_status arm_sefr_train_f32 (const arm_sefr_instance_f32 *S, const float32_t *pSrc, const uint32_t *pLabels, uint32_t numSamples, float32_t *pTmp)
 SEFR training.
 

Description

Implement the naive gaussian Bayes estimator. The training must be done from scikit-learn.

The parameters can be easily generated from the scikit-learn object. Some examples are given in DSP/Testing/PatternGeneration/Bayes.py

Also implement SEFR, a linear classifier that can be trained on the device. Training does not iterate and has no gradients or learning rate.

arm_sefr_train_f32 makes one pass over the labelled samples. arm_sefr_lda_f32 is an optional second pass that fits linear discriminant analysis on the class scores and writes the result into the same weights. It is usually more accurate, and the model size and prediction cost stay the same.

The caller provides all the memory: the model buffers for arm_sefr_init_f32 and the temporary buffers for the training functions.

The method comes from: H. Keshavarz, M. S. Abadeh, R. Rawassizadeh, "SEFR: A Fast Linear-Time Classifier for Ultra-Low Power Devices", https://arxiv.org/abs/2006.04620

Function Documentation

◆ arm_gaussian_naive_bayes_predict_f16()

uint32_t arm_gaussian_naive_bayes_predict_f16 ( const arm_gaussian_naive_bayes_instance_f16 * S,
const float16_t * in,
float16_t * pOutputProbabilities,
float16_t * pBufferB )

Naive Gaussian Bayesian Estimator.

Parameters
[in]*Spoints to a naive bayes instance structure
[in]*inpoints to the elements of the input vector.
[out]*pOutputProbabilitiespoints to a buffer of length numberOfClasses containing estimated probabilities
[out]*pBufferBpoints to a temporary buffer of length numberOfClasses
Returns
The predicted class

◆ arm_gaussian_naive_bayes_predict_f32()

uint32_t arm_gaussian_naive_bayes_predict_f32 ( const arm_gaussian_naive_bayes_instance_f32 * S,
const float32_t * in,
float32_t * pOutputProbabilities,
float32_t * pBufferB )

Naive Gaussian Bayesian Estimator.

Parameters
[in]*Spoints to a naive bayes instance structure
[in]*inpoints to the elements of the input vector.
[out]*pOutputProbabilitiespoints to a buffer of length numberOfClasses containing estimated probabilities
[out]*pBufferBpoints to a temporary buffer of length numberOfClasses
Returns
The predicted class

◆ arm_sefr_init_f32()

void arm_sefr_init_f32 ( arm_sefr_instance_f32 * S,
uint32_t vectorDimension,
uint32_t numberOfClasses,
float32_t * pWeights,
float32_t * pBias )

Initialization of a SEFR classifier instance.

Parameters
[out]Spoints to a SEFR instance structure
[in]vectorDimensiondimension of the input vectors
[in]numberOfClassesnumber of classes
[in]pWeightspoints to a buffer of numberOfClasses * vectorDimension values
[in]pBiaspoints to a buffer of numberOfClasses values

◆ arm_sefr_lda_f32()

arm_status arm_sefr_lda_f32 ( const arm_sefr_instance_f32 * S,
const float32_t * pSrc,
const uint32_t * pLabels,
uint32_t numSamples,
float32_t * pTmp )

SEFR LDA stage.

Parameters
[in,out]Spoints to a SEFR instance structure trained by arm_sefr_train_f32
[in]pSrcpoints to numSamples * vectorDimension training values, row major
[in]pLabelspoints to numSamples class indices in [0, numberOfClasses)
[in]numSamplesnumber of training samples
[out]pTmppoints to a temporary buffer of arm_sefr_lda_tmp_buffer_size() values
Returns
ARM_MATH_SUCCESS, ARM_MATH_ARGUMENT_ERROR if a label is out of range or a class has no samples, or the error from the matrix function that failed. An error leaves the model unchanged.
Algorithm
One more pass over the data fits linear discriminant analysis on the numberOfClasses scores of the trained model. It uses a Gaussian for each class with a shared covariance, and takes the class priors from the data. The result goes into the same weights and bias, so the model size and the cost of arm_sefr_predict_f32 stay the same.
Ridge
The ridge added to the covariance starts at 1e-6 of the mean score variance. It grows by a factor of 10 each time the Cholesky decomposition fails, which can happen in float32 when the scores are nearly collinear.

◆ arm_sefr_predict_f32()

uint32_t arm_sefr_predict_f32 ( const arm_sefr_instance_f32 * S,
const float32_t * pIn,
float32_t * pScores )

SEFR prediction.

Parameters
[in]Spoints to a SEFR instance structure
[in]pInpoints to the elements of the input vector
[out]pScorespoints to a buffer of numberOfClasses values receiving the class scores
Returns
The predicted class

◆ arm_sefr_train_f32()

arm_status arm_sefr_train_f32 ( const arm_sefr_instance_f32 * S,
const float32_t * pSrc,
const uint32_t * pLabels,
uint32_t numSamples,
float32_t * pTmp )

SEFR training.

Parameters
[in,out]Spoints to a SEFR instance structure
[in]pSrcpoints to numSamples * vectorDimension training values, row major
[in]pLabelspoints to numSamples class indices in [0, numberOfClasses)
[in]numSamplesnumber of training samples
[out]pTmppoints to a temporary buffer of arm_sefr_train_tmp_buffer_size() values
Returns
ARM_MATH_SUCCESS, or ARM_MATH_ARGUMENT_ERROR if there are no samples, if a label is out of range, or if a class has no samples or holds all of them. Do not use the model after an error.
Algorithm
One pass over the data collects the sum of each class, the class counts and the minimum and maximum of each feature. Features are scaled to [0, 1]. For class k and feature j, p is the mean of the class, r is the mean of all other samples, and the weight is (p - r) / (p + r). The threshold is the mean of w . p and w . r, each weighted by the size of the other group. The final weights and bias include the scaling, so the predictor takes raw features.