Published
Edited
Jan 6, 2022
4 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
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 bbVar(pontos, i, entropia, erro=1e-6, passos=40) {
function bbVarRec(variancia, limiteInf, limiteSup) {
const probabilidades = calcPi(pontos, i, variancia),
entropiaAtual = calcEntropia(probabilidades);
if (passos-- <= 1 || Math.abs(entropiaAtual - entropia) <= erro)
return probabilidades;
if (entropiaAtual > entropia)
return bbVarRec((limiteInf+variancia)/2, limiteInf, variancia);
else
return bbVarRec((variancia+limiteSup)/2, variancia, limiteSup);
}

const MINVAR = 0.01,
MAXVAR = 50;
return bbVarRec((MINVAR+MAXVAR)/2, MINVAR, MAXVAR);
}
Insert cell
function ajustaVariancias(pontos, entropia, erro, passos) {
let tamanho = pontos.length,
p = [];
for (let i = 0; i < tamanho; i++)
p = p.concat(bbVar(pontos, i, entropia, erro, passos))
var total = p.reduce((soma, atual)=>soma+atual,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
pontosMapa = {
if (iteracao >= T)
yield yDisplay.map((p, i)=>(p.y==undefined?{x:Y[i][0],
nome:p.nome,
Cluster:p.Cluster}:
{x:Y[i][0],
y:Y[i][1],
nome:p.nome,
Cluster:p.Cluster}));
else {
// Adaptado de: https://github.com/karpathy/tsnejs
var N = Y.length;
var dim = Y[0].length;
var grad = gradiente(Y, pFinal, iteracao);
var sign = ((p)=>p<0?-1:p>0?1:p);
mutable custoRun = custo(Y, pFinal);
mutable iteracao++;
// 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 = valores_momentum[iteracao < gatilhoMomentum]; // ? 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],
nome:p.nome,
Cluster:p.Cluster}:
{x:Y[i][0],
y:Y[i][1],
nome:p.nome,
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
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