You've already forked wakapi-readme-stats
Bar graph added.
This commit is contained in:
27
node_modules/vega-regression/LICENSE
generated
vendored
Normal file
27
node_modules/vega-regression/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2015-2018, University of Washington Interactive Data Lab
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
8
node_modules/vega-regression/README.md
generated
vendored
Normal file
8
node_modules/vega-regression/README.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# vega-regression
|
||||
|
||||
Regression model fitting for Vega dataflows.
|
||||
|
||||
This package provides the following Vega data transforms:
|
||||
|
||||
- [**Loess**](https://vega.github.io/vega/docs/transforms/loess/) [<>](https://github.com/vega/vega/blob/master/packages/vega-regression/src/Loess.js "Source")
|
||||
- [**Regression**](https://vega.github.io/vega/docs/transforms/regression/) [<>](https://github.com/vega/vega/blob/master/packages/vega-regression/src/Regression.js "Source")
|
||||
212
node_modules/vega-regression/build/vega-regression.js
generated
vendored
Normal file
212
node_modules/vega-regression/build/vega-regression.js
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-statistics'), require('vega-dataflow'), require('vega-util')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'vega-statistics', 'vega-dataflow', 'vega-util'], factory) :
|
||||
(global = global || self, factory((global.vega = global.vega || {}, global.vega.transforms = {}), global.vega, global.vega, global.vega));
|
||||
}(this, (function (exports, vegaStatistics, vegaDataflow, vegaUtil) { 'use strict';
|
||||
|
||||
function partition(data, groupby) {
|
||||
var groups = [],
|
||||
get = function(f) { return f(t); },
|
||||
map, i, n, t, k, g;
|
||||
|
||||
// partition data points into stack groups
|
||||
if (groupby == null) {
|
||||
groups.push(data);
|
||||
} else {
|
||||
for (map={}, i=0, n=data.length; i<n; ++i) {
|
||||
t = data[i];
|
||||
k = groupby.map(get);
|
||||
g = map[k];
|
||||
if (!g) {
|
||||
map[k] = (g = []);
|
||||
g.dims = k;
|
||||
groups.push(g);
|
||||
}
|
||||
g.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute locally-weighted regression fits for one or more data groups.
|
||||
* @constructor
|
||||
* @param {object} params - The parameters for this operator.
|
||||
* @param {function(object): *} params.x - An accessor for the predictor data field.
|
||||
* @param {function(object): *} params.y - An accessor for the predicted data field.
|
||||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby.
|
||||
* @param {number} [params.bandwidth=0.3] - The loess bandwidth.
|
||||
*/
|
||||
function Loess(params) {
|
||||
vegaDataflow.Transform.call(this, null, params);
|
||||
}
|
||||
|
||||
Loess.Definition = {
|
||||
'type': 'Loess',
|
||||
'metadata': {'generates': true},
|
||||
'params': [
|
||||
{ 'name': 'x', 'type': 'field', 'required': true },
|
||||
{ 'name': 'y', 'type': 'field', 'required': true },
|
||||
{ 'name': 'groupby', 'type': 'field', 'array': true },
|
||||
{ 'name': 'bandwidth', 'type': 'number', 'default': 0.3 },
|
||||
{ 'name': 'as', 'type': 'string', 'array': true }
|
||||
]
|
||||
};
|
||||
|
||||
var prototype = vegaUtil.inherits(Loess, vegaDataflow.Transform);
|
||||
|
||||
prototype.transform = function(_, pulse) {
|
||||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
|
||||
|
||||
if (!this.value || pulse.changed() || _.modified()) {
|
||||
const source = pulse.materialize(pulse.SOURCE).source,
|
||||
groups = partition(source, _.groupby),
|
||||
names = (_.groupby || []).map(vegaUtil.accessorName),
|
||||
m = names.length,
|
||||
as = _.as || [vegaUtil.accessorName(_.x), vegaUtil.accessorName(_.y)],
|
||||
values = [];
|
||||
|
||||
groups.forEach(g => {
|
||||
vegaStatistics.regressionLoess(g, _.x, _.y, _.bandwidth || 0.3).forEach(p => {
|
||||
const t = {};
|
||||
for (let i=0; i<m; ++i) {
|
||||
t[names[i]] = g.dims[i];
|
||||
}
|
||||
t[as[0]] = p[0];
|
||||
t[as[1]] = p[1];
|
||||
values.push(vegaDataflow.ingest(t));
|
||||
});
|
||||
});
|
||||
|
||||
if (this.value) out.rem = this.value;
|
||||
this.value = out.add = out.source = values;
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
const Methods = {
|
||||
linear: vegaStatistics.regressionLinear,
|
||||
log: vegaStatistics.regressionLog,
|
||||
exp: vegaStatistics.regressionExp,
|
||||
pow: vegaStatistics.regressionPow,
|
||||
quad: vegaStatistics.regressionQuad,
|
||||
poly: vegaStatistics.regressionPoly
|
||||
};
|
||||
|
||||
function degreesOfFreedom(method, order) {
|
||||
return method === 'poly' ? order : method === 'quad' ? 2 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute regression fits for one or more data groups.
|
||||
* @constructor
|
||||
* @param {object} params - The parameters for this operator.
|
||||
* @param {function(object): *} params.x - An accessor for the predictor data field.
|
||||
* @param {function(object): *} params.y - An accessor for the predicted data field.
|
||||
* @param {string} [params.method='linear'] - The regression method to apply.
|
||||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby.
|
||||
* @param {Array<number>} [params.extent] - The domain extent over which to plot the regression line.
|
||||
* @param {number} [params.order=3] - The polynomial order. Only applies to the 'poly' method.
|
||||
*/
|
||||
function Regression(params) {
|
||||
vegaDataflow.Transform.call(this, null, params);
|
||||
}
|
||||
|
||||
Regression.Definition = {
|
||||
'type': 'Regression',
|
||||
'metadata': {'generates': true},
|
||||
'params': [
|
||||
{ 'name': 'x', 'type': 'field', 'required': true },
|
||||
{ 'name': 'y', 'type': 'field', 'required': true },
|
||||
{ 'name': 'groupby', 'type': 'field', 'array': true },
|
||||
{ 'name': 'method', 'type': 'string', 'default': 'linear', 'values': Object.keys(Methods) },
|
||||
{ 'name': 'order', 'type': 'number', 'default': 3 },
|
||||
{ 'name': 'extent', 'type': 'number', 'array': true, 'length': 2 },
|
||||
{ 'name': 'params', 'type': 'boolean', 'default': false },
|
||||
{ 'name': 'as', 'type': 'string', 'array': true }
|
||||
]
|
||||
};
|
||||
|
||||
var prototype$1 = vegaUtil.inherits(Regression, vegaDataflow.Transform);
|
||||
|
||||
prototype$1.transform = function(_, pulse) {
|
||||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
|
||||
|
||||
if (!this.value || pulse.changed() || _.modified()) {
|
||||
const source = pulse.materialize(pulse.SOURCE).source,
|
||||
groups = partition(source, _.groupby),
|
||||
names = (_.groupby || []).map(vegaUtil.accessorName),
|
||||
method = _.method || 'linear',
|
||||
order = _.order || 3,
|
||||
dof = degreesOfFreedom(method, order),
|
||||
as = _.as || [vegaUtil.accessorName(_.x), vegaUtil.accessorName(_.y)],
|
||||
fit = Methods[method],
|
||||
values = [];
|
||||
|
||||
let domain = _.extent;
|
||||
|
||||
if (!vegaUtil.hasOwnProperty(Methods, method)) {
|
||||
vegaUtil.error('Invalid regression method: ' + method);
|
||||
}
|
||||
|
||||
if (domain != null) {
|
||||
if (method === 'log' && domain[0] <= 0) {
|
||||
pulse.dataflow.warn('Ignoring extent with values <= 0 for log regression.');
|
||||
domain = null;
|
||||
}
|
||||
}
|
||||
|
||||
groups.forEach(g => {
|
||||
const n = g.length;
|
||||
if (n <= dof) {
|
||||
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
|
||||
return;
|
||||
}
|
||||
|
||||
const model = fit(g, _.x, _.y, order);
|
||||
|
||||
if (_.params) {
|
||||
// if parameter vectors requested return those
|
||||
values.push(vegaDataflow.ingest({
|
||||
keys: g.dims,
|
||||
coef: model.coef,
|
||||
rSquared: model.rSquared
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
const dom = domain || vegaUtil.extent(g, _.x),
|
||||
add = p => {
|
||||
const t = {};
|
||||
for (let i=0; i<names.length; ++i) {
|
||||
t[names[i]] = g.dims[i];
|
||||
}
|
||||
t[as[0]] = p[0];
|
||||
t[as[1]] = p[1];
|
||||
values.push(vegaDataflow.ingest(t));
|
||||
};
|
||||
|
||||
if (method === 'linear') {
|
||||
// for linear regression we only need the end points
|
||||
dom.forEach(x => add([x, model.predict(x)]));
|
||||
} else {
|
||||
// otherwise return trend line sample points
|
||||
vegaStatistics.sampleCurve(model.predict, dom, 25, 200).forEach(add);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.value) out.rem = this.value;
|
||||
this.value = out.add = out.source = values;
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
exports.loess = Loess;
|
||||
exports.regression = Regression;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
1
node_modules/vega-regression/build/vega-regression.min.js
generated
vendored
Normal file
1
node_modules/vega-regression/build/vega-regression.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("vega-statistics"),require("vega-dataflow"),require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-statistics","vega-dataflow","vega-util"],r):r(((e=e||self).vega=e.vega||{},e.vega.transforms={}),e.vega,e.vega,e.vega)}(this,(function(e,r,a,t){"use strict";function n(e,r){var a,t,n,s,i,o,u=[],l=function(e){return e(s)};if(null==r)u.push(e);else for(a={},t=0,n=e.length;t<n;++t)s=e[t],(o=a[i=r.map(l)])||(a[i]=o=[],o.dims=i,u.push(o)),o.push(s);return u}function s(e){a.Transform.call(this,null,e)}s.Definition={type:"Loess",metadata:{generates:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"bandwidth",type:"number",default:.3},{name:"as",type:"string",array:!0}]},t.inherits(s,a.Transform).transform=function(e,s){var i=s.fork(s.NO_SOURCE|s.NO_FIELDS);if(!this.value||s.changed()||e.modified()){const o=n(s.materialize(s.SOURCE).source,e.groupby),u=(e.groupby||[]).map(t.accessorName),l=u.length,d=e.as||[t.accessorName(e.x),t.accessorName(e.y)],f=[];o.forEach(t=>{r.regressionLoess(t,e.x,e.y,e.bandwidth||.3).forEach(e=>{const r={};for(let e=0;e<l;++e)r[u[e]]=t.dims[e];r[d[0]]=e[0],r[d[1]]=e[1],f.push(a.ingest(r))})}),this.value&&(i.rem=this.value),this.value=i.add=i.source=f}return i};const i={linear:r.regressionLinear,log:r.regressionLog,exp:r.regressionExp,pow:r.regressionPow,quad:r.regressionQuad,poly:r.regressionPoly};function o(e){a.Transform.call(this,null,e)}o.Definition={type:"Regression",metadata:{generates:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"method",type:"string",default:"linear",values:Object.keys(i)},{name:"order",type:"number",default:3},{name:"extent",type:"number",array:!0,length:2},{name:"params",type:"boolean",default:!1},{name:"as",type:"string",array:!0}]},t.inherits(o,a.Transform).transform=function(e,s){var o=s.fork(s.NO_SOURCE|s.NO_FIELDS);if(!this.value||s.changed()||e.modified()){const u=n(s.materialize(s.SOURCE).source,e.groupby),l=(e.groupby||[]).map(t.accessorName),d=e.method||"linear",f=e.order||3,m=function(e,r){return"poly"===e?r:"quad"===e?2:1}(d,f),p=e.as||[t.accessorName(e.x),t.accessorName(e.y)],c=i[d],g=[];let y=e.extent;t.hasOwnProperty(i,d)||t.error("Invalid regression method: "+d),null!=y&&"log"===d&&y[0]<=0&&(s.dataflow.warn("Ignoring extent with values <= 0 for log regression."),y=null),u.forEach(n=>{if(n.length<=m)return void s.dataflow.warn("Skipping regression with more parameters than data points.");const i=c(n,e.x,e.y,f);if(e.params)return void g.push(a.ingest({keys:n.dims,coef:i.coef,rSquared:i.rSquared}));const o=y||t.extent(n,e.x),u=e=>{const r={};for(let e=0;e<l.length;++e)r[l[e]]=n.dims[e];r[p[0]]=e[0],r[p[1]]=e[1],g.push(a.ingest(r))};"linear"===d?o.forEach(e=>u([e,i.predict(e)])):r.sampleCurve(i.predict,o,25,200).forEach(u)}),this.value&&(o.rem=this.value),this.value=o.add=o.source=g}return o},e.loess=s,e.regression=o,Object.defineProperty(e,"__esModule",{value:!0})}));
|
||||
2
node_modules/vega-regression/index.js
generated
vendored
Normal file
2
node_modules/vega-regression/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {default as loess} from './src/Loess';
|
||||
export {default as regression} from './src/Regression';
|
||||
70
node_modules/vega-regression/package.json
generated
vendored
Normal file
70
node_modules/vega-regression/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "vega-regression@~1.0.6",
|
||||
"_id": "vega-regression@1.0.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-s4kjsKp23WvDJDHkpIrGNUaLI3/95k6nTURj9RDtM4C6CbUgO2snIaEfki4JfOCnBYtvotwDuZgXKmJInu9hVw==",
|
||||
"_location": "/vega-regression",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "vega-regression@~1.0.6",
|
||||
"name": "vega-regression",
|
||||
"escapedName": "vega-regression",
|
||||
"rawSpec": "~1.0.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.0.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vega"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/vega-regression/-/vega-regression-1.0.6.tgz",
|
||||
"_shasum": "0081a91328e933c826813c06afe7041915532d4f",
|
||||
"_spec": "vega-regression@~1.0.6",
|
||||
"_where": "/home/prabhatdev/Documents/opensource/gitHubStats/waka-readme-stats/node_modules/vega",
|
||||
"author": {
|
||||
"name": "Jeffrey Heer",
|
||||
"url": "http://idl.cs.washington.edu"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vega/vega/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"d3-array": "^2.4.0",
|
||||
"vega-dataflow": "^5.5.1",
|
||||
"vega-statistics": "^1.7.4",
|
||||
"vega-util": "^1.13.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Regression transform for Vega dataflows.",
|
||||
"devDependencies": {
|
||||
"vega-transforms": "*"
|
||||
},
|
||||
"gitHead": "35e31c5c6b54db9dc3a577b5adad8d15ec274d32",
|
||||
"homepage": "https://github.com/vega/vega#readme",
|
||||
"keywords": [
|
||||
"vega",
|
||||
"regression",
|
||||
"loess"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "build/vega-regression.js",
|
||||
"module": "index",
|
||||
"name": "vega-regression",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vega/vega.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn rollup",
|
||||
"postbuild": "terser build/vega-regression.js -c -m -o build/vega-regression.min.js",
|
||||
"postpublish": "git push && git push --tags",
|
||||
"prebuild": "rimraf build && mkdir build",
|
||||
"prepublishOnly": "yarn test && yarn build",
|
||||
"pretest": "yarn prebuild && yarn rollup",
|
||||
"rollup": "rollup -g d3-array:d3,vega-dataflow:vega,vega-statistics:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-regression.js -- index.js",
|
||||
"test": "tape 'test/**/*-test.js'"
|
||||
},
|
||||
"version": "1.0.6"
|
||||
}
|
||||
61
node_modules/vega-regression/src/Loess.js
generated
vendored
Normal file
61
node_modules/vega-regression/src/Loess.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import partition from './partition';
|
||||
import {regressionLoess} from 'vega-statistics';
|
||||
import {Transform, ingest} from 'vega-dataflow';
|
||||
import {accessorName, inherits} from 'vega-util';
|
||||
|
||||
/**
|
||||
* Compute locally-weighted regression fits for one or more data groups.
|
||||
* @constructor
|
||||
* @param {object} params - The parameters for this operator.
|
||||
* @param {function(object): *} params.x - An accessor for the predictor data field.
|
||||
* @param {function(object): *} params.y - An accessor for the predicted data field.
|
||||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby.
|
||||
* @param {number} [params.bandwidth=0.3] - The loess bandwidth.
|
||||
*/
|
||||
export default function Loess(params) {
|
||||
Transform.call(this, null, params);
|
||||
}
|
||||
|
||||
Loess.Definition = {
|
||||
'type': 'Loess',
|
||||
'metadata': {'generates': true},
|
||||
'params': [
|
||||
{ 'name': 'x', 'type': 'field', 'required': true },
|
||||
{ 'name': 'y', 'type': 'field', 'required': true },
|
||||
{ 'name': 'groupby', 'type': 'field', 'array': true },
|
||||
{ 'name': 'bandwidth', 'type': 'number', 'default': 0.3 },
|
||||
{ 'name': 'as', 'type': 'string', 'array': true }
|
||||
]
|
||||
};
|
||||
|
||||
var prototype = inherits(Loess, Transform);
|
||||
|
||||
prototype.transform = function(_, pulse) {
|
||||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
|
||||
|
||||
if (!this.value || pulse.changed() || _.modified()) {
|
||||
const source = pulse.materialize(pulse.SOURCE).source,
|
||||
groups = partition(source, _.groupby),
|
||||
names = (_.groupby || []).map(accessorName),
|
||||
m = names.length,
|
||||
as = _.as || [accessorName(_.x), accessorName(_.y)],
|
||||
values = [];
|
||||
|
||||
groups.forEach(g => {
|
||||
regressionLoess(g, _.x, _.y, _.bandwidth || 0.3).forEach(p => {
|
||||
const t = {};
|
||||
for (let i=0; i<m; ++i) {
|
||||
t[names[i]] = g.dims[i];
|
||||
}
|
||||
t[as[0]] = p[0];
|
||||
t[as[1]] = p[1];
|
||||
values.push(ingest(t));
|
||||
});
|
||||
});
|
||||
|
||||
if (this.value) out.rem = this.value;
|
||||
this.value = out.add = out.source = values;
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
125
node_modules/vega-regression/src/Regression.js
generated
vendored
Normal file
125
node_modules/vega-regression/src/Regression.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
import partition from './partition';
|
||||
import {Transform, ingest} from 'vega-dataflow';
|
||||
import {
|
||||
regressionExp, regressionLinear, regressionLog,
|
||||
regressionPoly, regressionPow, regressionQuad, sampleCurve
|
||||
} from 'vega-statistics';
|
||||
import {accessorName, error, extent, hasOwnProperty, inherits} from 'vega-util';
|
||||
|
||||
const Methods = {
|
||||
linear: regressionLinear,
|
||||
log: regressionLog,
|
||||
exp: regressionExp,
|
||||
pow: regressionPow,
|
||||
quad: regressionQuad,
|
||||
poly: regressionPoly
|
||||
};
|
||||
|
||||
function degreesOfFreedom(method, order) {
|
||||
return method === 'poly' ? order : method === 'quad' ? 2 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute regression fits for one or more data groups.
|
||||
* @constructor
|
||||
* @param {object} params - The parameters for this operator.
|
||||
* @param {function(object): *} params.x - An accessor for the predictor data field.
|
||||
* @param {function(object): *} params.y - An accessor for the predicted data field.
|
||||
* @param {string} [params.method='linear'] - The regression method to apply.
|
||||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby.
|
||||
* @param {Array<number>} [params.extent] - The domain extent over which to plot the regression line.
|
||||
* @param {number} [params.order=3] - The polynomial order. Only applies to the 'poly' method.
|
||||
*/
|
||||
export default function Regression(params) {
|
||||
Transform.call(this, null, params);
|
||||
}
|
||||
|
||||
Regression.Definition = {
|
||||
'type': 'Regression',
|
||||
'metadata': {'generates': true},
|
||||
'params': [
|
||||
{ 'name': 'x', 'type': 'field', 'required': true },
|
||||
{ 'name': 'y', 'type': 'field', 'required': true },
|
||||
{ 'name': 'groupby', 'type': 'field', 'array': true },
|
||||
{ 'name': 'method', 'type': 'string', 'default': 'linear', 'values': Object.keys(Methods) },
|
||||
{ 'name': 'order', 'type': 'number', 'default': 3 },
|
||||
{ 'name': 'extent', 'type': 'number', 'array': true, 'length': 2 },
|
||||
{ 'name': 'params', 'type': 'boolean', 'default': false },
|
||||
{ 'name': 'as', 'type': 'string', 'array': true }
|
||||
]
|
||||
};
|
||||
|
||||
var prototype = inherits(Regression, Transform);
|
||||
|
||||
prototype.transform = function(_, pulse) {
|
||||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
|
||||
|
||||
if (!this.value || pulse.changed() || _.modified()) {
|
||||
const source = pulse.materialize(pulse.SOURCE).source,
|
||||
groups = partition(source, _.groupby),
|
||||
names = (_.groupby || []).map(accessorName),
|
||||
method = _.method || 'linear',
|
||||
order = _.order || 3,
|
||||
dof = degreesOfFreedom(method, order),
|
||||
as = _.as || [accessorName(_.x), accessorName(_.y)],
|
||||
fit = Methods[method],
|
||||
values = [];
|
||||
|
||||
let domain = _.extent;
|
||||
|
||||
if (!hasOwnProperty(Methods, method)) {
|
||||
error('Invalid regression method: ' + method);
|
||||
}
|
||||
|
||||
if (domain != null) {
|
||||
if (method === 'log' && domain[0] <= 0) {
|
||||
pulse.dataflow.warn('Ignoring extent with values <= 0 for log regression.');
|
||||
domain = null;
|
||||
}
|
||||
}
|
||||
|
||||
groups.forEach(g => {
|
||||
const n = g.length;
|
||||
if (n <= dof) {
|
||||
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
|
||||
return;
|
||||
}
|
||||
|
||||
const model = fit(g, _.x, _.y, order);
|
||||
|
||||
if (_.params) {
|
||||
// if parameter vectors requested return those
|
||||
values.push(ingest({
|
||||
keys: g.dims,
|
||||
coef: model.coef,
|
||||
rSquared: model.rSquared
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
const dom = domain || extent(g, _.x),
|
||||
add = p => {
|
||||
const t = {};
|
||||
for (let i=0; i<names.length; ++i) {
|
||||
t[names[i]] = g.dims[i];
|
||||
}
|
||||
t[as[0]] = p[0];
|
||||
t[as[1]] = p[1];
|
||||
values.push(ingest(t));
|
||||
};
|
||||
|
||||
if (method === 'linear') {
|
||||
// for linear regression we only need the end points
|
||||
dom.forEach(x => add([x, model.predict(x)]));
|
||||
} else {
|
||||
// otherwise return trend line sample points
|
||||
sampleCurve(model.predict, dom, 25, 200).forEach(add);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.value) out.rem = this.value;
|
||||
this.value = out.add = out.source = values;
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
24
node_modules/vega-regression/src/partition.js
generated
vendored
Normal file
24
node_modules/vega-regression/src/partition.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export default function(data, groupby) {
|
||||
var groups = [],
|
||||
get = function(f) { return f(t); },
|
||||
map, i, n, t, k, g;
|
||||
|
||||
// partition data points into stack groups
|
||||
if (groupby == null) {
|
||||
groups.push(data);
|
||||
} else {
|
||||
for (map={}, i=0, n=data.length; i<n; ++i) {
|
||||
t = data[i];
|
||||
k = groupby.map(get);
|
||||
g = map[k];
|
||||
if (!g) {
|
||||
map[k] = (g = []);
|
||||
g.dims = k;
|
||||
groups.push(g);
|
||||
}
|
||||
g.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
Reference in New Issue
Block a user