Package edu.msu.cme.rdp.classifier

Examples of edu.msu.cme.rdp.classifier.TrainingInfo


    public synchronized static ClassifierFactory getFactory(String gene) throws IOException, TrainingDataException {
        if (!classifierFactoryMap.containsKey(gene)) {

            if (relativePath) {
                ClassifierFactory factory = new ClassifierFactory(gene);
                factory.trainingInfo = new TrainingInfo();

                InputStreamReader in = new InputStreamReader(ClassifierFactory.class.getResourceAsStream(dataDir + gene + "/" + convert("probabilityList")));
    try {
        factory.trainingInfo.createGenusWordProbList(in);
    } finally {
View Full Code Here


     * Returns a factory with the training information for the non-default training data files.
     */
    private static ClassifierFactory getNonDefaultFactory(String gene) throws IOException, TrainingDataException {
        if (classifierFactoryMap.get(gene) == null) {
            ClassifierFactory factory = new ClassifierFactory(gene);
            factory.trainingInfo = new TrainingInfo();
            String filename = parentPath + File.separatorChar + convert("probabilityList");

            FileReader in = new FileReader(filename);
            factory.trainingInfo.createGenusWordProbList(in);
            // the tree information has to be read after at least one of the other
View Full Code Here

    public void testCreateLogWordPriorArr() throws Exception{
        System.out.println("testCreateLogWordPriorArr");
        InputStream dstream = System.class.getResourceAsStream("/test/classifier/testLogWordPrior.txt");
        Reader in =  new InputStreamReader( dstream );
       
        TrainingInfo train = new TrainingInfo();
        train.createLogWordPriorArr(in);
        float wordPrior = train.getLogWordPrior(10);
        assertEquals(wordPrior, -2.77, 0.1);
        wordPrior = train.getLogWordPrior(55);
        assertEquals(wordPrior, -1.67, 0.1);
       
        // test getWordPairPriorDiff()
        wordPrior = train.getLogWordPrior(24573);
        assertEquals(wordPrior, -2.77, 0.01);
        float revWordPrior = train.getLogWordPrior(10912);
        assertEquals(revWordPrior, -1.67, 0.01);       
       
        float wordPriorDiff = train.getWordPairPriorDiff(24573);
        assertEquals(wordPriorDiff, (wordPrior - revWordPrior), 0.01);
        float revWordPriorDiff = train.getWordPairPriorDiff(10912);
        assertEquals(revWordPriorDiff, (revWordPrior - wordPrior), 0.01);
        assertEquals( (wordPriorDiff + revWordPriorDiff), 0, 0.01);
       
    }
View Full Code Here

    /** Test of createGenusWordProbLis method, of class classification.TrainingInfo. */
    public void testCreateGenusWordProbList() throws Exception{
        System.out.println("testCreateGenusWordConditionalProbList");
        InputStream dstream = System.class.getResourceAsStream("/test/classifier/testGenus_probList.txt");
        Reader in =  new InputStreamReader( dstream );
        TrainingInfo train = new TrainingInfo();
        train.createGenusWordProbList(in);
        GenusWordConditionalProb gProb = train.getWordConditionalProbObject(8);
        int genusIndex = gProb.getGenusIndex();
        float prob = gProb.getProbability();
        assertEquals(genusIndex, 4);
        assertEquals(prob, -0.15, 0.1);
       
        gProb = train.getWordConditionalProbObject(1865);
        genusIndex = gProb.getGenusIndex();
        prob = gProb.getProbability();
        assertEquals(genusIndex, 0);
        assertEquals(prob, -0.5, 0.1);
       
View Full Code Here

    /** Test of makeProbIndexArr method, of class classification.TrainingInfo. */
    public void testCreateProbIndexArr() throws Exception {
        System.out.println("testCreateProbIndexArr");
        InputStream dstream = System.class.getResourceAsStream("/test/classifier/testProbIndex.txt");
        Reader in =  new InputStreamReader( dstream );
        TrainingInfo train = new TrainingInfo();
        train.createProbIndexArr(in);
        int start = train.getStartIndex(100);
        int stop = train.getStopIndex(65535);
        assertEquals(start, 1);
        assertEquals(stop, 1866);
       
    }
View Full Code Here

    }
   
    /** 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()
View Full Code Here

TOP

Related Classes of edu.msu.cme.rdp.classifier.TrainingInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.