I need some help on these formulas implementation
<p>I need some help with implementing these formulas. I think I implemented them correctly but for some reason I don't get the expected results:</p>

<p><img src="http://i.stack.imgur.com/pOWn3.png" alt="enter image description here"></p>

<p>This is the code for NMI, I, and H functions respectively.
Are the formulas implemented correctly ?
Thanks</p>

<pre><code>int totalN = getTotalN(events);
        double h1 = H(clusters, totalN);
        double h2 = H(events, totalN);
        double valueI = I(clusters, events, totalN);
        double value_NMI = valueI / (double) ((h1 + h2) / (double) 2);
        System.out.println("NMI: " + value_NMI);

static public double I(HashMap&lt;String, ArrayList&lt;String&gt;&gt; clusters, HashMap&lt;String, ArrayList&lt;String&gt;&gt; events, int totalN) {

        //store sorted content to contents
        Iterator&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt; it = events.entrySet().iterator();
        Iterator&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt; it2 = clusters.entrySet().iterator();

        String key;
        ArrayList&lt;String&gt; event;
        ArrayList&lt;String&gt; cluster;

        double valueI = 0;
        while (it.hasNext()) {

            Map.Entry&lt;String, ArrayList&lt;String&gt;&gt; mapItem = it.next();
            key = mapItem.getKey();

            //if cluster doesn't exist
            //if(!clusters.containsKey(key)) continue;
            //cluster = clusters.get(key);

            event = mapItem.getValue();

            while (it2.hasNext()) {
                Map.Entry&lt;String, ArrayList&lt;String&gt;&gt; mapItem2 = it2.next();
                cluster = mapItem2.getValue();

            float common_docs = 0;
            for (int i=0; i&lt; event.size(); i++) {   
                for (int j=0; j&lt; cluster.size(); j++) { 
                    if (event.get(i).equals(cluster.get(j))) {
                        common_docs = common_docs + 1;
                        break;
                    }
                }
            }


            if (common_docs != 0) valueI = valueI + ( ( common_docs / (float) totalN) * Math.log((common_docs * totalN) / (float) (event.size() * cluster.size())) );       
            }
        }

        return valueI;
    }


    static public double H(HashMap&lt;String, ArrayList&lt;String&gt;&gt; clusters, int totalN) {

        //store sorted content to contents
        Iterator&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt; it = clusters.entrySet().iterator();
        ArrayList&lt;String&gt; cluster;

        double entropy = 0;
        while (it.hasNext()) {

            Map.Entry&lt;String, ArrayList&lt;String&gt;&gt; mapItem = it.next();
            cluster = mapItem.getValue();

            double ratio = cluster.size() / (float) totalN;
            entropy = entropy + ratio * Math.log(ratio);

        }

        return -entropy;
    }

    static public int getTotalN(HashMap&lt;String, ArrayList&lt;String&gt;&gt; dataset) {

        int totalN = 0;
        Iterator&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt; it = dataset.entrySet().iterator();
        ArrayList&lt;String&gt; item;

        while (it.hasNext()) {

            Map.Entry&lt;String, ArrayList&lt;String&gt;&gt; mapItem = it.next();
            item = mapItem.getValue();

            for (int i=0; i&lt; item.size(); i++) {
                totalN = totalN + 1;
            }

        }

        return totalN ;
    }
</code></pre>
