jsat.distributions.multivariate
Class MetricKDE
- java.lang.Object
-
- jsat.distributions.multivariate.MultivariateDistributionSkeleton
-
- jsat.distributions.multivariate.MultivariateKDE
-
- jsat.distributions.multivariate.MetricKDE
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, MultivariateDistribution, Parameterized
public class MetricKDE extends MultivariateKDE implements Parameterized
MetricKDE is a generalization of theKernelDensityEstimatorto the multivariate case. AKernelFunctionis used to weight the contribution of each data point, and aDistanceMetricis used to effectively alter the shape of the kernel. The MetricKDE uses one bandwidth parameter, which can be estimated using a nearest neighbor approach, or tuned by hand. The bandwidth of the MetricKDE can not be estimated en the same way as the univariate case.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intDEFAULT_KWhen estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate.static KernelFunctionDEFAULT_KFWhen estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate.static doubleDEFAULT_STND_DEVWhen estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate.
-
Constructor Summary
Constructors Constructor and Description MetricKDE()Creates a new KDE object that still needs a data set to model the distribution ofMetricKDE(DistanceMetric distanceMetric)Creates a new KDE object that still needs a data set to model the distribution ofMetricKDE(DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc)Creates a new KDE object that still needs a data set to model the distribution ofMetricKDE(KernelFunction kf, DistanceMetric distanceMetric)MetricKDE(KernelFunction kf, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc)Creates a new KDE object that still needs a data set to model the distribution ofMetricKDE(KernelFunction kf, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc, int defaultK, double defaultStndDev)Creates a new KDE object that still needs a data set to model the distribution of
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description MetricKDEclone()doublegetBandwith()Returns the current bandwidth usedintgetDefaultK()Returns the default value of the k'th nearest neighbor to use when not specified.doublegetDefaultStndDev()Returns the multiple of the standard deviations that is added to the bandwidth estimateDistanceMetricgetDistanceMetric()Returns the distance metric that is used for density estimationKernelFunctiongetKernelFunction()java.util.List<? extends VecPaired<VecPaired<Vec,java.lang.Integer>,java.lang.Double>>getNearby(Vec x)Returns the list of vectors that have a non zero contribution to the density of the query point x.java.util.List<? extends VecPaired<VecPaired<Vec,java.lang.Integer>,java.lang.Double>>getNearbyRaw(Vec x)Returns the list of vectors that have a non zero contribution to the density of the query point x.doublepdf(Vec x)Returns the probability of a given vector from this distribution.java.util.List<Vec>sample(int count, java.util.Random rand)Sampling not yet supportedvoidscaleBandwidth(double scale)A caller may want to increase or decrease the bandwidth after training has been completed to get smoother model, or decrease it to observe behavior.voidsetBandwith(double bandwidth)Sets the bandwidth used to estimate the density of the underlying distribution.voidsetDefaultK(int defaultK)When estimating the bandwidth, the mean of the k'th nearest neighbors to each data point is used.voidsetDefaultStndDev(double defaultStndDev)When estimating the bandwidth, the mean of the neighbor distances is used, and a multiple of the standard deviations is added.voidsetDistanceMetric(DistanceMetric distanceMetric)Sets the distance metric that is used for density estimationvoidsetKernelFunction(KernelFunction kf)<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, boolean parallel)Sets the parameters of the distribution to attempt to fit the given list of vectors.<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, double bandwith)Sets the KDE to model the density of the given data set with the specified bandwidth<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, double bandwith, java.util.concurrent.ExecutorService threadpool)Sets the KDE to model the density of the given data set with the specified bandwidth<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, java.util.concurrent.ExecutorService threadpool)<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, int k)Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data point.<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, int k, double stndDevs)Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data data point.<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, int k, double stndDevs, java.util.concurrent.ExecutorService threadpool)Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data data point.<V extends Vec>
booleansetUsingData(java.util.List<V> dataSet, int k, java.util.concurrent.ExecutorService threadpool)Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data point.-
Methods inherited from class jsat.distributions.multivariate.MultivariateDistributionSkeleton
logPdf
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
Methods inherited from interface jsat.distributions.multivariate.MultivariateDistribution
logPdf, pdf, setUsingData, setUsingData, setUsingData, setUsingDataList
-
-
-
-
Field Detail
-
DEFAULT_K
public static final int DEFAULT_K
When estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate. The default value of this k is 3- See Also:
- Constant Field Values
-
DEFAULT_STND_DEV
public static final double DEFAULT_STND_DEV
When estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate. The default number of standard deviations from the mean to add to the bandwidth estimate is 2.0- See Also:
- Constant Field Values
-
DEFAULT_KF
public static final KernelFunction DEFAULT_KF
When estimating the bandwidth, the distances of the k'th nearest neighbors are used to perform the estimate. The weight of each neighbor is controlled by the kernel function.
-
-
Constructor Detail
-
MetricKDE
public MetricKDE()
Creates a new KDE object that still needs a data set to model the distribution of
-
MetricKDE
public MetricKDE(DistanceMetric distanceMetric)
Creates a new KDE object that still needs a data set to model the distribution of- Parameters:
distanceMetric- the distance metric to use
-
MetricKDE
public MetricKDE(DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc)
Creates a new KDE object that still needs a data set to model the distribution of- Parameters:
distanceMetric- the distance metric to usevc- a vector collection to generate vector collection from
-
MetricKDE
public MetricKDE(KernelFunction kf, DistanceMetric distanceMetric)
-
MetricKDE
public MetricKDE(KernelFunction kf, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc)
Creates a new KDE object that still needs a data set to model the distribution of- Parameters:
kf- the kernel function to usedistanceMetric- the distance metric to usevc- a factory to generate vector collection from
-
MetricKDE
public MetricKDE(KernelFunction kf, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Integer>> vc, int defaultK, double defaultStndDev)
Creates a new KDE object that still needs a data set to model the distribution of- Parameters:
kf- the kernel function to usedistanceMetric- the distance metric to usevc- a factory to generate vector collection fromdefaultK- the default neighbor to use when estimating the bandwidthdefaultStndDev- the default multiple of standard deviations to add when estimating the bandwidth
-
-
Method Detail
-
setBandwith
public void setBandwith(double bandwidth)
Sets the bandwidth used to estimate the density of the underlying distribution. Too small a bandwidth results in high variance, while too large causes high bias.- Parameters:
bandwidth- the bandwidth to use for estimation- Throws:
java.lang.ArithmeticException- if the bandwidth given is not a positive number
-
getBandwith
public double getBandwith()
Returns the current bandwidth used- Returns:
- the current bandwidth
-
setDefaultK
public void setDefaultK(int defaultK)
When estimating the bandwidth, the mean of the k'th nearest neighbors to each data point is used. This value controls the default value of k used when it is not specified.- Parameters:
defaultK-
-
getDefaultK
public int getDefaultK()
Returns the default value of the k'th nearest neighbor to use when not specified.- Returns:
- the default neighbor used to estimate the bandwidth when not specified
-
setDefaultStndDev
public void setDefaultStndDev(double defaultStndDev)
When estimating the bandwidth, the mean of the neighbor distances is used, and a multiple of the standard deviations is added. This controls the multiplier value used when the bandwidth is not specified. Zero and negative multipliers are allowed, but a negative multiplier may result in the fitting failing.- Parameters:
defaultStndDev- the multiple of the standard deviation to add the to bandwidth estimate
-
getDefaultStndDev
public double getDefaultStndDev()
Returns the multiple of the standard deviations that is added to the bandwidth estimate- Returns:
- the multiple of the standard deviations that is added to the bandwidth estimate
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
Returns the distance metric that is used for density estimation- Returns:
- the metric used
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric distanceMetric)
Sets the distance metric that is used for density estimation- Parameters:
distanceMetric- the metric to use
-
clone
public MetricKDE clone()
- Specified by:
clonein interfaceMultivariateDistribution- Specified by:
clonein classMultivariateKDE
-
getNearby
public java.util.List<? extends VecPaired<VecPaired<Vec,java.lang.Integer>,java.lang.Double>> getNearby(Vec x)
Description copied from class:MultivariateKDEReturns the list of vectors that have a non zero contribution to the density of the query point x. Each vector is paired with its integer index from the original constructing list vectors, and a double indicating its weight given the kernel function in use.- Specified by:
getNearbyin classMultivariateKDE- Parameters:
x- the query point- Returns:
- the list of near by vectors and their weights
-
getNearbyRaw
public java.util.List<? extends VecPaired<VecPaired<Vec,java.lang.Integer>,java.lang.Double>> getNearbyRaw(Vec x)
Description copied from class:MultivariateKDEReturns the list of vectors that have a non zero contribution to the density of the query point x. Each vector is paired with its integer index from the original constructing list vectors, and a double indicating its distance from the query point divided by the bandwidth of the point.- Specified by:
getNearbyRawin classMultivariateKDE- Parameters:
x- the query point- Returns:
- the list of near by vectors and their weights
-
pdf
public double pdf(Vec x)
Description copied from interface:MultivariateDistributionReturns the probability of a given vector from this distribution. By definition, the probability will always be in the range [0, 1].- Specified by:
pdfin interfaceMultivariateDistribution- Parameters:
x- the vector the get the log probability of- Returns:
- the probability
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, boolean parallel)
Description copied from interface:MultivariateDistributionSets the parameters of the distribution to attempt to fit the given list of vectors. All vectors are assumed to have the same weight.- Specified by:
setUsingDatain interfaceMultivariateDistribution- Type Parameters:
V- the vector type- Parameters:
dataSet- the list of data pointsparallel-trueif the training should be done using multiple-cores,falsefor single threaded.- Returns:
- true if the distribution was fit to the data, or false if the distribution could not be fit to the data set.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, double bandwith)
Sets the KDE to model the density of the given data set with the specified bandwidth- Parameters:
dataSet- the data set to model the density ofbandwith- the bandwidth- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, double bandwith, java.util.concurrent.ExecutorService threadpool)
Sets the KDE to model the density of the given data set with the specified bandwidth- Parameters:
dataSet- the data set to model the density ofbandwith- the bandwidththreadpool- the source of threads for parallel construction- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, int k)
Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data point.- Parameters:
dataSet- the data set to model the density ofk- the number of neighbors to use to estimate the bandwidth- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, int k, java.util.concurrent.ExecutorService threadpool)
Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data point.- Parameters:
dataSet- the data set to model the density ofk- the number of neighbors to use to estimate the bandwidththreadpool- the source of threads for computation- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, int k, double stndDevs)
Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data data point.
The bandwidth estimate is calculate as the mean of the distances of the k'th nearest neighbor plus stndDevs standard deviations added to the mean.- Parameters:
dataSet- the data set to model the density ofk- the number of neighbors to use to estimate the bandwidthstndDevs- the multiple of the standard deviation to add to the mean of the distances- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, int k, double stndDevs, java.util.concurrent.ExecutorService threadpool)
Sets the KDE to model the density of the given data set by estimating the bandwidth by using the k nearest neighbors of each data data point.
The bandwidth estimate is calculate as the mean of the distances of the k'th nearest neighbor plus stndDevs standard deviations added to the mean.- Parameters:
dataSet- the data set to model the density ofk- the number of neighbors to use to estimate the bandwidthstndDevs- the multiple of the standard deviation to add to the mean of the distancesthreadpool- the source of threads to use for computation- Returns:
- true if the model was fit, false if it could not be fit.
-
setUsingData
public <V extends Vec> boolean setUsingData(java.util.List<V> dataSet, java.util.concurrent.ExecutorService threadpool)
-
sample
public java.util.List<Vec> sample(int count, java.util.Random rand)
Sampling not yet supported- Specified by:
samplein interfaceMultivariateDistribution- Parameters:
count-rand-- Returns:
- will not return
- Throws:
java.lang.UnsupportedOperationException- not yet implemented
-
getKernelFunction
public KernelFunction getKernelFunction()
- Specified by:
getKernelFunctionin classMultivariateKDE- Returns:
- the kernel function used
-
setKernelFunction
public void setKernelFunction(KernelFunction kf)
-
scaleBandwidth
public void scaleBandwidth(double scale)
Description copied from class:MultivariateKDEA caller may want to increase or decrease the bandwidth after training has been completed to get smoother model, or decrease it to observe behavior. This method will scaled the bandwidth of each data point by the given factor- Specified by:
scaleBandwidthin classMultivariateKDE- Parameters:
scale- the value to scale the bandwidth used
-
-
DataMelt 3.0 © DataMelt by jWork.ORG