Published
Edited
Feb 26, 2019
10 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function varianceBinarySearch(points, i, entropy, error=1e-6, steps=40) {
function recursiveBinarySearch(variance, lowerBound, upperBound) {
const probabilities = computeP_i(points, i, variance),
currentEntropy = computeEntropy(probabilities);
if (steps-- <= 1 || Math.abs(currentEntropy - entropy) <= error)
return probabilities;
if (currentEntropy > entropy)
return recursiveBinarySearch((lowerBound+variance)/2, lowerBound, variance);
else
return recursiveBinarySearch((variance+upperBound)/2, variance, upperBound);
}

const MINVAR = 0.01,
MAXVAR = 50;
return recursiveBinarySearch((MINVAR+MAXVAR)/2, MINVAR, MAXVAR);
}
Insert cell
function adjustVariances(points, entropy, error, steps) {
let size = points.length,
p = [];
for (let i = 0; i < size; i++)
p = p.concat(varianceBinarySearch(points, i, entropy, error, steps))
var total = p.reduce((sum, current)=>sum+current,0)
return p.map((x)=>x/total);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pointsMap = {
if (iteractionCount >= T)
yield yDisplay.map((p, i)=>(p.y==undefined?{x:Y[i][0],
name:p.name,
Cluster:p.Cluster}:
{x:Y[i][0],
y:Y[i][1],
name:p.name,
Cluster:p.Cluster}));
else {
// Adapted from: https://github.com/karpathy/tsnejs
var N = Y.length;
var dim = Y[0].length;
var grad = gradient(Y, pFinal, iteractionCount);
var sign = ((p)=>p<0?-1:p>0?1:p);
mutable costRun = cost(Y, pFinal);
mutable iteractionCount++;
// perform gradient step
for(var i=0;i<N;i++) {
for(var d=0;d<dim;d++) {
var gid = grad[i][d];
var sid = ystep[i][d];
var gainid = gains[i][d];

// compute gain update
var newgain = sign(gid) === sign(sid) ? gainid * 0.8 : gainid + 0.2;
if(gainid < 0.01) gainid = 0.01; // clamp
gains[i][d] = newgain; // store for next turn

// compute momentum step direction
var momval = momentum[iteractionCount < triggerMomentum]; // ? 0.5 : 0.8;
var newsid = momval * sid - eta * newgain * grad[i][d];
ystep[i][d] = newsid; // remember the step we took

// step!
Y[i][d] += newsid;
}
}
yield yDisplay.map((p, i)=>(p.y==undefined?{x:Y[i][0],
name:p.name,
Cluster:p.Cluster}:
{x:Y[i][0],
y:Y[i][1],
name:p.name,
Cluster:p.Cluster}));
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more