finding the extremum of density in a sample

asked 2016-06-10 06:26:24 -0500

fagui gravatar image

updated 2017-01-08 05:25:05 -0500

FrédéricC gravatar image

I am facing the following problem: I have (large) sample of unevenly distributed points $(X_i,Y_i)$ in a 2D space. I would like to determine the local extremas of the density of the distribution.

I have tried with the function KernelDensity in sklearn.

Does the function KernelDensity allow to estimate the density of the sample in a point outside the sample ?

if yes, i cannot find the right syntax ?

Here is an example:

import numpy as np
import pandas as pd
A=pd.DataFrame(np.vstack((np.random.multivariate_normal(mean0, cov0, 5000),np.random.multivariate_normal(mean1, cov1, 5000))))

from sklearn.neighbors import KernelDensity
kde = KernelDensity(bandwidth=0.04, metric='euclidean',
                        kernel='gaussian', algorithm='ball_tree')

If I make this query


i get a negative number, clearly not a density !!


I don't know if its the right approach. I would like then use that function to use an optimizer to get local extremas. (which library/function would you recommend ?)

is there some easy way to do that in Sagemath ?

thank you very much for your help

edit retag flag offensive close merge delete