title: Mathematical formula to a recursive method
body: <p>I need to implement current formula.It is for scoring the nodes in a taxonomy. Basically, the score of a node depends on the amount of child nodes and their scores (<code>(nodes(h+1))</code> is the amount of nodes on the next level and <code>Cl(concept)</code> is a set of children).</p>
  
  <p><a href="https://i.stack.imgur.com/dCC7i.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dCC7i.gif" alt="Formula"></a></p>
  
  <p>In my usecase term frequencies are only defined for the leaves as of now. I have made an implementation, but the issue is that when there are 2 children for the node then the implementation only goes to one side.  </p>
  
  <p>For a given taxonomy:</p>
  
  <pre><code>     1
      / \
     2   3
     |   |
     4   17
    / \
   11 13
  </code></pre>
  
  <p>the frequencies are given: <code>freq(11) = 3</code>, <code>freq(13) = 5</code> and <code>freq(17) = 10</code>. When I try to get the score for <code>node(1)</code>, the result is <code>0.0</code>, because the recursion doesn't go into descendent <code>node(4)</code>, it retrieves only <code>freq(17)</code> and that's it. Normally, the result should be 7.</p>
  
  <p>Here is the implementation: </p>
  
  <pre><code>public static float calcScore(int keyID, Map&lt;Integer, Integer&gt; frequencies, Map&lt;Integer, Integer&gt; subTaxonomy) {
      float res = 0f;
      int nodes = 0;
      if (frequencies.containsKey(keyID)) {
          return frequencies.get(keyID) + 0f;
      }
  
      for (Map.Entry&lt;Integer, Integer&gt; entry : subTaxonomy.entrySet()) {
          if (entry.getValue() - 1 == subTaxonomy.get(keyID)) {
              nodes++;
              res += calcScore(entry.getKey(), frequencies, subTaxonomy);
          }
      }
      return 1 / nodes * res;
  }
  </code></pre>
  
  <p>NOTE:</p>
  
  <p><code>subTaxonomy</code> - stores the nodeID and its level in the taxonomy</p>
  
  <p><code>frequencies</code> - store the frequencies for leaf nodes.</p>
  
  <p>I also created a snippet at Ideone: <a href="https://ideone.com/kQegWQ" rel="nofollow noreferrer">Source</a></p>
  
  <p>How should I edit the code, so that it traverses all over the children for a given node?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So now, in updated source, it traverses all over taxonomy, but the result is 0.0 still. </p>