Skip to content

Instantly share code, notes, and snippets.

@invisprints
invisprints / nmi.m
Created March 12, 2022 06:13
Normalized Mutual Information (NMI)
function z = nmi(x, y)
% Compute normalized mutual information I(x,y)/sqrt(H(x)*H(y)) of two discrete variables x and y.
% Input:
% x, y: two integer vector of the same length
% Ouput:
% z: normalized mutual information z=I(x,y)/sqrt(H(x)*H(y))
% Written by Mo Chen (sth4nth@gmail.com).
assert(numel(x) == numel(y));
n = numel(x);
x = reshape(x,1,n);