@@ -33,86 +33,85 @@ namespace o2::analysis
3333 std::vector<float > yScaled, yOutRescaled;
3434 // private :
3535 void setMinMaxScaling (std::vector<float >& yOut, std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
36- { yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
37- for (size_t j = 0 ; j < yIn.size (); ++j)
38- { // loop for over the features
39- // MinMax scaling of the input features
40- LOG (debug)<<" --------------> MinMax scaling Debug \t " <<scaleMin.at (j)<<" \t " <<scaleMax.at (j);
41- yOut.push_back ((yIn.at (j) - scaleMin.at (j))/(scaleMax.at (j)- scaleMin.at (j)));
42- LOG (debug)<<" Feature = " <<j<<" ----> input = " <<yIn.at (j)<<" scaled feature = " << yOut.at (j);
43- }
44- }
36+ { yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
37+ for (size_t j = 0 ; j < yIn.size (); ++j)
38+ { // loop for over the features
39+ // MinMax scaling of the input features
40+ LOG (debug)<<" --------------> MinMax scaling Debug \t " <<scaleMin.at (j)<<" \t " <<scaleMax.at (j);
41+ yOut.push_back ((yIn.at (j) - scaleMin.at (j))/(scaleMax.at (j)- scaleMin.at (j)));
42+ LOG (debug)<<" Feature = " <<j<<" ----> input = " <<yIn.at (j)<<" scaled feature = " << yOut.at (j);
43+ }
44+ }
4545 // ---- External preprocessing scaling
4646 void setScaling (bool scaleFlag, int scaleType, /* input features of a candidate */ std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
4747 { // it takes the bool flag and scaling parameters configurables in taskXic
4848 yScaled.clear ();
49- if ( scaleFlag == false ){
50- LOG (debug)<<" No external preprocessing transformation will be applied" ;
49+ if ( scaleFlag == false ){
50+ LOG (debug)<<" No external preprocessing transformation will be applied" ;
5151 yScaled.assign (yIn.begin (), yIn.end ());
5252 } else {
5353 if (scaleType == 1 ){
54- LOG (debug)<<" MinMax scaling will be applied" ;
54+ LOG (debug)<<" MinMax scaling will be applied" ;
5555 setMinMaxScaling (yScaled, yIn, scaleMin, scaleMax);
5656 } // ... with scaleType > 1 we could add other preprocessing trasformations
5757 }
5858 }
59- std::vector<float > getPreprocessedFeatures (){
60- for (size_t j = 0 ; j < yScaled.size (); ++j) LOG (debug)<<" Global scaled feature = " << yScaled.at (j);
61- return yScaled;
59+ std::vector<float > getPreprocessedFeatures (){
60+ for (size_t j = 0 ; j < yScaled.size (); ++j) LOG (debug)<<" Global scaled feature = " << yScaled.at (j);
61+ return yScaled;
6262 }
6363 // Reverse preprocessing - output postprocessing
6464 void unsetMinMaxScaling (std::vector<float >& yOut, std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
6565 { yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
6666 for (size_t j = 0 ; j < yIn.size (); ++j)
67- { // loop for over the features
67+ { // loop for over the features
6868 // MinMax scaling of the input features
6969 LOG (debug)<<" --------------> MinMax unscaling Debug \t " <<scaleMin.at (j)<<" \t " <<scaleMax.at (j);
7070 yOut.push_back (yIn.at (j)*(scaleMax.at (j)- scaleMin.at (j))+ scaleMin.at (j));
7171 LOG (debug)<<" Unscaling output = " <<j<<" ----> input = " <<yIn.at (j)<<" rescaled output = " << yOut.at (j);
7272 }
73- }
73+ }
7474
7575 void unsetScaling (bool scaleFlag, int scaleType, /* AE output*/ std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
7676 { // it takes the bool flag and scaling parameters configurables in taskXic
7777 yOutRescaled.clear ();
78- if ( scaleFlag == false ){
79- LOG (debug)<<" No external preprocessing transformation will be applied" ;
78+ if ( scaleFlag == false ){
79+ LOG (debug)<<" No external preprocessing transformation will be applied" ;
8080 yOutRescaled.assign (yIn.begin (), yIn.end ());
8181 } else {
8282 if (scaleType == 1 ){
83- LOG (debug)<<" MinMax unscaling will be applied" ;
83+ LOG (debug)<<" MinMax unscaling will be applied" ;
8484 unsetMinMaxScaling (yOutRescaled, yIn, scaleMin, scaleMax);
85- }// ... with scaleType > 1 we could add other preprocessing trasformations
85+ } // ... with scaleType > 1 we could add other preprocessing trasformations
8686 }
8787 }
88-
89- std::vector<float > getPostprocessedOutput (){
90- for (size_t j = 0 ; j < yOutRescaled.size (); ++j) LOG (debug)<<" Global rescaled AE output = " << yOutRescaled.at (j);
91- return yOutRescaled;
92- }
88+
89+ std::vector<float > getPostprocessedOutput (){
90+ for (size_t j = 0 ; j < yOutRescaled.size (); ++j) LOG (debug)<<" Global rescaled AE output = " << yOutRescaled.at (j);
91+ return yOutRescaled;
92+ }
9393 // ---- MSE function
9494 float getMse (std::vector<float > yTrue, std::vector<float > yPred){
9595 LOG (debug)<<" Inside getMse sizes " <<yTrue.size ()<<" \t " <<yPred.size ();
9696 float mse= 0 .0f ;
97- float sum = 0 .0f ;
97+ float sum = 0 .0f ;
9898 for (size_t j = 0 ; j < yTrue.size (); ++j) LOG (debug)<<" Local Feature = " <<j<<" ----> input = " <<yTrue.at (j)<<" scaled feature = " << yPred.at (j);
9999 std::vector<float > yTrueScaled = getPreprocessedFeatures (); // to make the input features adimensional
100- if ( yTrue.size () != yPred.size ()){
100+ if ( yTrue.size () != yPred.size ()){
101101 LOG (debug)<< " size of input vector =" <<yTrue.size ();
102102 LOG (debug)<< " size of AE output vector =" << yPred.size ();
103103 LOG (fatal) << " vectors of input and predictions don't have the same size" ;
104- } else { // MSE
105- for (size_t j = 0 ; j < yPred.size (); ++j) {
104+ } else { // MSE
105+ for (size_t j = 0 ; j < yPred.size (); ++j) {
106106 sum += std::pow (((yTrueScaled).at (j) - (yPred).at (j)), 2 ); // AE model gives adimensional predictions by design choice
107- LOG (debug)<<" getMse Local feature = " <<j<<" ----> input = " <<yTrueScaled.at (j)<<" AE prediction = " << yPred.at (j);
107+ LOG (debug)<<" getMse Local feature = " <<j<<" ----> input = " <<yTrueScaled.at (j)<<" AE prediction = " << yPred.at (j);
108108 }
109- mse = sum/yPred.size (); // MSE of a candidate
109+ mse = sum/yPred.size (); // MSE of a candidate
110110 LOG (debug)<<" Local mse " <<mse;
111111 }
112112 return mse;
113113 }
114- }; // end of the class
115-
114+ }; // end of the class
116115
117116} // namespace o2::analysis
118117#endif // PWGHF_CORE_HFAETOMSEXICTOPKPI_H_
0 commit comments