Skip to content

Explore KDE for overlapping gaussians #1

@TomDonoghue

Description

@TomDonoghue

Copied over from fooof-tools/fooof#30, original post by @voytek:

Okay, the overlapping oscillations issue is really annoying. As much as I want to avoid an iterative procedure that requires more than one call to the gaussian multi-fitting function, we may need to, in some cases.

My proposed solution is to take the gaussian output from from FOOOF--which may have many noisy overlapping gaussian fits--and do kernel density estimation on that output. It looks like this on the right:

KDE from Wikipedia

This integrates those overlapping gaussians, and then we can try running FOOOF on that, again.

seaborn has some nice KDE code that only has a scipy dependency, so it doesn't change our dependencies at all.

from scipy import stats, integrate

support = np.linspace(np.min(frequency_vector), np.max(frequency_vector), np.size(frequency_vector))
bandwidth = 1.06 * x.std() * x.size ** (-1 / 2.)
kernels = []
for i in x:
    kernel = stats.norm(i, bandwidth).pdf(support)
    kernels.append(kernel)

density = np.sum(kernels, axis=0)
density /= integrate.trapz(density, support)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions