tommyod/KDEpy

Anisotropic KDEs via PCA

Open

#6 opened on Nov 11, 2018

View on GitHub
 (11 comments) (1 reaction) (1 assignee)Jupyter Notebook (104 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (647 stars)
PR merge metrics
 (PR metrics pending)

Description

Currently, the bandwidth in d dimensions is bw * np.eye(d)---the covariance matrix is a multiple of the identity. As a result, the KDE works best if anisotropic data is shifted, rotatated and scaled before sent into the algorithm.

Having a routine for this built into the library would be nice.

@blasern suggested implementing anisotropic KDE. We agree that the following might work:

  • Shift data to have mean zero. Call this transformation f.
  • Apply the whitening transformation using the PCA / SVD. Call this g.
  • Fit a KDE.
  • Transform back using f^{-1}(g^{-1}(D)), make sure to scale the volume to preserve an integral of unity (determinant of the transformation).
                KDE                       
     Data  -------------> KDE estimate    
                                          
        |                  |              
  g o f |                  |   f^-1 o g^-1
        |                  |              
        v                  v              
           ------------->                 
 Transformed    KDE      KDE estimate     
    Data                                  

The above would implement very general KDEs in arbitrary dimensions.

Contributor guide