vega-regression
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -9,13 +9,13 @@ (function (global, factory) { | ||
var groups = [], | ||
get = function (f) { | ||
return f(t); | ||
}, | ||
map, | ||
i, | ||
n, | ||
t, | ||
k, | ||
g; // partition data points into stack groups | ||
get = function (f) { | ||
return f(t); | ||
}, | ||
map, | ||
i, | ||
n, | ||
t, | ||
k, | ||
g; | ||
// partition data points into stack groups | ||
if (groupby == null) { | ||
@@ -28,3 +28,2 @@ groups.push(data); | ||
g = map[k]; | ||
if (!g) { | ||
@@ -35,7 +34,5 @@ map[k] = g = []; | ||
} | ||
g.push(t); | ||
} | ||
} | ||
return groups; | ||
@@ -53,3 +50,2 @@ } | ||
*/ | ||
function Loess(params) { | ||
@@ -88,18 +84,15 @@ vegaDataflow.Transform.call(this, null, params); | ||
const 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 = 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]; | ||
@@ -113,6 +106,4 @@ t[as[1]] = p[1]; | ||
} | ||
return out; | ||
} | ||
}); | ||
@@ -128,4 +119,4 @@ | ||
}; | ||
const degreesOfFreedom = (method, order) => method === 'poly' ? order : method === 'quad' ? 2 : 1; | ||
const degreesOfFreedom = (method, order) => method === 'poly' ? order : method === 'quad' ? 2 : 1; | ||
/** | ||
@@ -142,4 +133,2 @@ * Compute regression fits for one or more data groups. | ||
*/ | ||
function Regression(params) { | ||
@@ -192,19 +181,16 @@ vegaDataflow.Transform.call(this, null, params); | ||
const 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 = []; | ||
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) { | ||
@@ -216,6 +202,4 @@ if (method === 'log' && domain[0] <= 0) { | ||
} | ||
groups.forEach(g => { | ||
const n = g.length; | ||
if (n <= dof) { | ||
@@ -225,5 +209,3 @@ pulse.dataflow.warn('Skipping regression with more parameters than data points.'); | ||
} | ||
const model = fit(g, _.x, _.y, order); | ||
if (_.params) { | ||
@@ -238,16 +220,12 @@ // if parameter vectors requested return those | ||
} | ||
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)); | ||
}; | ||
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') { | ||
@@ -264,6 +242,4 @@ // for linear regression we only need the end points | ||
} | ||
return out; | ||
} | ||
}); | ||
@@ -274,4 +250,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); |
@@ -1,2 +0,2 @@ | ||
!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="undefined"!=typeof globalThis?globalThis:e||self).vega={},e.vega,e.vega,e.vega)}(this,(function(e,r,a,t){"use strict";function s(e,r){var a,t,s,n,o,i,l=[],u=function(e){return e(n)};if(null==r)l.push(e);else for(a={},t=0,s=e.length;t<s;++t)n=e[t],(i=a[o=r.map(u)])||(a[o]=i=[],i.dims=o,l.push(i)),i.push(n);return l}function n(e){a.Transform.call(this,null,e)}n.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(n,a.Transform,{transform(e,n){const o=n.fork(n.NO_SOURCE|n.NO_FIELDS);if(!this.value||n.changed()||e.modified()){const i=s(n.materialize(n.SOURCE).source,e.groupby),l=(e.groupby||[]).map(t.accessorName),u=l.length,d=e.as||[t.accessorName(e.x),t.accessorName(e.y)],f=[];i.forEach((t=>{r.regressionLoess(t,e.x,e.y,e.bandwidth||.3).forEach((e=>{const r={};for(let e=0;e<u;++e)r[l[e]]=t.dims[e];r[d[0]]=e[0],r[d[1]]=e[1],f.push(a.ingest(r))}))})),this.value&&(o.rem=this.value),this.value=o.add=o.source=f}return o}});const o={linear:r.regressionLinear,log:r.regressionLog,exp:r.regressionExp,pow:r.regressionPow,quad:r.regressionQuad,poly:r.regressionPoly};function i(e){a.Transform.call(this,null,e)}i.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(o)},{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(i,a.Transform,{transform(e,n){const i=n.fork(n.NO_SOURCE|n.NO_FIELDS);if(!this.value||n.changed()||e.modified()){const l=s(n.materialize(n.SOURCE).source,e.groupby),u=(e.groupby||[]).map(t.accessorName),d=e.method||"linear",f=e.order||3,m=((e,r)=>"poly"===e?r:"quad"===e?2:1)(d,f),p=e.as||[t.accessorName(e.x),t.accessorName(e.y)],g=o[d],c=[];let y=e.extent;t.hasOwnProperty(o,d)||t.error("Invalid regression method: "+d),null!=y&&"log"===d&&y[0]<=0&&(n.dataflow.warn("Ignoring extent with values <= 0 for log regression."),y=null),l.forEach((s=>{if(s.length<=m)return void n.dataflow.warn("Skipping regression with more parameters than data points.");const o=g(s,e.x,e.y,f);if(e.params)return void c.push(a.ingest({keys:s.dims,coef:o.coef,rSquared:o.rSquared}));const i=y||t.extent(s,e.x),l=e=>{const r={};for(let e=0;e<u.length;++e)r[u[e]]=s.dims[e];r[p[0]]=e[0],r[p[1]]=e[1],c.push(a.ingest(r))};"linear"===d?i.forEach((e=>l([e,o.predict(e)]))):r.sampleCurve(o.predict,i,25,200).forEach(l)})),this.value&&(i.rem=this.value),this.value=i.add=i.source=c}return i}}),e.loess=n,e.regression=i,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!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="undefined"!=typeof globalThis?globalThis:e||self).vega={},e.vega,e.vega,e.vega)}(this,(function(e,r,a,t){"use strict";function s(e,r){var a,t,s,n,i,o,l=[],u=function(e){return e(n)};if(null==r)l.push(e);else for(a={},t=0,s=e.length;t<s;++t)n=e[t],(o=a[i=r.map(u)])||(a[i]=o=[],o.dims=i,l.push(o)),o.push(n);return l}function n(e){a.Transform.call(this,null,e)}n.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(n,a.Transform,{transform(e,n){const i=n.fork(n.NO_SOURCE|n.NO_FIELDS);if(!this.value||n.changed()||e.modified()){const o=s(n.materialize(n.SOURCE).source,e.groupby),l=(e.groupby||[]).map(t.accessorName),u=l.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<u;++e)r[l[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(e,n){const o=n.fork(n.NO_SOURCE|n.NO_FIELDS);if(!this.value||n.changed()||e.modified()){const l=s(n.materialize(n.SOURCE).source,e.groupby),u=(e.groupby||[]).map(t.accessorName),d=e.method||"linear",f=e.order||3,m=((e,r)=>"poly"===e?r:"quad"===e?2:1)(d,f),p=e.as||[t.accessorName(e.x),t.accessorName(e.y)],g=i[d],c=[];let h=e.extent;t.hasOwnProperty(i,d)||t.error("Invalid regression method: "+d),null!=h&&"log"===d&&h[0]<=0&&(n.dataflow.warn("Ignoring extent with values <= 0 for log regression."),h=null),l.forEach((s=>{if(s.length<=m)return void n.dataflow.warn("Skipping regression with more parameters than data points.");const i=g(s,e.x,e.y,f);if(e.params)return void c.push(a.ingest({keys:s.dims,coef:i.coef,rSquared:i.rSquared}));const o=h||t.extent(s,e.x),l=e=>{const r={};for(let e=0;e<u.length;++e)r[u[e]]=s.dims[e];r[p[0]]=e[0],r[p[1]]=e[1],c.push(a.ingest(r))};"linear"===d?o.forEach((e=>l([e,i.predict(e)]))):r.sampleCurve(i.predict,o,25,200).forEach(l)})),this.value&&(o.rem=this.value),this.value=o.add=o.source=c}return o}}),e.loess=n,e.regression=o})); | ||
//# sourceMappingURL=vega-regression.min.js.map |
@@ -7,13 +7,13 @@ import { regressionLoess, sampleCurve, regressionLinear, regressionLog, regressionExp, regressionPow, regressionQuad, regressionPoly } from 'vega-statistics'; | ||
var groups = [], | ||
get = function (f) { | ||
return f(t); | ||
}, | ||
map, | ||
i, | ||
n, | ||
t, | ||
k, | ||
g; // partition data points into stack groups | ||
get = function (f) { | ||
return f(t); | ||
}, | ||
map, | ||
i, | ||
n, | ||
t, | ||
k, | ||
g; | ||
// partition data points into stack groups | ||
if (groupby == null) { | ||
@@ -26,3 +26,2 @@ groups.push(data); | ||
g = map[k]; | ||
if (!g) { | ||
@@ -33,7 +32,5 @@ map[k] = g = []; | ||
} | ||
g.push(t); | ||
} | ||
} | ||
return groups; | ||
@@ -51,3 +48,2 @@ } | ||
*/ | ||
function Loess(params) { | ||
@@ -86,18 +82,15 @@ Transform.call(this, null, params); | ||
const 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 = 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]; | ||
@@ -111,6 +104,4 @@ t[as[1]] = p[1]; | ||
} | ||
return out; | ||
} | ||
}); | ||
@@ -126,4 +117,4 @@ | ||
}; | ||
const degreesOfFreedom = (method, order) => method === 'poly' ? order : method === 'quad' ? 2 : 1; | ||
const degreesOfFreedom = (method, order) => method === 'poly' ? order : method === 'quad' ? 2 : 1; | ||
/** | ||
@@ -140,4 +131,2 @@ * Compute regression fits for one or more data groups. | ||
*/ | ||
function Regression(params) { | ||
@@ -190,19 +179,16 @@ Transform.call(this, null, params); | ||
const 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 = []; | ||
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) { | ||
@@ -214,6 +200,4 @@ if (method === 'log' && domain[0] <= 0) { | ||
} | ||
groups.forEach(g => { | ||
const n = g.length; | ||
if (n <= dof) { | ||
@@ -223,5 +207,3 @@ pulse.dataflow.warn('Skipping regression with more parameters than data points.'); | ||
} | ||
const model = fit(g, _.x, _.y, order); | ||
if (_.params) { | ||
@@ -236,16 +218,12 @@ // if parameter vectors requested return those | ||
} | ||
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)); | ||
}; | ||
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') { | ||
@@ -262,8 +240,6 @@ // for linear regression we only need the end points | ||
} | ||
return out; | ||
} | ||
}); | ||
export { Loess as loess, Regression as regression }; |
{ | ||
"name": "vega-regression", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Regression transform for Vega dataflows.", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"prebuild": "rimraf build", | ||
"build": "rollup -c", | ||
"build": "rollup -c rollup.config.mjs", | ||
"pretest": "yarn build --config-test", | ||
@@ -25,3 +25,3 @@ "test": "tape 'test/**/*-test.js'", | ||
"dependencies": { | ||
"d3-array": "^3.1.1", | ||
"d3-array": "^3.2.2", | ||
"vega-dataflow": "^5.7.3", | ||
@@ -34,3 +34,3 @@ "vega-statistics": "^1.7.9", | ||
}, | ||
"gitHead": "9a3faca4395cade9ecdfde90af98f1c53e9916b2" | ||
"gitHead": "fb1092f6b931d450f9c210b67ae4752bd3dd461b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38619
Updatedd3-array@^3.2.2