Implementing rolling average of data (using a normalised gaussian function)

Hello,

I am trying to implement in my code to have a routine for calculating the rolling average or moving weighted average using a normalised gaussian function.

The idea is as follows -

The weights are given by the chosen distribution, in this case Gaussian.
The weight would be given by evaluating a gaussian for the current bin: i.e. the weight is proportional to exp(-(x-)^2/2*sigma^2).
At each bin, I perform a loop over all neighboring bins.
The centroid of the current bin would be “”.
The “x” would be the centroid of the neighboring bin within the loop.

in the code I try it like this-

  int nbinsIp = hIntensity2D->GetXaxis()->GetNbins();
		  Double_t ReEvalIp;
		  Double_t Ygaus;
		   for(int i =0;nbinsIp+1;i++)
		    {
		      // //re-set the re-evaluated y-value for the current bin
		       ReEvalIp=0;
		       double bcx = hIntensity2D->GetXaxis()->GetBinCenter(i);
		       funcGaus->SetParameter(1,bcx);// set mean to bin center , centroid of the current bin
		       //loop over all neighboring bins
		       for (int j =0; j<i; j++)
		       	{ //evaluate the gaussian function at the neighboring bin
		       	  Ygaus = funcGaus->Eval(hIntensity2D->GetXaxis()->GetBinCenter(j));
		      	  ReEvalIp = +Ygaus;
			  

			}
		  }
  

I am not sure if I am doing it correctly. The code gets stuck forever in this loop.
Can anyone help out with the rolling average method or its implementation.

Thanks


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18
Platform: Mac OS Big Sur
Compiler:


hello,

if anyone has implemented the rolling average method, please do reach out.

thanks

Hi,

The conditions to continue the first for loop is always true. Missing a “i<” I guess.

Joa

I am trying to implement in my code to have a routine for calculating the rolling average or moving weighted average using a normalised gaussian function.

The weights are given by the chosen distribution, in this case Gaussian.
The weight would be given by evaluating a gaussian for the current bin: i.e.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.