How to use vega-statistics - 10 common examples

To help you get started, we’ve selected a few vega-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

domoritz / line-density / demo / demo.ts View on Github
``````let canvas;
document.getElementById("regl").innerText = "";
if ((document.getElementById("debug") as HTMLInputElement).checked) {
canvas = document.createElement("canvas");
document.getElementById("regl").appendChild(canvas);
}

const maxY = (data.data as Float32Array).reduce(
(agg, val) => Math.max(agg, val),
0
);

// compute nice bin boundaries
const binConfigX = bin({ maxbins: binsx, extent: [0, points - 1] });
const binConfigY = bin({ maxbins: binsy, extent: [0, maxY] });

start = Date.now();
compute(data, binConfigX, binConfigY, canvas).then(heatmapData => {
document.getElementById("computetime").innerText = `\${(Date.now() - start) /
1000} seconds`;
heatmap(heatmapData, binConfigX, binConfigY);
});
}``````
uwdata / errudite / ui / src / components / attr-manager / AttrBar.tsx View on Github
``````extent.push(extent[0] === 1 ? extent[0] + 0.1 : extent[0] + 1);
}
// the performance distribution is always [0, 1]
const binIdxes = d3.range(0, this.binCount - 2);
const binFunction = d3.scaleQuantile()
.domain(d3.merge([
this.flatCounts.correct.concat(this.flatCountsRewrite.correct) as number[],
this.flatCounts.incorrect.concat(this.flatCountsRewrite.incorrect) as number[]]))
.range(binIdxes);

this.scale.attrScale_continue.domain(extent);
let bins = d3.merge([
[extent[0]],binFunction.quantiles(),
[extent[1]]]).filter(utils.uniques) as number[];
if ( (bins[bins.length-1] - bins[0] &lt;= 1) || bins.length &lt; this.binCount * 0.6) {
const bins_ = vegaStat.bin({extent: extent, nice: false, maxbins: this.binCount });
this.scale.bins = d3.range(bins_.start, bins_.stop + bins_.step, bins_.step);
} else {
//bins.push(extent[1] === 1 ? extent[1] + 0.1 : extent[1] + 1);
this.scale.bins = bins;
}
} else {
this.scale.bins = this.domain.slice();//this.attr.stats.map(s =&gt; s.value);
this.scale.attrScale_discrete.domain(this.scale.bins as string[]);
}
/*
if (this.props.attr.name === "groundtruths_length") {
this.scale.attrScale_continue.domain([1, 20]);
this.scale.bins = [1, 2, 3, 4, 5, 6, 7, 8, 20]
}
if (this.props.attr.name === "prediction_length") {
this.scale.attrScale_continue.domain([1, 50]);``````
domoritz / line-density / demo / demo.ts View on Github
``````lineChart(data);

let canvas;
document.getElementById("regl").innerText = "";
if ((document.getElementById("debug") as HTMLInputElement).checked) {
canvas = document.createElement("canvas");
document.getElementById("regl").appendChild(canvas);
}

const maxY = (data.data as Float32Array).reduce(
(agg, val) => Math.max(agg, val),
0
);

// compute nice bin boundaries
const binConfigX = bin({ maxbins: binsx, extent: [0, points - 1] });
const binConfigY = bin({ maxbins: binsy, extent: [0, maxY] });

start = Date.now();
compute(data, binConfigX, binConfigY, canvas).then(heatmapData => {
document.getElementById("computetime").innerText = `\${(Date.now() - start) /
1000} seconds`;
heatmap(heatmapData, binConfigX, binConfigY);
});
}``````
vega / vega / packages / vega-regression / src / Regression.js View on Github
``````add = p =&gt; {
const t = {};
for (let i=0; i add([x, model.predict(x)]));
} else {
// otherwise return trend line sample points
sampleCurve(model.predict, dom, 25, 200).forEach(add);
}
});``````
vega / vega / packages / vega-transforms / src / DotBin.js View on Github
``````const source = pulse.materialize(pulse.SOURCE).source,
groups = partition(pulse.source, _.groupby, identity),
smooth = _.smooth || false,
field = _.field,
step = _.step || autostep(source, field),
sort = stableCompare((a, b) =&gt; field(a) - field(b)),
as = _.as || Output,
n = groups.length;

// compute dotplot bins per group
let min = Infinity, max = -Infinity, i = 0, j;
for (; i max) max = v;
g[++j][as] = v;
}
}

this.value = {
start: min,
stop: max,
step: step
};
return pulse.reflow(true).modifies(as);
};``````
vega / vega / packages / vega-transforms / src / Sample.js View on Github
``````function update(t) {
var p, idx;

if (res.length &lt; num) {
res.push(t);
} else {
idx = ~~((cnt + 1) * random());
if (idx &lt; res.length &amp;&amp; idx &gt;= cap) {
p = res[idx];
if (map[tupleid(p)]) out.rem.push(p); // eviction
res[idx] = t;
}
}
++cnt;
}``````
vega / vega-dataflow / src / transforms / Bin.js View on Github
``````prototype._bins = function(_) {
if (this.value && !_.modified()) {
return this.value;
}

var field = _.field,
bins  = bin(_),
start = bins.start,
stop  = bins.stop,
step  = bins.step,
a, d;

if ((a = _.anchor) != null) {
d = a - (start + step * Math.floor((a - start) / step));
start += d;
stop += d;
}

var f = function(t) {
var v = field(t);
if (v == null) {
return null;
} else {``````
vega / vega / packages / vega-transforms / src / Bin.js View on Github
``````prototype._bins = function(_) {
if (this.value &amp;&amp; !_.modified()) {
return this.value;
}

var field = _.field,
bins  = bin(_),
step  = bins.step,
start = bins.start,
stop  = start + Math.ceil((bins.stop - start) / step) * step,
a, d;

if ((a = _.anchor) != null) {
d = a - (start + step * Math.floor((a - start) / step));
start += d;
stop += d;
}

var f = function(t) {
var v = field(t);
return v == null ? null
: v &lt; start ? -Infinity
: v &gt; stop ? +Infinity``````
vega / vega / packages / vega-transforms / src / KDE.js View on Github
``````groups.forEach(g =&gt; {
const density = randomKDE(g, bandwidth)[method],
scale = _.counts ? g.length : 1,
local = domain || extent(g);

sampleCurve(density, local, minsteps, maxsteps).forEach(v =&gt; {
const t = {};
for (let i=0; i``````
vega / vega / packages / vega-transforms / src / Density.js View on Github
``````var dist = parseDist(_.distribution, source(pulse)),
minsteps = _.steps || _.minsteps || 25,
maxsteps = _.steps || _.maxsteps || 200,
method = _.method || 'pdf';

if (method !== 'pdf' && method !== 'cdf') {
error('Invalid density method: ' + method);
}
if (!_.extent && !dist.data) {
error('Missing density extent parameter.');
}
method = dist[method];

var as = _.as || ['value', 'density'],
domain = _.extent || extent(dist.data()),
values = sampleCurve(method, domain, minsteps, maxsteps).map(v => {
var tuple = {};
tuple[as[0]] = v[0];
tuple[as[1]] = v[1];
return ingest(tuple);
});

if (this.value) out.rem = this.value;
this.value = out.add = out.source = values;
}

return out;
};``````

vega-statistics

Statistical routines and probability distributions.

BSD-3-Clause