KernelDensityEstimation
public class KernelDensityEstimation
Kernel density estimation using a Gaussian kernel and automatic bandwidth selection via Silverman’s rule-of-thumb.
-
Bandwidth used in evaluate() method
Declaration
Swift
public let bandwidth: Double
-
Creates a new instance from an array of Doubles
Declaration
Swift
public init?(_ data: [Double], bandwidth: Double? = nil)
Parameters
data
Array of Doubles. If automatic bandwidth selection is required, this arry needs to have no fewer than two values.
bandwidth
Either specify the size of the bandwidth (the standard deviation of the normal kernel), or specify
nil
to automatically select the bandwidth using Silverman’s rule-of-thumb. Note that this rule is only appropriate if the data comes from a distribution not too dissimilar to a normal distribution. In other words, you will be better served by manually specifying the bandwidth if the source distribution is multi-modal. See the Kernel Density Estimation Wikipedia article.Return Value
A new instance of KernelDensityEstimation, or
nil
ifdata
contained fewer than two values and bandwidth was set tonil
. -
Evaluates the Kernel Density Estimator at the given value,
x
.Declaration
Swift
public func evaluate(_ x: Double) -> Double
Parameters
x
The point at which the KDE should be evaluated.
Return Value
The density at the specified point,
x
.