20161107

Faster hypot for JavaScript

When the distance between two points is required, one method of computation in modern browsers is a function called Hypot. Implementation of this function is often not optimized and ultimately calls on Math.sqrt at the last step. Performance tests indicate a calculation bottleneck with JavaScript's standard Math library implementation. Here then is an improvement of hypot at the cost of a fractional error (0.05%):

  function hypot(x, y) { // expects: abs(x) and abs(y)
    var a = Math.max(x,y),
        b = Math.min(x,y)/a,
        c = 1 + b*b;
    return a * ((-0.0705613450914645*c + 0.624084374908536)*c + 0.447383574908535);
  };

Note, this function expects absolute values (which can be computed on the call). The formula in the return is a polynomial approximation of the square root of values in the range from 1 to 2. Caveat: your mileage may vary!

20161102

Neural Network in 12 lines of JavaScript

Inspired by Andrew Trask's article about coding a neural network in 11 lines of Python, I wondered if this could be accomplished as succinctly in JavaScript. Part of the brevity of the Python solution is the use of a common numeric library called Numpy which helps manipulate matrix mathematics. For something comparable, I rolled my own JavaScript matrix library to assist with some of the notation and computation. The implementation converges quickly on the XOR solution as represented by the box moving toward the outlined target. Explore the solution on the newly revamped OpenProcessing website and embedded here:
20161112 Update: Just noticed this similar implementation.

20160306

Sphiral Minima

1000 dots perform a coordinated dance. How many combinations could there be? It's surprising! Tap/click to advance along the time continuum (the x value is added to the timeline, so clicking near the left side advances more slowly than clicking near the right side)...amazing harmonic patterns await. WARNING: there is a naturally occurring stroboscopic effect at times. This sketch is a reduction of http://hakim.se/experiments/html5/sphere.

KVR News:

The Gadget Blog | Latest Gadgets, Technology