From 4606f8480990e0660b019449317d5356f68340d3 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Thu, 3 Mar 2016 15:14:17 +0100 Subject: [PATCH] [new] implementing comparison methods into pdf class --- pylot/core/util/pdf.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/pylot/core/util/pdf.py b/pylot/core/util/pdf.py index e070ccc3..aaa70194 100644 --- a/pylot/core/util/pdf.py +++ b/pylot/core/util/pdf.py @@ -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