[closes #187] pdf methods for some values like expectation and plotting ready
This commit is contained in:
		
							parent
							
								
									e6b5848f36
								
							
						
					
					
						commit
						9f7f00314a
					
				| @ -157,7 +157,7 @@ class ProbabilityDensityFunction(object): | |||||||
|         return ProbabilityDensityFunction(x0, incr, npts, pdf) |         return ProbabilityDensityFunction(x0, incr, npts, pdf) | ||||||
| 
 | 
 | ||||||
|     def __nonzero__(self): |     def __nonzero__(self): | ||||||
|         return True |         return bool(np.round(self.prob_gt_val(self.axis[0]), 4) == 1.) | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def data(self): |     def data(self): | ||||||
| @ -259,6 +259,18 @@ class ProbabilityDensityFunction(object): | |||||||
|             return None |             return None | ||||||
|         return self.data[find_nearest(self.axis, value)] * self.incr |         return self.data[find_nearest(self.axis, value)] * self.incr | ||||||
| 
 | 
 | ||||||
|  |     def plot(self): | ||||||
|  |         import matplotlib.pyplot as plt | ||||||
|  | 
 | ||||||
|  |         plt.plot(self.axis, self.data) | ||||||
|  |         plt.xlabel('x') | ||||||
|  |         plt.ylabel('f(x)') | ||||||
|  |         if self: | ||||||
|  |             plt.title('Probability density function') | ||||||
|  |         else: | ||||||
|  |             plt.title('Function not suitable as probability density function') | ||||||
|  |         plt.show() | ||||||
|  | 
 | ||||||
|     def commonlimits(self, incr, other, max_npts=1e5): |     def commonlimits(self, incr, other, max_npts=1e5): | ||||||
|         ''' |         ''' | ||||||
|         Takes an increment incr and two left and two right limits and returns |         Takes an increment incr and two left and two right limits and returns | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user