CMSIS-DSP: Added Bayes benchmarks

pull/19/head
Christophe Favergeon 5 years ago
parent 9d7dc65c3b
commit c2325e1370

@ -150,6 +150,7 @@ set (NNSRC
Source/Benchmarks/ComplexMathsBenchmarksF32.cpp
Source/Benchmarks/ComplexMathsBenchmarksQ31.cpp
Source/Benchmarks/ComplexMathsBenchmarksQ15.cpp
Source/Benchmarks/BayesF32.cpp
Source/Benchmarks/FIRF32.cpp
Source/Benchmarks/FIRQ31.cpp
Source/Benchmarks/FIRQ15.cpp

@ -0,0 +1,37 @@
#include "Test.h"
#include "Pattern.h"
#include "dsp/bayes_functions.h"
class BayesF32:public Client::Suite
{
public:
BayesF32(Testing::testID_t id);
virtual void setUp(Testing::testID_t,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr);
virtual void tearDown(Testing::testID_t,Client::PatternMgr *mgr);
private:
#include "BayesF32_decl.h"
Client::Pattern<float32_t> input;
Client::Pattern<float32_t> params;
Client::Pattern<int16_t> dims;
Client::LocalPattern<float32_t> outputProbas;
Client::LocalPattern<int16_t> outputPredicts;
// Reference patterns are not loaded when we are in dump mode
Client::RefPattern<int16_t> predicts;
int classNb,vecDim;
int nb=0;
const float32_t *theta;
const float32_t *sigma;
const float32_t *classPrior;
float32_t epsilon;
arm_gaussian_naive_bayes_instance_f32 bayes;
const float32_t *inp;
float32_t *bufp;
};

@ -0,0 +1,19 @@
18
12
3
12
5
12
4
14
3
14
5
14
4
20
3
20
5
20
4

@ -0,0 +1,19 @@
18
12
3
12
5
12
4
14
3
14
5
14
4
20
3
20
5
20
4

@ -0,0 +1,19 @@
18
12
3
12
5
12
4
14
3
14
5
14
4
20
3
20
5
20
4

@ -0,0 +1,19 @@
18
12
3
12
5
12
4
14
3
14
5
14
4
20
3
20
5
20
4

@ -142,6 +142,52 @@ def generateNewTest(config,nb):
def writeTests(config):
generateNewTest(config,1)
def writeBenchmark(config):
someLists=[VECDIM,BAYESCLASSES]
r=np.array([element for element in itertools.product(*someLists)])
nbtests=len(VECDIM)*len(BAYESCLASSES)*2
config.writeParam(2, r.reshape(nbtests))
params=[]
inputs=[]
referencepredict=[]
dims=[]
nbin=0
nbparam=0;
for vecDim, classNb in r:
gb = trainGaussian(classNb,vecDim)
p = []
p += list(np.reshape(gb.theta_,np.size(gb.theta_)))
p += list(np.reshape(gb.sigma_,np.size(gb.sigma_)))
p += list(np.reshape(gb.class_prior_,np.size(gb.class_prior_)))
p.append(gb.epsilon_)
params += p
dims += [nbin,nbparam]
nbparam = nbparam + len(p)
v,c=newRandomVector(classNb,vecDim,PREDICTRATIO)
inputs += v
nbin = nbin + len(v)
y_pred = gb.predict([v])
referencepredict.append(y_pred[0])
inputs = np.array(inputs)
params = np.array(params)
referencepredict = np.array(referencepredict)
dims = np.array(dims)
config.writeInput(2, inputs,"Inputs")
config.writeReferenceS16(2, referencepredict,"Predicts")
config.writeReference(2, params,"Params")
config.writeInputS16(2, dims,"DimsBench")
def generatePatterns():
PATTERNDIR = os.path.join("Patterns","DSP","Bayes","Bayes")
PARAMDIR = os.path.join("Parameters","DSP","Bayes","Bayes")
@ -152,5 +198,8 @@ def generatePatterns():
writeTests(configf32)
writeTests(configf16)
writeBenchmark(configf32)
writeBenchmark(configf16)
if __name__ == '__main__':
generatePatterns()

@ -0,0 +1,38 @@
H
18
// 0
0x0000
// 0
0x0000
// 12
0x000C
// 76
0x004C
// 24
0x0018
// 202
0x00CA
// 36
0x0024
// 303
0x012F
// 50
0x0032
// 391
0x0187
// 64
0x0040
// 537
0x0219
// 78
0x004E
// 654
0x028E
// 98
0x0062
// 778
0x030A
// 118
0x0076
// 984
0x03D8

@ -0,0 +1,278 @@
H
138
// -0.040186
0xa925
// 1.073982
0x3c4c
// 0.028277
0x273d
// 0.011638
0x21f5
// 0.028431
0x2747
// 0.025892
0x26a1
// 0.019511
0x24ff
// 0.010574
0x216a
// -0.000066
0x8455
// 0.046097
0x29e6
// 0.016035
0x241b
// -0.053561
0xaadb
// 0.013593
0x22f6
// 0.021897
0x259b
// 1.003003
0x3c03
// 0.038005
0x28dd
// -0.023690
0xa611
// -0.011551
0xa1ea
// 0.025625
0x268f
// 0.012535
0x226b
// 0.024917
0x2661
// -0.011525
0xa1e7
// -0.073949
0xacbc
// 0.022863
0x25da
// -0.048628
0xaa39
// 0.969280
0x3bc1
// -0.051026
0xaa88
// 0.049948
0x2a65
// -0.001735
0x971b
// 0.028726
0x275b
// -0.024842
0xa65c
// -0.013571
0xa2f3
// -0.007444
0x9f9f
// 0.012261
0x2247
// -0.006992
0x9f29
// -0.018144
0xa4a5
// 0.063726
0x2c14
// 0.014435
0x2364
// 1.070055
0x3c48
// 0.011378
0x21d3
// 0.020624
0x2548
// 0.012175
0x223c
// -0.060880
0xabcb
// -0.003673
0x9b86
// 0.066080
0x2c3b
// -0.030483
0xa7ce
// -0.026682
0xa6d5
// -0.041411
0xa94d
// 0.030163
0x27b9
// -0.024941
0xa663
// -0.006896
0x9f10
// -0.024445
0xa642
// 0.018958
0x24da
// -0.014716
0xa389
// 1.017171
0x3c12
// -0.024220
0xa633
// -0.043287
0xa98a
// 0.029118
0x2774
// -0.008586
0xa065
// 0.029317
0x2781
// -0.000696
0x91b4
// 0.007286
0x1f76
// -0.044731
0xa9ba
// -0.024640
0xa64f
// -0.010476
0xa15d
// 0.005055
0x1d2d
// 0.038301
0x28e7
// 0.931977
0x3b75
// -0.028171
0xa736
// 0.037370
0x28c9
// -0.041713
0xa957
// -0.039430
0xa90c
// 0.034133
0x285e
// -0.059803
0xaba8
// -0.008422
0xa050
// 0.035178
0x2881
// 0.048290
0x2a2e
// -0.018230
0xa4ab
// 0.004761
0x1ce0
// -0.034561
0xa86c
// 0.977494
0x3bd2
// -0.056634
0xab40
// 0.020863
0x2557
// 0.039257
0x2906
// 0.034689
0x2871
// 0.007272
0x1f72
// 0.072741
0x2ca8
// 0.011958
0x221f
// -0.004184
0x9c49
// 0.080404
0x2d25
// -0.093746
0xae00
// 0.046717
0x29fb
// 0.034230
0x2862
// 0.037576
0x28cf
// -0.030905
0xa7e9
// -0.002138
0x9861
// -0.014129
0xa33c
// 0.014546
0x2373
// 0.006195
0x1e58
// 0.979450
0x3bd6
// 0.008912
0x2090
// -0.036559
0xa8ae
// -0.027870
0xa722
// -0.017747
0xa48b
// 0.050483
0x2a76
// 0.073055
0x2cad
// 0.046158
0x29e9
// -0.009757
0xa0ff
// 0.085861
0x2d7f
// -0.019322
0xa4f2
// -0.020828
0xa555
// -0.055185
0xab10
// -0.005840
0x9dfb
// 0.007642
0x1fd3
// -0.012141
0xa237
// -0.005708
0x9dd8
// -0.073105
0xacae
// 0.004961
0x1d14
// -0.025444
0xa684
// 0.038032
0x28de
// -0.023309
0xa5f8
// 0.984341
0x3be0
// 0.057406
0x2b59
// 0.038917
0x28fb
// -0.034246
0xa862
// -0.030406
0xa7c9
// -0.015718
0xa406
// -0.025802
0xa69b
// 0.081464
0x2d37
// 0.026505
0x26c9
// 0.006918
0x1f16
// 0.029659
0x2798
// 0.091538
0x2ddc
// 0.065798
0x2c36
// 0.016095
0x241f
// 0.019768
0x250f
// 0.023790
0x2617
// -0.034357
0xa866

File diff suppressed because it is too large Load Diff

@ -0,0 +1,20 @@
H
9
// 1
0x0001
// 2
0x0002
// 1
0x0001
// 2
0x0002
// 4
0x0004
// 3
0x0003
// 2
0x0002
// 1
0x0001
// 3
0x0003

@ -0,0 +1,25 @@
H
36
// -209.584253
0xda8d
// 15.746762
0x4be0
// -254.107146
0xdbf1
// -157.088915
0xd8e9
// -92.588131
0xd5c9
// 15.834292
0x4beb
// -127.374179
0xd7f6
// -242.993175
0xdb98
// -2791.670271
0xe974
// -242.605961
0xdb95
// 17.386646
0x4c59
// -5143447946.019080

@ -0,0 +1,38 @@
H
18
// 0
0x0000
// 0
0x0000
// 12
0x000C
// 76
0x004C
// 24
0x0018
// 202
0x00CA
// 36
0x0024
// 303
0x012F
// 50
0x0032
// 391
0x0187
// 64
0x0040
// 537
0x0219
// 78
0x004E
// 654
0x028E
// 98
0x0062
// 778
0x030A
// 118
0x0076
// 984
0x03D8

@ -0,0 +1,278 @@
W
138
// 0.993859
0x3f7e6d8d
// 0.003266
0x3b560992
// 0.035641
0x3d11fcc8
// -0.090419
0xbdb92d74
// 0.043912
0x3d33dd75
// -0.042546
0xbd2e44f2
// 0.070849
0x3d911948
// -0.065232
0xbd859867
// 0.007983
0x3c02cab8
// -0.001672
0xbadb2eff
// -0.028464
0xbce92cc8
// 0.010911
0x3c32c31a
// -0.092912
0xbdbe48c5
// 0.035668
0x3d121905
// -0.000463
0xb9f2ce6a
// 0.946335
0x3f72430a
// 0.007799
0x3bff8e6c
// -0.038055
0xbd1bdf91
// -0.001537
0xbac9679b
// -0.021848
0xbcb2faf7
// -0.081510
0xbda6eeae
// 0.013917
0x3c6405b4
// -0.018004
0xbc937ce5
// -0.018478
0xbc975fdc
// 0.001077
0x3a8d3045
// -0.069425
0xbd8e2edc
// 0.978310
0x3f7a7285
// -0.015063
0xbc76ccc2
// -0.100549
0xbdcdec89
// 0.057286
0x3d6aa507
// -0.028425
0xbce8dc1e
// 0.014849
0x3c73499a
// -0.050356
0xbd4e41db
// 0.047657
0x3d433441
// 0.008310
0x3c082839
// 0.040505
0x3d25e83f
// -0.008813
0xbc106253
// 0.045229
0x3d39427e
// 1.030162
0x3f83dc5a
// 0.015668
0x3c805992
// 0.017410
0x3c8e9f6a
// 0.008313
0x3c083303
// -0.006206
0xbbcb5f18
// 0.039141
0x3d2051f2
// -0.028887
0xbceca4dd
// 0.057686
0x3d6c47e2
// 0.049255
0x3d49bff8
// -0.031344
0xbd006299
// 0.096180
0x3dc4fa04
// 0.027573
0x3ce1e1c8
// 0.912040
0x3f697b77
// -0.006232
0xbbcc361a
// 0.037752
0x3d1aa1f4
// 0.080582
0x3da50835
// -0.029815
0xbcf43f5f
// 0.039508
0x3d21d378
// 0.070669
0x3d90bb29
// -0.023232
0xbcbe5201
// -0.013015
0xbc553b5e
// 0.045539
0x3d3a8793
// 0.015317
0x3c7af242
// -0.038341
0xbd1d0bd8
// -0.001877
0xbaf5f566
// 0.033180
0x3d07e73d
// -0.009663
0xbc1e5304
// -0.082668
0xbda94df0
// 0.005600
0x3bb77c75
// 0.895062
0x3f6522c8
// 0.031259
0x3d00093a
// -0.013758
0xbc6168d0
// 0.067527
0x3d8a4b85
// 0.058772
0x3d70ba6a
// -0.003151
0xbb4e893a
// -0.029285
0xbcefe650
// 0.022418
0x3cb7a583
// 0.015898
0x3c823d8a
// -0.033489
0xbd092c45
// -0.073212
0xbd95efea
// 1.016488
0x3f821c44
// 0.053423
0x3d5ad1c4
// 0.011955
0x3c43dce2
// 0.020540
0x3ca84447
// 0.017797
0x3c91cb17
// 0.002332
0x3b18d194
// 0.022311
0x3cb6c679
// 0.029993
0x3cf5b3fc
// -0.024722
0xbcca85ac
// -0.040891
0xbd277dbc
// -0.008009
0xbc0339b6
// 0.033292
0x3d085d91
// 0.021992
0x3cb42852
// -0.017457
0xbc8f0267
// 0.044975
0x3d383751
// 0.038378
0x3d1d3291
// -0.016065
0xbc839aba
// 0.032482
0x3d050c11
// 0.052955
0x3d58e783
// 0.040116
0x3d2450a0
// 0.016201
0x3c84b8be
// -0.025682
0xbcd2621d
// 1.011317
0x3f8172d6
// 0.007611
0x3bf9678a
// 0.036635
0x3d160ed5
// 0.041180
0x3d28acc2
// 0.097578
0x3dc7d6e9
// -0.028906
0xbceccb92
// -0.126198
0xbe013a2a
// -0.115196
0xbdebebf8
// 0.066253
0x3d87afca
// -0.000212
0xb95ea1a9
// -0.109596
0xbde0739e
// -0.029895
0xbcf4e6bc
// -0.043222
0xbd310982
// 0.067351
0x3d89ef58
// 0.015362
0x3c7bb139
// -0.032368
0xbd04941e
// -0.046210
0xbd3d46b7
// 0.078026
0x3d9fcc50
// -0.019191
0xbc9d3608
// 0.993031
0x3f7e374a
// -0.028901
0xbcecc174
// -0.034949
0xbd0f2637
// 0.002125
0x3b0b3e33
// 0.031756
0x3d02122b
// -0.075827
0xbd9b4b43
// -0.053971
0xbd5d10ca
// -0.014613
0xbc6f6bc9
// -0.052876
0xbd589502
// 0.023186
0x3cbdf07b
// 0.000434
0x39e3664d
// -0.028223
0xbce73343
// -0.021082
0xbcacb466
// -0.001837
0xbaf0bf56
// -0.005527
0xbbb51ea2
// -0.044851
0xbd37b529
// -0.069432
0xbd8e322d
// 0.045976
0x3d3c5144
// 0.004058
0x3b84f778

File diff suppressed because it is too large Load Diff

@ -0,0 +1,20 @@
H
9
// 0
0x0000
// 3
0x0003
// 2
0x0002
// 2
0x0002
// 0
0x0000
// 3
0x0003
// 0
0x0000
// 2
0x0002
// 1
0x0001

@ -0,0 +1,74 @@
W
36
// -170.307298
0xc32a4eab
// -267.771059
0xc385e2b2
// 16.290787
0x41825388
// -234.610901
0xc36a9c64
// -140.670377
0xc30cab9e
// -287.238709
0xc38f9e8e
// 8.717363
0x410b7a52
// -249.629949
0xc379a144
// -169.858412
0xc329dbc1
// 16.384652
0x418313c5
// -3171.146048
0xc5463256
// -58.258899
0xc269091d
// -135.793466
0xc307cb21
// 18.502745
0x4194059f
// -151.200604
0xc317335b
// -219.228024
0xc35b3a60
// -129.752365
0xc301c09b
// 18.600433
0x4194cdb0
// -2255.153596
0xc50cf275
// -138.331120
0xc30a54c4
// -203.517142
0xc34b8463
// -133.665973
0xc305aa7d
// 19.542878
0x419c57d1
// -214.140087
0xc35623dd
// -463.633133
0xc3e7d10b
// -141.046419
0xc30d0be2
// 27.619449
0x41dcf4a2
// -336.431591
0xc3a8373e
// -328.807438
0xc3a4675a
// 19.551493
0x419c6975
// -143.817546
0xc30fd14b
// -580.701057
0xc4112cde
// 21.032212
0x41a841f9
// -123.852127
0xc2f7b44a
// -300.631048
0xc39650c6
// -188.210839
0xc33c35fa

@ -0,0 +1,79 @@
#include "BayesF32.h"
#include <stdio.h>
#include "Error.h"
#include "Test.h"
void BayesF32::test_gaussian_naive_bayes_predict_f32()
{
int16_t p;
p = arm_gaussian_naive_bayes_predict_f32(&bayes,
inp,
bufp);
}
void BayesF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
{
std::vector<Testing::param_t>::iterator it = paramsArgs.begin();
this->vecDim = *it++;
this->classNb = *it++;
switch(id)
{
case BayesF32::TEST_GAUSSIAN_NAIVE_BAYES_PREDICT_F32_1:
{
int nbp,nbi;
input.reload(BayesF32::INPUTS2_F32_ID,mgr);
params.reload(BayesF32::PARAMS2_F32_ID,mgr);
dims.reload(BayesF32::DIMS2_S16_ID,mgr);
int16_t *dimsp=dims.ptr();
nbi = dimsp[2*this->nb];
nbp = dimsp[2*this->nb + 1];
const float32_t *paramsp = params.ptr() + nbp;
this->theta=paramsp ;
this->sigma=paramsp + (this->classNb * this->vecDim);
this->classPrior=paramsp + 2*(this->classNb * this->vecDim);
this->epsilon=paramsp[this->classNb + 2*(this->classNb * this->vecDim)];
//printf("%f %f %f\n",this->theta[0],this->sigma[0],this->classPrior[0]);
// Reference patterns are not loaded when we are in dump mode
predicts.reload(BayesF32::PREDICTS2_S16_ID,mgr);
outputProbas.create(this->classNb,BayesF32::OUT_PROBA_F32_ID,mgr);
bayes.vectorDimension=this->vecDim;
bayes.numberOfClasses=this->classNb;
bayes.theta=this->theta;
bayes.sigma=this->sigma;
bayes.classPriors=this->classPrior;
bayes.epsilon=this->epsilon;
this->inp = input.ptr() + nbi;
this->bufp = outputProbas.ptr();
}
break;
}
}
void BayesF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
{
(void)id;
this->nb++;
}

@ -747,6 +747,41 @@ group Root {
}
}
group Bayes{
class = Bayes
folder = Bayes
suite Bayes F32 {
class = BayesF32
folder = BayesF32
ParamList {
VECDIM,NBCLASSES
Summary VECDIM,NBCLASSES
Names "Vector dimension","Number of classes"
Formula "VECDIM*NBCLASSES"
}
Pattern DIMS2_S16_ID : DimsBench2_s16.txt
Pattern INPUTS2_F32_ID : Inputs2_f32.txt
Pattern PARAMS2_F32_ID : Params2_f32.txt
Pattern PREDICTS2_S16_ID : Predicts2_s16.txt
Output OUT_PROBA_F32_ID : Probas
Output OUT_PREDICT_S16_ID : Predicts
// Must be consisten with the Python script
Params PARAM1_ID = {
VECDIM = [12,14,20]
NBCLASSES = [3,5,4]
}
Functions {
arm_gaussian_naive_bayes_predict_f32:test_gaussian_naive_bayes_predict_f32
} -> PARAM1_ID
}
}
group Barycenter {
class = Barycenter

Loading…
Cancel
Save