Package: pyfigtree
pyfigtreeA python ctypes wrapper of thefigtree libraryfor fast
Gaussian summation by V. Morariu et al.The main function for users ispyfigtree.figtree. It computes the
improved fast Gauss transformg(y) = \sum_{i=1}^N w_i \exp( -|x_i - y|^2 / h^2)for N samples{x_i}at the target point y.Kernel density estimationFor a properly normalized Gaussian kernel density estimation in 1D,
the weight isw_i = 1 / (N \sqrt{\pi h^2}),wherehis thebandwidth.  Details about the algorithm and the
parameters are given in theoriginal paper.Note that multidimensional input usually has to be transformed to
avoid distortions if the variates are of different scales.  The
fastest strategy is to scale the samples to the unit hypercube. For example in 2Dforiinrange(2):x[:,i]=(x[:,i]-x[:,i].min())/(x[:,i].max()-x[:,i].min())If that is not good enough (i.e., scales still too different), transform
intoalmost principal componentsas suggested inScott, Sain (1992),
section 3.3.ExampleSample from a unit Gaussian, and do kernel density estimation with
figtree. The weights are adjusted such that the density is normalized
correctly.fromfigtreeimportfigtreeimportnumpyasnpsamples=np.random.normal(size=1000)bandwidth=0.5weights=np.ones(len(samples))/len(samples)/np.sqrt(np.pi)/bandwidthtarget_points=np.linspace(-5,5,70)target_densities=figtree(samples,target_points,weights,bandwidth=bandwidth)frommatplotlibimportpyplotaspltplt.plot(target_points,target_densities)plt.hist(samples,histtype='stepfilled',normed=True)plt.show()Installation with pippipinstallpyfigtreeInstallation from sourceThis wrapper has been developed and tested only on linux. To use it,
first install both the figtree and the ANN library following the
instructions athttps://github.com/vmorariu/figtreeand make the
libraries available to the loader at runtime. For example,exportFIGTREEDIR=/path/to/figtreeexportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FIGTREEDIR/libexportPYTHONPATH=/path/to/pyfigtree:$PYTHONPATHThenaddpyfigtree.pyto yourPYTHON_PATH;make surenumpyis installed;test the setup by executingpython figtree.pyto run a set of unit
tests.Historical noteI wrote this wrapper around 2011. In 2014, I figured I should clean it
up and release it on github because it may be useful to others. When I
notified Vlad Morariu, the author of figtree, he told me that he had
in fact done the same so now there are twopython wrappers.What's the difference? Vlad usescythonand I usectypes; the
latter is included in a standardpythoninstallation, so I have one
less dependency and I don't need to compile anything, the only requirement
is to be able to load the figtree libraries at runtime.LicenseCopyright (c) 2014 Frederik BeaujeanFrederik.Beaujean@lmu.dePyfigtree is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2, as
published by the Free Software Foundation.This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA