@@ -24,21 +24,21 @@ namespace o2::analysis
2424template <typename TypeOutputScore = float >
2525class HfAeToMseXicToPKPi : public HfMlResponse <TypeOutputScore>
2626{
27- public:
27+ public:
2828 // / Default constructor
2929 HfAeToMseXicToPKPi () = default ;
3030 // / Default destructor
3131 virtual ~HfAeToMseXicToPKPi () = default ;
3232
3333 std::vector<float > yScaled, yOutRescaled;
34- // private :
34+ // private :
3535 void setMinMaxScaling (std::vector<float >& yOut, std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
36- {
37- yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
38- for (size_t j = 0 ; j < yIn.size (); ++j){ // loop for over the features
36+ {
37+ yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
38+ for (size_t j = 0 ; j < yIn.size (); ++j) { // loop for over the features
3939 // MinMax scaling of the input features
4040 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)));
41+ yOut.push_back ((yIn.at (j) - scaleMin.at (j)) / (scaleMax.at (j) - scaleMin.at (j)));
4242 LOG (debug) << " Feature = " << j << " ----> input = " << yIn.at (j) << " scaled feature = " << yOut.at (j);
4343 }
4444 }
@@ -53,73 +53,70 @@ class HfAeToMseXicToPKPi : public HfMlResponse<TypeOutputScore>
5353 if (scaleType == 1 ) {
5454 LOG (debug) << " MinMax scaling will be applied" ;
5555 setMinMaxScaling (yScaled, yIn, scaleMin, scaleMax);
56- } // ... with scaleType > 1 we could add other preprocessing trasformations
57- }
56+ } // ... with scaleType > 1 we could add other preprocessing trasformations
5857 }
59- std::vector<float > getPreprocessedFeatures ()
60- {
61- for (size_t j = 0 ; j < yScaled.size (); ++j)
62- LOG (debug) << " Global scaled feature = " << yScaled.at (j);
63- return yScaled;
58+ }
59+ std::vector<float > getPreprocessedFeatures ()
60+ {
61+ for (size_t j = 0 ; j < yScaled.size (); ++j)
62+ LOG (debug) << " Global scaled feature = " << yScaled.at (j);
63+ return yScaled;
64+ }
65+ // Reverse preprocessing - output postprocessing
66+ void unsetMinMaxScaling (std::vector<float >& yOut, std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
67+ {
68+ yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
69+ for (size_t j = 0 ; j < yIn.size (); ++j) { // loop for over the features
70+ // MinMax scaling of the input features
71+ LOG (debug) << " --------------> MinMax unscaling Debug \t " << scaleMin.at (j) << " \t " << scaleMax.at (j);
72+ yOut.push_back (yIn.at (j) * (scaleMax.at (j) - scaleMin.at (j)) + scaleMin.at (j));
73+ LOG (debug) << " Unscaling output = " << j << " ----> input = " << yIn.at (j) << " rescaled output = " << yOut.at (j);
6474 }
65- // Reverse preprocessing - output postprocessing
66- void unsetMinMaxScaling (std::vector<float >& yOut, std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
67- {
68- yOut.clear (); // initial clear to avoid multiple filling if setMinMax o setScaling are called more than once
69- for (size_t j = 0 ; j < yIn.size (); ++j){ // loop for over the features
70- // MinMax scaling of the input features
71- LOG (debug) << " --------------> MinMax unscaling Debug \t " << scaleMin.at (j) << " \t " << scaleMax.at (j);
72- yOut.push_back (yIn.at (j)*(scaleMax.at (j)- scaleMin.at (j))+ scaleMin.at (j));
73- LOG (debug) << " Unscaling output = " << j << " ----> input = " << yIn.at (j) << " rescaled output = " << yOut.at (j);
74- }
75- }
75+ }
7676
77- void unsetScaling (bool scaleFlag, int scaleType, /* AE output*/ std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
78- { // it takes the bool flag and scaling parameters configurables in taskXic
79- yOutRescaled.clear ();
80- if (scaleFlag == false ) {
81- LOG (debug) << " No external preprocessing transformation will be applied" ;
82- yOutRescaled.assign (yIn.begin (), yIn.end ());
83- } else {
84- if (scaleType == 1 ) {
85- LOG (debug) << " MinMax unscaling will be applied" ;
86- unsetMinMaxScaling (yOutRescaled, yIn, scaleMin, scaleMax);
87- } // ... with scaleType > 1 we could add other preprocessing trasformations
88- }
89- }
77+ void unsetScaling (bool scaleFlag, int scaleType, /* AE output*/ std::vector<float > yIn, std::vector<float > scaleMin, std::vector<float > scaleMax)
78+ { // it takes the bool flag and scaling parameters configurables in taskXic
79+ yOutRescaled.clear ();
80+ if (scaleFlag == false ) {
81+ LOG (debug) << " No external preprocessing transformation will be applied" ;
82+ yOutRescaled.assign (yIn.begin (), yIn.end ());
83+ } else {
84+ if (scaleType == 1 ) {
85+ LOG (debug) << " MinMax unscaling will be applied" ;
86+ unsetMinMaxScaling (yOutRescaled, yIn, scaleMin, scaleMax);
87+ } // ... with scaleType > 1 we could add other preprocessing trasformations
88+ }
89+ }
9090
91- std::vector<float > getPostprocessedOutput ()
92- {
93- for (size_t j = 0 ; j < yOutRescaled.size (); ++j)
94- LOG (debug)<<" Global rescaled AE output = " << yOutRescaled.at (j);
95- return yOutRescaled;
96- }
97- // ---- MSE function
98- float getMse (std::vector<float > yTrue, std::vector<float > yPred)
99- {
100- LOG (debug) << " Inside getMse sizes " << yTrue.size () << " \t " << yPred.size ();
101- float mse= 0 .0f ;
102- float sum = 0 .0f ;
103- for (size_t j = 0 ; j < yTrue.size (); ++j)
104- LOG (debug) << " Local Feature = " << j << " ----> input = " << yTrue.at (j) << " scaled feature = " << yPred.at (j);
105- std::vector<float > yTrueScaled = getPreprocessedFeatures (); // to make the input features adimensional
106- if (yTrue.size () != yPred.size ())
107- {
108- LOG (debug) << " size of input vector =" << yTrue.size ();
109- LOG (debug) << " size of AE output vector =" << yPred.size ();
110- LOG (fatal) << " vectors of input and predictions don't have the same size" ;
111- }
112- else
113- { // MSE
114- for (size_t j = 0 ; j < yPred.size (); ++j) {
115- sum += std::pow (((yTrueScaled).at (j) - (yPred).at (j)), 2 ); // AE model gives adimensional predictions by design choice
116- LOG (debug) << " getMse Local feature = " << j << " ----> input = " << yTrueScaled.at (j) << " AE prediction = " << yPred.at (j);
117- }
118- mse = sum/yPred.size (); // MSE of a candidate
119- LOG (debug) << " Local mse " << mse;
120- }
121- return mse;
122- }
91+ std::vector<float > getPostprocessedOutput ()
92+ {
93+ for (size_t j = 0 ; j < yOutRescaled.size (); ++j)
94+ LOG (debug) << " Global rescaled AE output = " << yOutRescaled.at (j);
95+ return yOutRescaled;
96+ }
97+ // ---- MSE function
98+ float getMse (std::vector<float > yTrue, std::vector<float > yPred)
99+ {
100+ LOG (debug) << " Inside getMse sizes " << yTrue.size () << " \t " << yPred.size ();
101+ float mse = 0 .0f ;
102+ float sum = 0 .0f ;
103+ for (size_t j = 0 ; j < yTrue.size (); ++j)
104+ LOG (debug) << " Local Feature = " << j << " ----> input = " << yTrue.at (j) << " scaled feature = " << yPred.at (j);
105+ std::vector<float > yTrueScaled = getPreprocessedFeatures (); // to make the input features adimensional
106+ if (yTrue.size () != yPred.size ()) {
107+ LOG (debug) << " size of input vector =" << yTrue.size ();
108+ LOG (debug) << " size of AE output vector =" << yPred.size ();
109+ LOG (fatal) << " vectors of input and predictions don't have the same size" ;
110+ } else { // MSE
111+ for (size_t j = 0 ; j < yPred.size (); ++j) {
112+ sum += std::pow (((yTrueScaled).at (j) - (yPred).at (j)), 2 ); // AE model gives adimensional predictions by design choice
113+ LOG (debug) << " getMse Local feature = " << j << " ----> input = " << yTrueScaled.at (j) << " AE prediction = " << yPred.at (j);
114+ }
115+ mse = sum / yPred.size (); // MSE of a candidate
116+ LOG (debug) << " Local mse " << mse;
117+ }
118+ return mse;
119+ }
123120}; // end of the class
124121
125122} // namespace o2::analysis
0 commit comments