0

So, I have a set of probabilities (z_scaled) and I'm trying to plot the PDF of the distribution as well as the CDF. Now my code is as follows:

cdf = np.cumsum(z_scaled)
pdf = np.gradient(cdf)

Now, the cdf looks like so:

CDF

And the PDF, as calculated from the CDF using the gradient function looks like so:

PDF

My question is, why is the area under the PDF as calculated from this, not equal to 1?

avd28
  • 23
  • 3
  • What is it equal to? I would hazard a guess that you've run into a floating point arithmetic problem -- http://floating-point-gui.de/ – Dunes Jun 10 '17 at 20:35
  • Its a finite value equal to around 0.004538. I dont think its running into floating point problems though – avd28 Jun 10 '17 at 23:20
  • 1
    Duplicate of https://stackoverflow.com/questions/17937979/calculating-the-derivative-of-cumulative-density-function-in-python – Severin Pappadeux Jun 11 '17 at 00:50
  • Note that `Numpy.gradient` takes an optional second argument which is the spacing between the samples. See also https://stackoverflow.com/questions/17937979 as suggested. – Robert Dodier Jun 13 '17 at 00:23

0 Answers0