File Exchange

image thumbnail

Normalized Mutual Information

version (734 Bytes) by Mo Chen
Fully vectorized implementation NMI. NMI is often used for evaluating clustering results.


Updated 07 Mar 2016

View License

Normalized mutual information is often used for evaluating clustering results, information retrieval, feature selection etc. This is a optimized implementation of the function which has no for loops.
This function is now a part of the PRML toolbox (

Cite As

Mo Chen (2021). Normalized Mutual Information (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)

Ali Komai


Bryar Hassan

I am wondering to ask why the result is always 0 or 1? NMI result should be [0,1]. The code seems buggy! Anyone could please give some examples to show the validity of the code?

Katerina Tzimourta

Ruo-chen Jiang

ahmed silik

I need description of the inputs especially the function sparse

Albert Pun

Would appreciate more comments and some examples

Sowmya Ravindra

I am trying to find similarities between two signals obtained from two different modalities and sampling frequencies.Hence tried the mutual information code. but i get an error : 'Error using sparse
Sparse matrix sizes must be non-negative integers less than MAXSIZE as defined by COMPUTER. Use HELP COMPUTER for more details.

Error in nmi (line 20)
Mx = sparse(idx,x,1,n,k,n);'

Please help me correct this error.

samira rahimi


Why is it important to verify the integrity of results, i.e. length(labels)==length(results)?

Isn't it possible to use nmi for clustering with k that is different from number of labels?

I changed the script for my use so that it will accept this. should I upload?

Jianxiong Chen

please add more comments, especially for the inputs. Thanks

bao dinh


Kelvin Wong

It doesn't work for large matrix as it rans out of memory in line 16 and 17.


Eric Chen

grateful if more comments provided

Artur Abdullin

Good job, I used your function to validate mine :). Sometime in research you cannot trust even yourself.

Md. Ali Hossain

Can you give a detailed docomented .m file so that we can have a easy understanding of NMI.



I agree, an example... and a little description of the inputs would be strongly appreciated! Thank you!


Could you provide some examples of running your code to prove it is correct?

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!