From 9f7f00314ad19706e19c191513f125d1d2eed67e Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Fri, 4 Mar 2016 14:13:44 +0100 Subject: [PATCH] [closes #187] pdf methods for some values like expectation and plotting ready --- pylot/core/util/pdf.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pylot/core/util/pdf.py b/pylot/core/util/pdf.py index 3149fc0a..c3af13e0 100644 --- a/pylot/core/util/pdf.py +++ b/pylot/core/util/pdf.py @@ -157,7 +157,7 @@ class ProbabilityDensityFunction(object): return ProbabilityDensityFunction(x0, incr, npts, pdf) def __nonzero__(self): - return True + return bool(np.round(self.prob_gt_val(self.axis[0]), 4) == 1.) @property def data(self): @@ -259,6 +259,18 @@ class ProbabilityDensityFunction(object): return None 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): ''' Takes an increment incr and two left and two right limits and returns