2016-11-23 57 views
1

我試圖使用fastKDE包(https://pypi.python.org/pypi/fastkde/1.0.8)來查找2D圖中某個點的KDE。但是,我想知道KDE超出數據點的限制,並且無法弄清楚如何執行此操作。python fastKDE超出數據點極限

使用上面鏈接的網站上列出的代碼;

#!python 

import numpy as np 
from fastkde import fastKDE 
import pylab as PP 

#Generate two random variables dataset (representing 100000 pairs of datapoints) 
N = 2e5 
var1 = 50*np.random.normal(size=N) + 0.1 
var2 = 0.01*np.random.normal(size=N) - 300 

#Do the self-consistent density estimate 
myPDF,axes = fastKDE.pdf(var1,var2) 

#Extract the axes from the axis list 
v1,v2 = axes 

#Plot contours of the PDF should be a set of concentric ellipsoids centered on 
#(0.1, -300) Comparitively, the y axis range should be tiny and the x axis range 
#should be large 
PP.contour(v1,v2,myPDF) 
PP.show() 

我能找到KDE的數據範圍內的任何一點,但我怎麼找到KDE的說點(0,300),而不必把它列入到VAR1和VAR2。我不想用這個數據點來計算KDE,我想知道當時的KDE。

我想我真正想要做的就是給fastKDE一個直方圖的數據,這樣我就可以自己設置座標軸。我只是不知道這是否可能?

乾杯

回答

2

我也一直在嘗試這個代碼,並遇到了同樣的問題。我所做的(代替一個好的N-D外推器)是從快速KDE返回的網格點構建一個KDTree(帶有scipy.spatial),並找到最接近我要評估的點的網格點。然後,我查找相應的pdf值(如果不是相同的零,它應該在pdf網格的邊緣附近很小),並相應地分配該值。