2

I'm trying to split a gaussian shaped curve, to K equal-volume segments, with Python for signal-filtering purposes.

I'm seeking for pseudo-code, general idea or a library that performs it. Any help will be much appreciated.

Thanks!

For example in the image below: for K=6. volumes s1 = s2 = ... = s6:

enter image description here

Ronen
  • 45
  • 6

1 Answers1

1

You need to determine percentiles of the distribution. You can use for this scipy.stats.norm class and its .ppf() method.

import numpy as np
import scipy.stats as sps
import matplotlib.pyplot as plt

mu = 25
sigma = 4
splits = 8

# define the normal distribution and PDF
dist = sps.norm(loc=mu, scale=sigma)
x = np.linspace(dist.ppf(.001), dist.ppf(.999))
y = dist.pdf(x)

# calculate PPFs
step = 1 / splits
quantiles = np.arange(step, 1.0 - step / 2, step)
ppfs = dist.ppf(quantiles)  # boundaries

# plot results
fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(x, y, color='k')
for i, ppf in enumerate(ppfs):
    ax.axvline(ppf, color=f'C{i}', label=f'{quantiles[i]:.3f}: {ppf:.1f}')
ax.legend()
plt.show()

enter image description here This is based on this answer

dankal444
  • 3,172
  • 1
  • 23
  • 35