shredding
shredding

Reputation: 5591

How to find area under exponential curve (and the curve) from random distribution in python?

Given the following algorithm:

import numpy as np
from matplotlib import pyplot as plt

exponent = 2
sample = np.random.random_sample(1000000)
distribution = sample ** exponent

plt.hist(distribution)
plt.show()

Curve

How can I find / interpolate the exponential curve that describes the given distribution from the graphic the best for any exponent where the sample is always between 0 and 1 - and how can I find the area under that to-be-found-curve? I mean the curve for a sample size that equals infinity.

Upvotes: 1

Views: 820

Answers (1)

Serenity
Serenity

Reputation: 36635

Define type of distribution for samples of a random distribution is not easy task. You have to check some validation tests to define distribution with desirable statistical confidence.

Scipy has test for normal distribution: http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.mstats.normaltest.html

However, if you know the function (or just set of x,y points) you can calculate area under it using numerical methods.

For example, trapezoidal method: http://docs.scipy.org/doc/numpy/reference/generated/numpy.trapz.html or Simpson's rule: http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simps.html#scipy.integrate.simps

from scipy.integrate import simps
from numpy import trapz

print trapz([1,2,3], x=[4,6,8])
print simps([1,2,3], x=[4,6,8])

Output:

8.0 8.0

Upvotes: 3

Related Questions