Skip to main content
Module

x/simplestatistics/index.js>epsilon

simple statistics for node & browser javascript
Go to Latest
variable epsilon
import { epsilon } from "https://deno.land/x/simplestatistics@v7.7.5/index.js";

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: it progresses until it is close enough.

Below is an example of using epsilon in gradient descent, where we're trying to find a local minimum of a function's derivative, given by the fDerivative method.

Examples

// 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);

type

0.0001