8000 Add statistics recipe for sampling from an estimated probability density distribution by rhettinger · Pull Request #117221 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Add statistics recipe for sampling from an estimated probability density distribution #117221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve docstring
  • Loading branch information
rhettinger authored Mar 26, 2024
commit e2c8d1c92affcc74d0188e2226bd73c7c6834757
4 changes: 2 additions & 2 deletions Doc/library/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ The :func:`kde()` function creates a continuous probability density
function from discrete samples. Some applications need a way to make
random selections from that distribution.

Since the estimated function is just the sum of kernels centered at each
Since the smoothed probability density function is just the sum of kernels centered at each
data point, the problem can be reduced to sampling the kernel function
and recentering the result around a randomly chosen data point. This
works for kernels that have known or accurately approximated inverse
Expand All @@ -1176,7 +1176,7 @@ cumulative distribution functions.
}

def kde_random(data, h, kernel='normal'):
'Generate random a sample from an estimated kernel density function.'
'Generate a random sample from a smoothed probability density function.'
kernel_invcdf = kernel_invcdfs[kernel]
def rand():
return choice(data) + h * kernel_invcdf(random())
Expand Down
0