/*
* Imagimob Studio 5.1.1818.65534+396956ed1117c887044d045bd0b5090c686f8a93
* Copyright © 2023- Imagimob AB, All Rights Reserved.
* 
* Generated at 08/01/2024 14:13:33 UTC. Any changes will be lost.
* 
* Model ID  2759e08d-2185-4bfe-88d0-c253d934ca3a
* 
* Memory    Size                      Efficiency
* Buffers   120 bytes (RAM)           80 %
* State     232 bytes (RAM)           100 %
* Readonly  836 bytes (Flash)         100 %
* 
* Backend              tensorflow
* Keras Version        2.15.0
* Backend Model Type   Sequential
* Backend Model Name   conv_fast2
* 
* Class Index | Symbol Label
* 0           | unlabelled
* 1           | right
* 2           | left
* 
* Layer                          Shape           Type       Function
* Sliding Window (data points)   [6,1]           float      dequeue
*    window_shape = [6,1]
*    stride = 1
*    buffer_multiplier = 1
* Input Layer                    [6,1]           float      dequeue
*    shape = [6,1]
* Convolution 1D                 [3,4]           float      dequeue
*    filters = 4
*    kernel_size = 4
*    dilation_rate = 1
*    strides = 1
*    padding = valid
*    activation = relu
*    use_bias = True
*    trainable = True
*    weight = float[4,1,4]
*    bias = float[4]
* Batch Normalization            [3,4]           float      dequeue
*    epsilon = 0.001
*    trainable = True
*    scale = True
*    center = True
*    axis = 2
*    gamma = float[4]
*    beta = float[4]
*    mean = float[4]
*    variance = float[4]
* Convolution 1D                 [1,6]           float      dequeue
*    filters = 6
*    kernel_size = 3
*    dilation_rate = 1
*    strides = 1
*    padding = valid
*    activation = relu
*    use_bias = True
*    trainable = True
*    weight = float[3,4,6]
*    bias = float[6]
* Dense                          [10]            float      dequeue
*    units = 10
*    use_bias = True
*    activation = relu
*    trainable = True
*    weight = float[6,10]
*    bias = float[10]
* Flatten                        [10]            float      dequeue
* Dense                          [3]             float      dequeue
*    units = 3
*    use_bias = True
*    activation = softmax
*    trainable = True
*    weight = float[10,3]
*    bias = float[3]
* 
* Exported functions:
* 
* int GES_NN_dequeue(float *restrict data_out)
*    Description: Dequeue features. RET_SUCCESS (0) on success, RET_NODATA (-1) if no data is available, RET_NOMEM (-2) on internal memory error
*    Parameter data_out is Output of size float[3].
* 
* int GES_NN_enqueue(const float *restrict data_in)
*    Description: Enqueue features. Returns SUCCESS (0) on success, else RET_NOMEM (-2) when low on memory.
*    Parameter data_in is Input of size float[1].
* 
* void GES_NN_init(void)
*    Description: Initializes buffers to initial state. This function also works as a reset function.
* 
* 
* Disclaimer:
*   The generated code relies on the optimizations done by the C compiler.
*   For example many for-loops of length 1 must be removed by the optimizer.
*   This can only be done if the functions are inlined and simplified.
*   Check disassembly if unsure.
*   tl;dr Compile using gcc with -O3 or -Ofast
*/

#ifndef _GES_NN_GESTURES_NN_H_
#define _GES_NN_GESTURES_NN_H_
#ifdef _MSC_VER
#pragma once
#endif

#include <stdint.h>

typedef struct {    
    char *name;
    double TP; // True Positive or Correct Positive Prediction
    double FN; // False Negative or Incorrect Negative Prediction
    double FP; // False Positive or Incorrect Positive Prediction
    double TN; // True Negative or Correct Negative Prediction
    double TPR; // True Positive Rate or Sensitivity, Recall
    double TNR; // True Negative Rate or Specificity, Selectivity
    double PPV; // Positive Predictive Value or Precision
    double NPV; // Negative Predictive Value
    double FNR; // False Negative Rate or Miss Rate
    double FPR; // False Positive Rate or Fall-Out
    double FDR; // False Discovery Rate
    double FOR; // False Omission Rate
    double F1S; // F1 Score
} GES_NN_stats;

/*
* Tensorflow Test Set
* 
* (ACC) Accuracy 97.030 %
* (F1S) F1 Score 97.086 %
* 
* Name of class                                            (unlabelled)             left            right
* (TP) True Positive or Correct Positive Prediction                6568              639              698
* (FN) False Negative or Incorrect Negative Prediction              176               27               39
* (FP) False Positive or Incorrect Positive Prediction               66              126               50
* (TN) True Negative or Correct Negative Prediction                1337             7355             7360
* (TPR) True Positive Rate or Sensitivity, Recall               97.39 %          95.95 %          94.71 %
* (TNR) True Negative Rate or Specificity, Selectivity          95.30 %          98.32 %          99.33 %
* (PPV) Positive Predictive Value or Precision                  99.01 %          83.53 %          93.32 %
* (NPV) Negative Predictive Value                               88.37 %          99.63 %          99.47 %
* (FNR) False Negative Rate or Miss Rate                         2.61 %           4.05 %           5.29 %
* (FPR) False Positive Rate or Fall-Out                          4.70 %           1.68 %           0.67 %
* (FDR) False Discovery Rate                                     0.99 %          16.47 %           6.68 %
* (FOR) False Omission Rate                                     11.63 %           0.37 %           0.53 %
* (F1S) F1 Score                                                98.19 %          89.31 %          94.01 %
*/


#define GES_NN_TEST_AVG_ACC 0.9702958144102124 // Accuracy
#define GES_NN_TEST_AVG_F1S 0.9708637738347689 // F1 Score

#define GES_NN_TEST_STATS { \
 {name: "(unlabelled)", TP: 6568, FN: 176, FP: 66, TN: 1337, TPR: 0.9739027283511, TNR: 0.9529579472558, PPV: 0.9900512511305, NPV: 0.8836748182419, FNR: 0.0260972716488, FPR: 0.0470420527441, FDR: 0.0099487488694, FOR: 0.1163251817580, F1S: 0.9819105994917, }, \
 {name: "right", TP: 698, FN: 39, FP: 50, TN: 7360, TPR: 0.9470827679782, TNR: 0.9932523616734, PPV: 0.9331550802139, NPV: 0.9947290174347, FNR: 0.0529172320217, FPR: 0.0067476383265, FDR: 0.0668449197860, FOR: 0.0052709825652, F1S: 0.9400673400673, }, \
 {name: "left", TP: 639, FN: 27, FP: 126, TN: 7355, TPR: 0.9594594594594, TNR: 0.9831573319074, PPV: 0.8352941176470, NPV: 0.9963424546193, FNR: 0.0405405405405, FPR: 0.0168426680925, FDR: 0.1647058823529, FOR: 0.0036575453806, F1S: 0.8930817610062, }, \
}

#ifdef GES_NN_STATS_ENABLED
static const GES_NN_stats GES_NN_test_stats[] = GES_NN_TEST_STATS;
#endif

/*
* Tensorflow Train Set
* 
* (ACC) Accuracy 96.403 %
* (F1S) F1 Score 96.453 %
* 
* Name of class                                            (unlabelled)             left            right
* (TP) True Positive or Correct Positive Prediction                9341             1149             1170
* (FN) False Negative or Incorrect Negative Prediction              296               42               97
* (FP) False Positive or Incorrect Positive Prediction              139              208               88
* (TN) True Negative or Correct Negative Prediction                2319            10696            10740
* (TPR) True Positive Rate or Sensitivity, Recall               96.93 %          96.47 %          92.34 %
* (TNR) True Negative Rate or Specificity, Selectivity          94.34 %          98.09 %          99.19 %
* (PPV) Positive Predictive Value or Precision                  98.53 %          84.67 %          93.00 %
* (NPV) Negative Predictive Value                               88.68 %          99.61 %          99.10 %
* (FNR) False Negative Rate or Miss Rate                         3.07 %           3.53 %           7.66 %
* (FPR) False Positive Rate or Fall-Out                          5.66 %           1.91 %           0.81 %
* (FDR) False Discovery Rate                                     1.47 %          15.33 %           7.00 %
* (FOR) False Omission Rate                                     11.32 %           0.39 %           0.90 %
* (F1S) F1 Score                                                97.72 %          90.19 %          92.67 %
*/


#define GES_NN_TRAIN_AVG_ACC 0.9640347250930137 // Accuracy
#define GES_NN_TRAIN_AVG_F1S 0.9645330881952521 // F1 Score

#define GES_NN_TRAIN_STATS { \
 {name: "(unlabelled)", TP: 9341, FN: 296, FP: 139, TN: 2319, TPR: 0.9692850472138, TNR: 0.9434499593165, PPV: 0.9853375527426, NPV: 0.8868068833652, FNR: 0.0307149527861, FPR: 0.0565500406834, FDR: 0.0146624472573, FOR: 0.1131931166347, F1S: 0.9772453836899, }, \
 {name: "right", TP: 1170, FN: 97, FP: 88, TN: 10740, TPR: 0.9234411996842, TNR: 0.9918729220539, PPV: 0.9300476947535, NPV: 0.9910491833533, FNR: 0.0765588003157, FPR: 0.0081270779460, FDR: 0.0699523052464, FOR: 0.0089508166466, F1S: 0.9267326732673, }, \
 {name: "left", TP: 1149, FN: 42, FP: 208, TN: 10696, TPR: 0.9647355163727, TNR: 0.9809244314013, PPV: 0.8467207074428, NPV: 0.9960886571056, FNR: 0.0352644836272, FPR: 0.0190755685986, FDR: 0.1532792925571, FOR: 0.0039113428943, F1S: 0.9018838304552, }, \
}

#ifdef GES_NN_STATS_ENABLED
static const GES_NN_stats GES_NN_train_stats[] = GES_NN_TRAIN_STATS;
#endif

/*
* Tensorflow Validation Set
* 
* (ACC) Accuracy 96.659 %
* (F1S) F1 Score 96.675 %
* 
* Name of class                                            (unlabelled)             left            right
* (TP) True Positive or Correct Positive Prediction                5841              687              705
* (FN) False Negative or Incorrect Negative Prediction              136               47               67
* (FP) False Positive or Incorrect Positive Prediction              114               97               39
* (TN) True Negative or Correct Negative Prediction                1392             6652             6672
* (TPR) True Positive Rate or Sensitivity, Recall               97.72 %          93.60 %          91.32 %
* (TNR) True Negative Rate or Specificity, Selectivity          92.43 %          98.56 %          99.42 %
* (PPV) Positive Predictive Value or Precision                  98.09 %          87.63 %          94.76 %
* (NPV) Negative Predictive Value                               91.10 %          99.30 %          99.01 %
* (FNR) False Negative Rate or Miss Rate                         2.28 %           6.40 %           8.68 %
* (FPR) False Positive Rate or Fall-Out                          7.57 %           1.44 %           0.58 %
* (FDR) False Discovery Rate                                     1.91 %          12.37 %           5.24 %
* (FOR) False Omission Rate                                      8.90 %           0.70 %           0.99 %
* (F1S) F1 Score                                                97.90 %          90.51 %          93.01 %
*/


#define GES_NN_VALIDATION_AVG_ACC 0.9665909394627823 // Accuracy
#define GES_NN_VALIDATION_AVG_F1S 0.9667462484301595 // F1 Score

#define GES_NN_VALIDATION_STATS { \
 {name: "(unlabelled)", TP: 5841, FN: 136, FP: 114, TN: 1392, TPR: 0.9772461100886, TNR: 0.9243027888446, PPV: 0.9808564231738, NPV: 0.9109947643979, FNR: 0.0227538899113, FPR: 0.0756972111553, FDR: 0.0191435768261, FOR: 0.0890052356020, F1S: 0.9790479383171, }, \
 {name: "right", TP: 705, FN: 67, FP: 39, TN: 6672, TPR: 0.9132124352331, TNR: 0.9941886455073, PPV: 0.9475806451612, NPV: 0.9900578720878, FNR: 0.0867875647668, FPR: 0.0058113544926, FDR: 0.0524193548387, FOR: 0.0099421279121, F1S: 0.9300791556728, }, \
 {name: "left", TP: 687, FN: 47, FP: 97, TN: 6652, TPR: 0.9359673024523, TNR: 0.9856275003704, PPV: 0.8762755102040, NPV: 0.9929840274667, FNR: 0.0640326975476, FPR: 0.0143724996295, FDR: 0.1237244897959, FOR: 0.0070159725332, F1S: 0.9051383399209, }, \
}

#ifdef GES_NN_STATS_ENABLED
static const GES_NN_stats GES_NN_validation_stats[] = GES_NN_VALIDATION_STATS;
#endif

#define GES_NN_API_QUEUE

// All symbols in order
#define GES_NN_SYMBOL_MAP {"unlabelled", "right", "left"}

// Model GUID (16 bytes)
#define GES_NN_MODEL_ID {0x8d, 0xe0, 0x59, 0x27, 0x85, 0x21, 0xfe, 0x4b, 0x88, 0xd0, 0xc2, 0x53, 0xd9, 0x34, 0xca, 0x3a}

// First nibble is bit encoding, second nibble is number of bytes
#define IMAGINET_TYPES_NONE	(0x0)
#define IMAGINET_TYPES_FLOAT32	(0x14)
#define IMAGINET_TYPES_FLOAT64	(0x18)
#define IMAGINET_TYPES_INT8	(0x21)
#define IMAGINET_TYPES_INT16	(0x22)
#define IMAGINET_TYPES_INT32	(0x24)
#define IMAGINET_TYPES_INT64	(0x28)
#define IMAGINET_TYPES_QDYN8	(0x31)
#define IMAGINET_TYPES_QDYN16	(0x32)
#define IMAGINET_TYPES_QDYN32	(0x34)

// data_in [1] (4 bytes)
#define GES_NN_DATA_IN_COUNT (1)
#define GES_NN_DATA_IN_TYPE float
#define GES_NN_DATA_IN_TYPE_ID IMAGINET_TYPES_FLOAT32
#define GES_NN_DATA_IN_SCALE (1)
#define GES_NN_DATA_IN_OFFSET (0)
#define GES_NN_DATA_IN_IS_QUANTIZED (0)

// data_out [3] (12 bytes)
#define GES_NN_DATA_OUT_COUNT (3)
#define GES_NN_DATA_OUT_TYPE float
#define GES_NN_DATA_OUT_TYPE_ID IMAGINET_TYPES_FLOAT32
#define GES_NN_DATA_OUT_SCALE (1)
#define GES_NN_DATA_OUT_OFFSET (0)
#define GES_NN_DATA_OUT_IS_QUANTIZED (0)

#define GES_NN_KEY_MAX (25)



// Return codes
#define GES_NN_RET_SUCCESS 0
#define GES_NN_RET_NODATA -1
#define GES_NN_RET_NOMEM -2

// Exported methods
int GES_NN_dequeue(float *restrict data_out);
int GES_NN_enqueue(const float *restrict data_in);
void GES_NN_init(void);

#endif /* _GES_NN_GESTURES_NN_H_ */
