}
/** Test of getRootTree method, of class classification.TrainingInfo. */
public void testCreateClassifier() throws Exception{
System.out.println("testCreateClassifier");
TrainingInfo train = new TrainingInfo();
InputStream dstream = System.class.getResourceAsStream("/test/classifier/testGenus_probList.txt");
Reader in = new InputStreamReader( dstream );
train.createGenusWordProbList(in);
dstream = System.class.getResourceAsStream("/test/classifier/test_bergeyTrainingTree.xml");
in = new InputStreamReader( dstream );
train.createTree(in);
dstream = System.class.getResourceAsStream("/test/classifier/testProbIndex.txt");
in = new InputStreamReader( dstream );
train.createProbIndexArr(in);
dstream = System.class.getResourceAsStream("/test/classifier/testLogWordPrior.txt");
in = new InputStreamReader( dstream );
train.createLogWordPriorArr(in);
int genusNodeListSize = train.getGenusNodeListSize();
assertEquals(genusNodeListSize, 6);
HierarchyTree genusNode = train.getGenusNodebyIndex(3);
assertEquals(genusNode.getGenusIndex(), 3);
assertEquals(genusNode.getName(), "Pseudomonas");
int leaveCount = genusNode.getLeaveCount();
float logLeaveCount = train.getLogLeaveCount(1);
assertEquals((double)leaveCount, Math.exp(logLeaveCount) -1, 0.1);
HierarchyTree rootTree = train.getRootTree();
assertEquals(rootTree.getName(), "Bacteria");
assertNotNull( rootTree.getSubclasses());
Classifier aClassifier = train.createClassifier();
//test addConfidence()
HashMap<HierarchyTree, RankAssignment> determinedMap = new HashMap <HierarchyTree, RankAssignment>();
HierarchyTree determinedGenusNode = train.getGenusNodebyIndex(4);
HierarchyTree Enterobacteriales = determinedGenusNode.getParent().getParent();
HierarchyTree Gammaproteobacteria = Enterobacteriales.getParent();
HierarchyTree aNode = determinedGenusNode;
while (aNode != null){
determinedMap.put(aNode, new RankAssignment(aNode, 0));
aNode = aNode.getParent();
}
HierarchyTree bestNode = train.getGenusNodebyIndex(1); // Vibrio
aClassifier.addConfidence(bestNode, determinedMap);
assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 0.0f, 0.0001); //Enterobacter
assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 0.0f, 0.0001); //Enterobacteriales
assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 1.0f, 0.0001); //Gammaproteobacteria
bestNode = train.getGenusNodebyIndex(4); //Enterobacter
aClassifier.addConfidence(bestNode, determinedMap);
assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 1.0f, 0.0001); //Enterobacter
assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 1.0f, 0.0001); //Enterobacteriales
assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 2.0f, 0.0001); //Gammaproteobacteria
aClassifier.addConfidence(train.getGenusNodebyIndex(4), determinedMap); //Enterobacter
aClassifier.addConfidence(train.getGenusNodebyIndex(0), determinedMap); //Clostridium
assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 2.0f, 0.0001); //Enterobacter
assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 2.0f, 0.0001); //Enterobacteriales
assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 3.0f, 0.0001); //Gammaproteobacteria
assertEquals( determinedMap.get(rootTree).getConfidence(), 4.0f, 0.0001); //Bacteria
// end test addConfidence()