Esempio n. 1
0
def loadForest():
    npic=0
    forest=[]
    for root, dirs, files in os.walk(rootdir):
        for f in files:
            if f.endswith('pic'):
                npic=npic+1
                print f
                #reading the tree pickle file
                pickleFile = open(rootdir + "/" + f, 'rb')
                root = pickle.load(pickleFile)
                pickleFile.close()
                #init the test tree
                t=tree()
                t.settree(root)
                forest.append(t)
    return forest,npic
Esempio n. 2
0
def recall(dsetname='ss', rfile=''):
    ts=time.time()
    strtime=datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    print("Starting time: "+strtime)
    
    #reading the tree pickle file
    pickleFile = open(rfile, 'rb')
    root = pickle.load(pickleFile)
    pickleFile.close()
    #init the test tree
    t=tree()
    t.settree(root)
    print("----main::recall::loadtree") 
    ts=timestamp(ts)
    
    #compute recall rate
    loader= imp.load_source('dataset', dsetname+'.py')
    dset=loader.dataset()
    correct=0;
    for x in xrange(dset.size):
        cL=dset.getL(x)
#print prob
        p=t.getP(np.array([x]),dset)
        ids = p.argsort()[::-1][:3]
        L=ids[0]        
        
#print max likelihood
        #L=t.getL(np.array([x]),dset)
        
        if  cL== L:
            correct=correct+1
            if cL!=0:
                print("\n%03d: correct L"%cL)
                for i in xrange(len(ids)):
                    print("%03d_%03d"%(ids[i],100*p[ids[i]])),

        dset.setL(x,L)
    print("recall rate: {}%".format(correct/float(dset.size)*100))
    print("----main::recall::evaluate") 
    ts=timestamp(ts)
    return t, dset
Esempio n. 3
0
def recall(dsetname='dataset_pickle', rfile='',mylog=None):
    mylog.current("recall")
    
    #reading the tree pickle file
    pickleFile = open(rfile, 'rb')
    root = pickle.load(pickleFile)
    pickleFile.close()
    #init the test tree
    t=tree()
    t.settree(root)
    print(mylog.finished("main::train>> loading tree"))
    
    #compute recall rate
    loader= imp.load_source('dataset', dsetname+'.py')
    dset=loader.dataset()
    print(mylog.finished("main::train>> loading dset\ndataset: %s"%dset))
    conf=np.zeros((dset.clmax,dset.clmax)) 
    correct=0;
    for x in xrange(dset.size):
        cL=dset.getL(x)#cL:correct label
#print prob
        p=t.getP(np.array([x]),dset)
        ids = p.argsort()[::-1][:3]
        L=ids[0]        
        
#print max likelihood
        #L=t.getL(np.array([x]),dset)
        
        if  cL== L:
            correct=correct+1
        conf[L,cL]=conf[L,cL]+1
 #       print("\n%03d: correct L"%cL)
 #       for i in xrange(len(ids)):
 #           print("%03d_%03d"%(ids[i],100*p[ids[i]])),

        dset.setL(x,L)
    print(mylog.finished("main::train>> classifying\nrecall rate: {}%".format(correct/float(dset.size)*100)))
    print(mylog.finished("main::train>> classifying\nconfusion matrix: \n{}".format(conf)))
    return t, dset
Esempio n. 4
0
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 24 03:21:34 2015

@author: Wasit
"""
import pickle
from sctree import tree
import numpy as np
import codecs

with open('root.pic', 'rb') as pickleFile:
    root = pickle.load(pickleFile)
    
#init the test tree
t=tree()
t.settree(root)
t.show()

pattern=np.zeros(10,dtype=np.int32)
p=t.classify(pattern)
newtext=unicode("")
mincode=3585
for i in xrange(100):
    nextchar=p.argsort()[::-1][0]
    newtext+=unichr( nextchar + mincode)
    pattern=np.roll(pattern,-1)
    pattern[-1]=nextchar
    p=t.classify(pattern)

print 'writing text'