[new] implementing comparison methods into pdf class
This commit is contained in:
		
							parent
							
								
									18785edf68
								
							
						
					
					
						commit
						4606f84809
					
				| @ -133,15 +133,13 @@ class ProbabilityDensityFunction(object): | ||||
|             'both operands must be of type ProbabilityDensityFunction' | ||||
| 
 | ||||
|         raise NotImplementedError('implementation of resulting axis unclear - feature pending!') | ||||
|         # x0, incr, npts, pdf_self, pdf_other = self.rearrange(other) | ||||
|         # | ||||
|         # pdf = np.convolve(pdf_self, pdf_other, 'same') * incr | ||||
|         # | ||||
|         # # shift axis values for correct plotting | ||||
|         # midpoint = npts / 2 | ||||
|         # x0 = incr * midpoint | ||||
|         # | ||||
|         # return ProbabilityDensityFunction(x0, incr, npts, pdf) | ||||
|         x0, incr, npts, pdf_self, pdf_other = self.rearrange(other) | ||||
|         pdf = np.convolve(pdf_self, pdf_other, 'same') * incr | ||||
| 
 | ||||
|         # shift axis values for correct plotting | ||||
|         npts *= 2 | ||||
|         x0 *= 2 | ||||
|         return ProbabilityDensityFunction(x0, incr, npts, pdf) | ||||
| 
 | ||||
|     def __sub__(self, other): | ||||
|         assert isinstance(other, ProbabilityDensityFunction), \ | ||||
| @ -222,6 +220,25 @@ class ProbabilityDensityFunction(object): | ||||
|         # return the object | ||||
|         return ProbabilityDensityFunction(x0, incr, npts, pdf) | ||||
| 
 | ||||
|     def expectation(self): | ||||
|         ''' | ||||
|         returns the expectation value of the actual pdf object | ||||
| 
 | ||||
|         ..formula:: | ||||
|                 mu_{\Delta t} = \int\limits_{-\infty}^\infty x \cdot f(x)dx | ||||
| 
 | ||||
|         :return float: rval | ||||
|         ''' | ||||
| 
 | ||||
|         rval = 0 | ||||
|         for n, x in enumerate(self.axis): | ||||
|             rval += x * self.data[n] | ||||
|         return rval * self.incr | ||||
| 
 | ||||
|     def standard_deviation(self): | ||||
|         pass | ||||
| 
 | ||||
| 
 | ||||
|     def commonlimits(self, incr, other, max_npts=1e5): | ||||
|         ''' | ||||
|         Takes an increment incr and two left and two right limits and returns | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user