test_class.declarator: computation = new InformationContentComputation(ontology)
test_class.modifier: private final
test_class.original_string: private final InformationContentComputation computation = new InformationContentComputation(ontology);
test_class.type: InformationContentComputation
test_class.var_name: computation
test_class.file: phenol-core/src/test/java/org/monarchinitiative/phenol/ontology/algo/InformationContentComputationTest.java
test_class.identifier: InformationContentComputationTest
test_class.superclass: extends VegetableOntologyTestBase
test_case.body: @Test
    void test() {
      Map<TermId, Collection<TermId>> termLabels = TermAnnotations.constructTermAnnotationToLabelsMap(ontology, recipeAnnotations);
      Map<TermId, Double> informationContent = computation.computeInformationContent(termLabels);
  
      assertEquals(7, informationContent.size());
  
      assertEquals(0.0, informationContent.get(idVegetable), 0.001);
      assertEquals(0.0, informationContent.get(idRootVegetable), 0.001);
      assertEquals(0.405, informationContent.get(idLeafVegetable), 0.001);
      assertEquals(0.405, informationContent.get(idCarrot), 0.001);
      assertEquals(0.405, informationContent.get(idBeet), 0.001);
      assertEquals(0.405, informationContent.get(idPumpkin), 0.001);
      assertEquals(1.099, informationContent.get(idBlueCarrot), 0.01);
    }
test_case.class_method_signature: InformationContentComputationTest.test()
test_case.full_signature: @Test void test()
test_case.identifier: test
test_case.invocations: constructTermAnnotationToLabelsMap computeInformationContent assertEquals size assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void test()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(InformationContentComputation.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(InformationContentComputation.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: ontology
focal_class.modifier: private final
focal_class.original_string: private final Ontology ontology;
focal_class.type: Ontology
focal_class.var_name: ontology
focal_class.file: phenol-core/src/main/java/org/monarchinitiative/phenol/ontology/algo/InformationContentComputation.java
focal_class.identifier: InformationContentComputation
focal_class.class_method_signature: InformationContentComputation.InformationContentComputation(Ontology ontology)
focal_class.full_signature: public  InformationContentComputation(Ontology ontology)
focal_class.identifier: InformationContentComputation
focal_class.modifiers: public
focal_class.parameters: (Ontology ontology)
focal_class.signature:  InformationContentComputation(Ontology ontology)
focal_class.class_method_signature: InformationContentComputation.computeInformationContent(Map<TermId, Collection<TermId>> termLabels)
focal_class.full_signature: public Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels)
focal_class.identifier: computeInformationContent
focal_class.modifiers: public
focal_class.parameters: (Map<TermId, Collection<TermId>> termLabels)
focal_class.return: Map<TermId, Double>
focal_class.signature: Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels)
focal_class.class_method_signature: InformationContentComputation.caculateInformationContent(double maxFreq, Map<TermId, Integer> termToFrequency)
focal_class.full_signature: private Map<TermId, Double> caculateInformationContent(double maxFreq, Map<TermId, Integer> termToFrequency)
focal_class.identifier: caculateInformationContent
focal_class.modifiers: private
focal_class.parameters: (double maxFreq, Map<TermId, Integer> termToFrequency)
focal_class.return: Map<TermId, Double>
focal_class.signature: Map<TermId, Double> caculateInformationContent(double maxFreq, Map<TermId, Integer> termToFrequency)
focal_class.class_method_signature: InformationContentComputation.mostInformativeCommonAncestor(TermId t1, TermId t2, Ontology ontology, Map<TermId, Double> term2ic)
focal_class.full_signature: public static TermId mostInformativeCommonAncestor(TermId t1, TermId t2, Ontology ontology, Map<TermId, Double> term2ic)
focal_class.identifier: mostInformativeCommonAncestor
focal_class.modifiers: public static
focal_class.parameters: (TermId t1, TermId t2, Ontology ontology, Map<TermId, Double> term2ic)
focal_class.return: TermId
focal_class.signature: TermId mostInformativeCommonAncestor(TermId t1, TermId t2, Ontology ontology, Map<TermId, Double> term2ic)
focal_method.body: public Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels) {
      LOGGER.info(
          "Computing IC of {} terms using {} labels...",
              ontology.countAllTerms(), termLabels.values().stream().mapToInt(Collection::size).sum()
          );
  
      // Build mapping from TermId -> absolute frequency
      // Ought to use ontology.getRootTermId() ?
      final TermId root = ontology.getRootTermId();//TermId.of("HP:0000118");
  
      final Map<TermId, Integer> termToFrequency = new HashMap<>();
      for (TermId termId : ontology.getNonObsoleteTermIds()) {
        termToFrequency.put(termId, 0);
      }
      for (Entry<TermId, Collection<TermId>> e : termLabels.entrySet()) {
        termToFrequency.put(e.getKey(), e.getValue().size());
      }
  
      // Compute information content for each TermId
      final int maxFreq = termToFrequency.get(root);
      final Map<TermId, Double> termToInformationContent = caculateInformationContent(maxFreq, termToFrequency);
  
      // Fix terms with IC of zero, set it to IC of root
      int countIcZero = 0;
      final double dummyIc = -Math.log(1 / (double) maxFreq);
  
      for (Term t : ontology.getTerms()) {
        if (t.isObsolete()) {
          continue;
        }
        if (!termToFrequency.containsKey(t.getId())) {
          ++countIcZero;
          termToInformationContent.put(t.getId(), dummyIc);
        }
      }
  
      if (countIcZero > 0) {
        LOGGER.warn(
            "Frequency of {} non-obsolete terms was zero! Their IC has been set to {} =  - log(1 / {}).", countIcZero, dummyIc, maxFreq);
      }
      LOGGER.info("Computing IC is complete.");
  
      return termToInformationContent;
    }
focal_method.class_method_signature: InformationContentComputation.computeInformationContent(Map<TermId, Collection<TermId>> termLabels)
focal_method.full_signature: public Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels)
focal_method.identifier: computeInformationContent
focal_method.invocations: info countAllTerms sum mapToInt stream values getRootTermId getNonObsoleteTermIds put entrySet put getKey size getValue get caculateInformationContent log getTerms isObsolete containsKey getId put getId warn info
focal_method.modifiers: public
focal_method.parameters: (Map<TermId, Collection<TermId>> termLabels)
focal_method.return: Map<TermId, Double>
focal_method.signature: Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels)