예제 #1
0
def big():
    def custom(sfrom, sto):
        label = sto
        w = random()
        if sto % 101 != 1:
            w += randint(5,15)
        return label, w

    t0 = time()
    f = network_fsa(20, 400, arc = custom)
    t1 = time()
    print 'Big: states %d arcs %d time %f' % (len(f), f.num_arcs(), t1-t0)
    return f
예제 #2
0
def small():
    A = defaultdict(lambda : defaultdict(int))
    A[0][1] = [1, 2]
    A[0][2] = [2, 1]
    A[1][3] = [3, 2]
    A[1][4] = [4, 4]
    A[2][3] = [5, 6]
    A[2][4] = [6, 2]
    A[3][5] = [7, 1]
    A[4][5] = [8, 2]
    
    t0 = time()
    f = network_fsa(2, 2, arc = lambda sfrom, sto: A[sfrom][sto])
    t1 = time()
    print 'Small: states %d arcs %d time %f' % (len(f), f.num_arcs(), t1-t0)
    return f
예제 #3
0
파일: util.py 프로젝트: wilkeraziz/pyfst
from pyfst.algorithm.util import draw, path_fsa, make_fsa, network_fsa

p = path_fsa([10, 20, 30])
draw(p, 'util-path')
wp = path_fsa([(1,10), (2,20), (3,30)], weights = [0.5, 0.6, 0.7], label = lambda pair: pair[1])
draw(wp, 'util-wpath')

wfsa = make_fsa(6, 0, 5, sort = True,
        arcs = [
            (0,1,1,1),
            (0,2,2,1),
            (1,3,3,2),
            (1,4,4,4),
            (2,3,3,2.5),
            (2,4,4,5),
            (3,5,5,1),
            (4,5,5,1)
            ])
draw(wfsa, 'util-wfsa')

net = network_fsa(3,3)
draw(net, 'util-net')