Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vega-regression

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-regression - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

183

build/vega-regression.js
(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));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.vega = global.vega || {}, global.vega.transforms = {}), global.vega, global.vega, global.vega));
}(this, (function (exports, vegaStatistics, vegaDataflow, vegaUtil) { 'use strict';

@@ -57,34 +57,34 @@

var prototype = vegaUtil.inherits(Loess, vegaDataflow.Transform);
vegaUtil.inherits(Loess, vegaDataflow.Transform, {
transform(_, pulse) {
const out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
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 = [];
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));
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;
if (this.value) out.rem = this.value;
this.value = out.add = out.source = values;
}
return out;
}
});
return out;
};
const Methods = {

@@ -99,5 +99,4 @@ linear: vegaStatistics.regressionLinear,

function degreesOfFreedom(method, order) {
return method === 'poly' ? order : method === 'quad' ? 2 : 1;
}
const degreesOfFreedom = (method, order) =>
method === 'poly' ? order : method === 'quad' ? 2 : 1;

@@ -134,77 +133,77 @@ /**

var prototype$1 = vegaUtil.inherits(Regression, vegaDataflow.Transform);
vegaUtil.inherits(Regression, vegaDataflow.Transform, {
transform(_, pulse) {
const out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
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 = [];
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;
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;
if (!vegaUtil.hasOwnProperty(Methods, method)) {
vegaUtil.error('Invalid regression method: ' + method);
}
}
groups.forEach(g => {
const n = g.length;
if (n <= dof) {
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
return;
if (domain != null) {
if (method === 'log' && domain[0] <= 0) {
pulse.dataflow.warn('Ignoring extent with values <= 0 for log regression.');
domain = null;
}
}
const model = fit(g, _.x, _.y, order);
groups.forEach(g => {
const n = g.length;
if (n <= dof) {
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
return;
}
if (_.params) {
// if parameter vectors requested return those
values.push(vegaDataflow.ingest({
keys: g.dims,
coef: model.coef,
rSquared: model.rSquared
}));
return;
}
const model = fit(g, _.x, _.y, order);
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 (_.params) {
// if parameter vectors requested return those
values.push(vegaDataflow.ingest({
keys: g.dims,
coef: model.coef,
rSquared: model.rSquared
}));
return;
}
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);
}
});
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 (this.value) out.rem = this.value;
this.value = out.add = out.source = values;
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;
}
});
return out;
};
exports.loess = Loess;

@@ -211,0 +210,0 @@ exports.regression = Regression;

@@ -1,1 +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})}));
!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.transforms={}),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})}));
{
"name": "vega-regression",
"version": "1.0.6",
"version": "1.0.7",
"description": "Regression transform for Vega dataflows.",

@@ -26,6 +26,6 @@ "keywords": [

"dependencies": {
"d3-array": "^2.4.0",
"vega-dataflow": "^5.5.1",
"vega-statistics": "^1.7.4",
"vega-util": "^1.13.2"
"d3-array": "^2.5.1",
"vega-dataflow": "^5.7.1",
"vega-statistics": "^1.7.7",
"vega-util": "^1.15.0"
},

@@ -35,3 +35,3 @@ "devDependencies": {

},
"gitHead": "35e31c5c6b54db9dc3a577b5adad8d15ec274d32"
"gitHead": "28db83352e43e321dfe55fc5cb6489b211e45662"
}

@@ -31,32 +31,32 @@ import partition from './partition';

var prototype = inherits(Loess, Transform);
inherits(Loess, Transform, {
transform(_, pulse) {
const out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
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 = [];
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));
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;
if (this.value) out.rem = this.value;
this.value = out.add = out.source = values;
}
return out;
}
return out;
};
});

@@ -18,5 +18,4 @@ import partition from './partition';

function degreesOfFreedom(method, order) {
return method === 'poly' ? order : method === 'quad' ? 2 : 1;
}
const degreesOfFreedom = (method, order) =>
method === 'poly' ? order : method === 'quad' ? 2 : 1;

@@ -53,75 +52,75 @@ /**

var prototype = inherits(Regression, Transform);
inherits(Regression, Transform, {
transform(_, pulse) {
const out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
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 = [];
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;
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;
if (!hasOwnProperty(Methods, method)) {
error('Invalid regression method: ' + method);
}
}
groups.forEach(g => {
const n = g.length;
if (n <= dof) {
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
return;
if (domain != null) {
if (method === 'log' && domain[0] <= 0) {
pulse.dataflow.warn('Ignoring extent with values <= 0 for log regression.');
domain = null;
}
}
const model = fit(g, _.x, _.y, order);
groups.forEach(g => {
const n = g.length;
if (n <= dof) {
pulse.dataflow.warn('Skipping regression with more parameters than data points.');
return;
}
if (_.params) {
// if parameter vectors requested return those
values.push(ingest({
keys: g.dims,
coef: model.coef,
rSquared: model.rSquared
}));
return;
}
const model = fit(g, _.x, _.y, order);
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 (_.params) {
// if parameter vectors requested return those
values.push(ingest({
keys: g.dims,
coef: model.coef,
rSquared: model.rSquared
}));
return;
}
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);
}
});
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 (this.value) out.rem = this.value;
this.value = out.add = out.source = values;
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;
}
return out;
};
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc