# Gaussian kernel density weight question (in Python)

#### dreamerBoy

##### New Member
Hi, I'm trying to decipher some code ...

class Gaussian(BaseKernel):

def _compute_weights(self):
if not self.fix_boundary:
return(1.)

weights = np.zeros(self.data.shape)
for i,d in enumerate(self.data):
weights = 2./(erf((1-d)/(np.sqrt(2)*self.bw)) + erf(d/(np.sqrt(2)*self.bw)))

return(weights[:,None])

def __call__(self, x_test):
distances = x_test[None,:] - self.data[:,None]
pdfs = np.exp(-0.5* np.power(distances/self.bw, 2))/(2.5066282746310002 * self.bw)

# reweigh to compensate for boundaries
pdfs *= self.weights

return(pdfs)

I do not understand what is going on here in compute_weights. I believe the data may be restricted to values between 0 and 1 (or else you are trying to combine a numerical literal with a distance with arbitrary scale in (1 - d) ) - which would make it a truncated normal situation. On the other hand, it could be related to boundary correction (reflection method?). It's bound to be something simple but have read all I can and done the research but need a hint as to what's going on. Any thoughts appreciated. Thank you.

#### dreamerBoy

##### New Member
Never mind ... figured it out. It's simple normalization of Gaussian function of (x_i - x) where x is restricted to values between 0 and 1.