Created
May 28, 2019 00:57
-
-
Save jdthorpe/240cd669c8c6909d32793883ed9842b2 to your computer and use it in GitHub Desktop.
Kernel densties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function kernelDensityEstimator(kernel:{(x:number):number}, X:number[]) { | |
return function(V:number[]) { | |
return X.map(function(x) { | |
return [x, d3.d3.mean(V, function(v:number) { return kernel(x - v); })]; | |
}); | |
}; | |
} | |
function kernelEpanechnikov(k:number): {(x:number):number}{ | |
return function(v:number):number { | |
return Math.abs(v /= k) <= 1 ? 0.75 * (1 - v * v) / k : 0; | |
}; | |
} | |
function cumulativeKernelEpanechnikov(k:number): {(x:number):number} { | |
return function(v:number):number { | |
return Math.abs(v /= k) <= 1 ? 0.5 * (1 + v * v * v) / k : (v < 0 ? 0 : 1); | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment