simple-statistics
Version:
38 lines (36 loc) • 1.3 kB
JavaScript
/**
* We use `ε`, epsilon, as a stopping criterion when we want to iterate
* until we're "close enough". Epsilon is a very small number: for
* simple statistics, that number is **0.0001**
*
* This is used in calculations like the binomialDistribution, in which
* the process of finding a value is [iterative](https://en.wikipedia.org/wiki/Iterative_method):
* it progresses until it is close enough.
*
* Below is an example of using epsilon in [gradient descent](https://en.wikipedia.org/wiki/Gradient_descent),
* where we're trying to find a local minimum of a function's derivative,
* given by the `fDerivative` method.
*
* @example
* // From calculation, we expect that the local minimum occurs at x=9/4
* var x_old = 0;
* // The algorithm starts at x=6
* var x_new = 6;
* var stepSize = 0.01;
*
* function fDerivative(x) {
* return 4 * Math.pow(x, 3) - 9 * Math.pow(x, 2);
* }
*
* // The loop runs until the difference between the previous
* // value and the current value is smaller than epsilon - a rough
* // meaure of 'close enough'
* while (Math.abs(x_new - x_old) > ss.epsilon) {
* x_old = x_new;
* x_new = x_old - stepSize * fDerivative(x_old);
* }
*
* console.log('Local minimum occurs at', x_new);
*/
const epsilon = 0.0001;
export default epsilon;