Kernel Density Estimation
An implementation of kernel density estimation with dual-tree algorithms. Given a set of reference points and query points and a kernel function, this can estimate the density function at the location of each query point using trees.
:- use_module('path/to/.../src/methods/kde/kde.pl').
%% usage example
TrainData = [5.1,3.5,1.4, 4.9,3.0,1.4, 4.7,3.2,1.3, 4.6,3.1,1.5],
TestData = [3,2,0, 5,1,4, 0,0,4, 3,3,5, 0,5,5, 2,5,5],
kde_initAndBuildModel(1.0, 0.05, 0.0, gaussian, kd_tree, dual_tree, 0, 0.95, 100, 3.0, 0.4, TrainData, 3),
kde_evaluateWithQuery(TestData, 3, Estimation).
Available Predicates
kde_initAndBuildModel/13
Build the KDE model with the given parameters and then trains it with the given reference data.
%% predicate definition
kde_initAndBuildModel(Bandwidth, RelError, AbsError, KernelType, TreeType, Algorithm, MonteCarlo, McProb, InitialSampleSize, MCEntryCoef, MCBreakCoef, DataList, DataRows) :-
Bandwidth > 0.0,
RelError >= 0.0, RelError =< 1.0,
AbsError >= 0.0,
McProb >= 0.0, McProb < 1.0,
InitialSampleSize > 0,
MCEntryCoef >= 1,
MCBreakCoef > 0.0, MCBreakCoef =< 1.0,
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
initAndBuildModelI(Bandwidth, RelError, AbsError, KernelType, TreeType, Algorithm, MonteCarlo, McProb, InitialSampleSize, MCEntryCoef, MCBreakCoef, X, Xsize, Xrownum).
%% foreign c++ predicate definition
foreign(initAndBuildModel, c, initAndBuildModelI( +float32, +float32, +float32,
+string, +string, +string,
+integer,
+float32, +integer, +float32, +float32,
+pointer(float_array), +integer, +integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
bandwidth | +float | Bandwidth of the kernel. | 1.0 |
relError | +float | Relative error tolerance for the prediction. | 0.05 |
absError | +float | Absolute error tolerance for the prediction. | 0.0 |
kernelType | +string | Kernel to use for the prediction.(‘gaussian’, ‘epanechnikov’, ‘laplacian’, ‘spherical’, ‘triangular’). | gaussian |
treeType | +string | Tree to use for the prediction.(‘kd-tree’, ‘ball-tree’, ‘cover-tree’, ‘octree’, ‘r-tree’). | kd-tree |
algorithm | +string | Algorithm to use for the prediction.(‘dual-tree’, ‘single-tree’). | dual-tree |
monteCarlo | +integer(bool) | Whether to use Monte Carlo estimations when possible. | (0)false |
mcProb | +float | Probability of the estimation being bounded by relative error when using Monte Carlo estimations. | 0.95 |
initialSampleSize | +integer | 100 | |
mcEntryCoef | +float | Controls how much larger does the amount of node descendants has to be compared to the initial sample size in order to be a candidate for Monte Carlo estimations. | 3.0 |
mcBreakCoef | +float | Controls what fraction of the amount of node’s descendants is the limit for the sample size before it recurses. | 0.4 |
referenceSet | +matrix | Input reference dataset use for KDE. | - |
kde_evaluateWithQuery/3
Perform kernel density estimation on the given query set.
kde_initAndBuildModel/13 has to be called before.
%% predicate definition
kde_evaluateWithQuery(QueryList, QueryRows, EstimationList) :-
convert_list_to_float_array(QueryList, QueryRows, array(Xsize, Xrownum, X)),
evaluateWithQueryI(X, Xsize, Xrownum, Y, Ysize),
convert_float_array_to_list(Y, Ysize, EstimationList).
%% foreign c++ predicate definition
foreign(evaluateWithQuery, c, evaluateWithQueryI( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
querySet | +matrix | Query dataset to KDE on. | - |
estimations | -vector | Vector to store density predictions. | - |
kde_evaluateNoQuery/1
Perform kernel density estimation on the reference set.
If possible, it returns normalized estimations.
kde_initAndBuildModel/13 has to be called before.
%% predicate definition
kde_evaluateNoQuery(EstimationList) :-
evaluateNoQueryI(Y, Ysize),
convert_float_array_to_list(Y, Ysize, EstimationList).
%% foreign c++ predicate definition
foreign(evaluateNoQuery, c, evaluateNoQueryI(-pointer(float_array), -integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
estimations | -vector | Vector to store density predictions. | - |
Connected Links/Resources
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
added some of the links from the python documentation