MCPcopy Index your code
hub / github.com/microsoft/SandDance / quad

Function quad

docs/app/js/sanddance-app.js:119756–119782  ·  view source on GitHub ↗
(data, x5, y)

Source from the content-addressed store, hash-verified

119754 };
119755}
119756function quad(data, x5, y) {
119757 const [xv, yv, ux, uy] = points(data, x5, y), n = xv.length;
119758 let X2 = 0, X3 = 0, X4 = 0, XY = 0, X2Y = 0, i, dx, dy, x2;
119759 for(i = 0; i < n;){
119760 dx = xv[i];
119761 dy = yv[i++];
119762 x2 = dx * dx;
119763 X2 += (x2 - X2) / i;
119764 X3 += (x2 * dx - X3) / i;
119765 X4 += (x2 * x2 - X4) / i;
119766 XY += (dx * dy - XY) / i;
119767 X2Y += (x2 * dy - X2Y) / i;
119768 }
119769 const X2X2 = X4 - X2 * X2, d = X2 * X2X2 - X3 * X3, a = (X2Y * X2 - XY * X3) / d, b = (XY * X2X2 - X2Y * X3) / d, c = -a * X2, predict = (x)=>{
119770 x = x - ux;
119771 return a * x * x + b * x + c + uy;
119772 }; // transform coefficients back from mean-centered space
119773 return {
119774 coef: [
119775 c - b * ux + a * ux * ux + uy,
119776 b - 2 * a * ux,
119777 a
119778 ],
119779 predict: predict,
119780 rSquared: rSquared(data, x5, y, uy, predict)
119781 };
119782}
119783// License: https://github.com/HarryStevens/d3-regression/blob/master/LICENSE
119784// ... which was adapted from regression-js by Tom Alexander
119785// Source: https://github.com/Tom-Alexander/regression-js/blob/master/src/regression.js#L246

Callers 1

polyFunction · 0.70

Calls 2

pointsFunction · 0.70
rSquaredFunction · 0.70

Tested by

no test coverage detected