]> SALOME platform Git repositories - modules/yacs.git/blob - src/pmml/Test/samples/unittest_ref_ann_model.cpp
Salome HOME
updated copyright message
[modules/yacs.git] / src / pmml / Test / samples / unittest_ref_ann_model.cpp
1 #define ActivationFunction(sum) ( 1.0 / ( 1.0 + exp( -1.0 * sum )) )
2 void myTestFunc(double *param, double *res)
3 {
4   ////////////////////////////// 
5   //
6   // File used by unit test
7   // PMMLBasicsTest1::testExportNeuralNetworkCpp
8   //
9   ////////////////////////////// 
10
11   int nInput   = 8;
12   int nOutput   = 1;
13   int nHidden  = 1;
14   const int nNeurones  = 10;
15   double myTestFunc_act[nNeurones];
16
17   // --- Preprocessing of the inputs and outputs
18   double myTestFunc_minInput[] = {
19   0.099999, 25048.9, 89334.9, 89.5523, 1050, 
20   760.001, 1400.02, 10950, 
21   };
22   double myTestFunc_minOutput[] = {
23   77.8117,   };
24   double myTestFunc_maxInput[] = {
25   0.028899, 14419.8, 15180.8, 15.2866, 34.6793, 
26   34.6718, 161.826, 632.913, 
27   };
28   double myTestFunc_maxOutput[] = {
29   45.7061,   };
30
31   // --- Values of the weights
32   double myTestFunc_valW[] = {
33   -1.74548, 6.96551, -1.26357, 0.753663, 0.00165366, 
34   0.004725, 0.00996979, 0.178798, -0.180981, -0.173569, 
35   0.0855967, 
36   };
37   // --- Constants
38   int indNeurone = 0;
39   int CrtW;
40   double sum;
41
42   // --- Input Layers
43   for(int i = 0; i < nInput; i++) {
44      myTestFunc_act[indNeurone++] = ( param[i] - myTestFunc_minInput[i] ) / myTestFunc_maxInput[i];
45   }
46
47   // --- Hidden Layers
48   for (int member = 0; member < nHidden; member++) {
49      int CrtW = member * ( nInput + 2) + 2;
50      sum = myTestFunc_valW[CrtW++];
51      for (int source = 0; source < nInput; source++) {
52          sum += myTestFunc_act[source] * myTestFunc_valW[CrtW++];
53        }
54        myTestFunc_act[indNeurone++] = ActivationFunction(sum);
55   }
56
57   // --- Output
58   for (int member = 0; member < nOutput; member++) {
59     sum = myTestFunc_valW[0];
60     for (int source = 0; source < nHidden; source++) {
61       CrtW = source * ( nInput + 2) + 1;
62       sum += myTestFunc_act[nInput+source] * myTestFunc_valW[CrtW];
63     }
64     myTestFunc_act[indNeurone++] = sum;
65     res[member] = myTestFunc_minOutput[member] + myTestFunc_maxOutput[member] * sum;
66   }
67 }