Skip to content
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

Error in documentation. Multidimensional grid_points for evaluationg FFTKDE needs to be numpy array. #179

Open
teakfi opened this issue Jan 28, 2025 · 1 comment

Comments

@teakfi
Copy link

teakfi commented Jan 28, 2025

import seaborn as sns
from KDEpy import FFTKDE
import numpy as np

penguins = sns.load_dataset("penguins")
chinstrap = penguins[penguins["species"]=="Chinstrap"].iloc[:,2:6].dropna()

fit=FFTKDE().fit(chinstrap.to_numpy())

lengthspace = np.linspace(25,65,5)
depthspace = np.linspace(10,25,5)
flipperspace = np.linspace(150,250,5)
massspace = np.linspace(2000,8000,5)

def gridcreator1(space1,space2,space3,space4):
    grid = []
    for s1 in space1:
        for s2 in space2:
            for s3 in space3:
                for s4 in space4:
                    row = np.array([s1,s2,s3,s4])
                    grid.append(row)
    return grid

testgrid = gridcreator1(lengthspace,depthspace,flipperspace,massspace)

result = fit.evaluate(testgrid)

produces error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], line 27
     23     return grid
     25 testgrid = gridcreator1(lengthspace,depthspace,flipperspace,massspace)
---> 27 result = fit.evaluate(testgrid)

File E:\anaconda3\envs\analysis\Lib\site-packages\KDEpy\FFTKDE.py:145, in FFTKDE.evaluate(self, grid_points)
    143 # Extra verification for FFTKDE (checking the sorting property)
    144 if not grid_is_sorted(self.grid_points):
--> 145     raise ValueError("The grid must be sorted.")
    147 if isinstance(self.bw, numbers.Number) and self.bw > 0:
    148     bw = self.bw

ValueError: The grid must be sorted.

casting testgrid as np array fixes this

result = fit.evaluate(np.asarray(testgrid))

works as intended (I hope).

@tommyod
Copy link
Owner

tommyod commented Jan 28, 2025

Thanks for reporting the issue. A PR on this is welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants