Currently, if the user calls cdf on a single value, the method always returns 1. This is because cdf is currently implemented as:
return np.cumsum(self.pdf(x))/np.sum(self.pdf(x))
but the cumulative sum should always be from some far left location up to x and the sum should be across the entire pdf, not just the x value. This is properly implemented in the cdfplot method though where you define neg_x and pos_x:
neg_x = np.linspace(self.value-(num_sigma*self.minus),self.value,discretization)
pos_x = np.linspace(self.value,self.value+(num_sigma*self.minus),discretization)
def cdf(self,x,num_sigma=5,discretization=100):
neg_x = np.linspace(self.value-(num_sigma*self.minus),self.value,discretization)
pos_x = np.linspace(self.value,self.value+(num_sigma*self.plus),discretization)
x_arr = np.array(list(neg_x)+list(pos_x))
if hasattr(x,'__len__'):
ret = np.zeros(shape=len(x))
for i in range(len(x)):
ret[i] = np.sum( self.pdf( x_arr[ : np.argmin(x[i] >= x_arr)] ) ) / np.sum(self.pdf(x_arr) )
else:
ret = np.sum( self.pdf( x_arr[ : np.argmin(x >= x_arr)] ) ) / np.sum(self.pdf(x_arr) )
return ret
(The if hasattr() statement is how I typically handle methods that have to compare either a single value or an array of values to some array, idk if it's the best way and would love any improvement you may know of).