Public
Edited
Nov 30, 2022
Insert cell
# Entropies
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
output = {
const min = Math.min;
const n = histogram.length;
const a = Array(n).fill(0);
const Entropy = (A, B) => {
return Shannon(A) + Shannon(B);
};
const Albuquerque = (A, B) => {
const tA = Tsallis(A, q);
const tB = Tsallis(B, q);
return tA + tB + (1 - q) * tA * tB;
};
const Nie = (A, B) => {
return Masi(A, r) + Masi(B, r);
};
const LinOu = (A, B) => {
return min(Shannon(A), Tsallis(B, q));
};
const OuLin = (A, B) => {
return min(Tsallis(A, q), Shannon(B));
};
const MasiTsallis = (A, B) => {
return min(Masi(A, r), Tsallis(B, q));
};
const TsallisMasi = (A, B) => {
return min(Tsallis(A, q), Masi(B, r));
};
const methods = {
Entropy: Entropy,
Albuquerque: Albuquerque,
Nie: Nie,
LinOu: LinOu,
OuLin: OuLin,
MasiTsallis: MasiTsallis,
TsallisMasi: TsallisMasi
};
const method = methods[methodName];
for (let t = 1; t < n - 1; ++t) {
const A = histogram.slice(0, t);
const B = histogram.slice(t);
a[t] = method(A, B);
}
return a;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function pdf(counts) {
let sum = counts.reduce((s, a) => s + a, 0);
sum = sum == 0 ? 1 : sum;
return counts.map((a) => a / sum);
}
Insert cell
function cdf(counts) {
let sum = 0;
let a = counts.map((x) => (sum += x));
sum = sum == 0 ? 1 : sum;
return a.map((x) => x / sum);
}
Insert cell
function Shannon(counts) {
let p = pdf(counts);
return -p.reduce((s, x) => s + (x == 0 ? 0 : x * Math.log(x)), 0);
}
Insert cell
function Tsallis(counts, q) {
let p = pdf(counts);
let s = p.reduce((s, x) => s + x ** q, 0);
return s == 0 ? 0 : (1 - s) / (q - 1);
}
Insert cell
function Masi(counts, r) {
let h = Shannon(counts);
return 1 + (1 - r) * h > 0 ? Math.log(1 + (1 - r) * h) / (1 - r) : 0;
// : Math.log(-1 - (1 - r) * h) / (1 - r);
//return Log(1 + (1 - r) * h) / (1 - r);
}
Insert cell
function Normal(mu, sigma, x) {
return (
(1 / (sigma * Math.sqrt(2 * Math.PI))) *
Math.exp(-0.5 * ((x - mu) / sigma) ** 2)
);
}
Insert cell
function Cauchy(x0, gamma, x) {
return gamma / Math.PI / ((x - x0) ** 2 + gamma ** 2);
}
Insert cell
arr = {
const n = 256;
return new Uint8ClampedArray(n * n * 4);
}
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