示例#1
0
def test_BeagleContextMulti():

    from vsm.util.corpustools import random_corpus
    from vsm.model.beagleenvironment import BeagleEnvironment

    ec = random_corpus(100000, 5000, 0, 20, context_type='sentence')
    cc = ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,5000,100)])

    e = BeagleEnvironment(ec, n_cols=200)
    e.train()

    m = BeagleContextMulti(cc, ec, e.matrix)
    m.train(n_procs=3)

    from tempfile import NamedTemporaryFile
    import os

    try:
        tmp = NamedTemporaryFile(delete=False, suffix='.npz')
        m.save(tmp.name)
        tmp.close()
        m1 = BeagleContextMulti.load(tmp.name)
        assert (m.matrix == m1.matrix).all()
    
    finally:
        os.remove(tmp.name)

    return m.matrix
示例#2
0
def test_BeagleOrderMulti():

    from vsm.util.corpustools import random_corpus
    from vsm.model.beagleenvironment import BeagleEnvironment

    c = random_corpus(1000, 50, 0, 20, context_type='sentence')

    e = BeagleEnvironment(c, n_cols=100)
    e.train()

    m = BeagleOrderMulti(c, e.matrix)
    m.train(4)

    from tempfile import NamedTemporaryFile
    import os

    try:
        tmp = NamedTemporaryFile(delete=False, suffix='.npz')
        m.save(tmp.name)
        tmp.close()
        m1 = BeagleOrderMulti.load(tmp.name)
        assert (m.matrix == m1.matrix).all()
    
    finally:
        os.remove(tmp.name)

    return m.matrix
示例#3
0
    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq
        from vsm.model.beaglecomposite import BeagleComposite

        ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        cc = ec.apply_stoplist(stoplist=[str(i) for i in range(0, 50, 7)])
        e = BeagleEnvironment(ec, n_cols=5)
        e.train()

        cm = BeagleContextSeq(cc, ec, e.matrix)
        cm.train()

        om = BeagleOrderSeq(ec, e.matrix)
        om.train()

        m = BeagleComposite(cc, cm.matrix, ec, om.matrix)
        m.train()

        self.venv = BeagleViewer(ec, e)
        self.vctx = BeagleViewer(cc, cm)
        self.vord = BeagleViewer(ec, om)
        self.vcom = BeagleViewer(cc, m)
示例#4
0
class TestBeagleOrder(unittest.TestCase):
    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.c = random_corpus(1000, 50, 0, 10, context_type='sentence')

        self.e = BeagleEnvironment(self.c, n_cols=100)
        self.e.train()

        self.ms = BeagleOrderSeq(self.c, self.e.matrix)
        self.ms.train()
        '''
        self.mm = BeagleOrderMulti(self.c, self.e.matrix)
        self.mm.train(2)
        '''

    def test_BeagleOrderSeq(self):
        from tempfile import NamedTemporaryFile
        import os

        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.ms.save(tmp.name)
            tmp.close()
            m1 = BeagleOrderSeq.load(tmp.name)
            self.assertTrue((self.ms.matrix == m1.matrix).all())

        finally:
            os.remove(tmp.name)

    '''
示例#5
0
    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq
        from vsm.model.beaglecomposite import BeagleComposite

        ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        cc = ec.apply_stoplist(stoplist=[str(i) for i in range(0,50,7)])
        e = BeagleEnvironment(ec, n_cols=5)
        e.train()

        cm = BeagleContextSeq(cc, ec, e.matrix)
        cm.train()

        om = BeagleOrderSeq(ec, e.matrix)
        om.train()

        m = BeagleComposite(cc, cm.matrix, ec, om.matrix)
        m.train()

        self.venv = BeagleViewer(ec, e)
        self.vctx = BeagleViewer(cc, cm)
        self.vord = BeagleViewer(ec, om)
        self.vcom = BeagleViewer(cc, m)
示例#6
0
    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.c = random_corpus(1000, 50, 0, 10, context_type='sentence')

        self.e = BeagleEnvironment(self.c, n_cols=100)
        self.e.train()

        self.ms = BeagleOrderSeq(self.c, self.e.matrix)
        self.ms.train()
        '''
示例#7
0
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecontext import BeagleContextSeq, BeagleContextMulti
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.ec = random_corpus(1000, 50, 0, 5, context_type='sentence')
        self.cc = self.ec.apply_stoplist(
            stoplist=[str(i) for i in range(0, 50, 7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.ms = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.ms.train()
        '''
示例#8
0
def test_compare():

    from vsm.util.corpustools import random_corpus
    from vsm.model.beagleenvironment import BeagleEnvironment

    ec = random_corpus(100000, 5000, 0, 20, context_type='sentence')
    cc = ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,5000,100)])

    e = BeagleEnvironment(ec, n_cols=5)
    e.train()

    print 'Training single processor model'
    ms = BeagleContextSeq(cc, ec, e.matrix)
    ms.train()

    print 'Training multiprocessor model'
    mm = BeagleContextMulti(cc, ec, e.matrix)
    mm.train()

    assert np.allclose(ms.matrix, mm.matrix)
示例#9
0
class TestBeagleComposite(unittest.TestCase):

    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecomposite import BeagleComposite 
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq

        self.ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        self.cc = self.ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,50,7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.cm = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.cm.train()

        self.om = BeagleOrderSeq(self.ec, self.e.matrix)
        self.om.train()

        self.m = BeagleComposite(self.cc, self.cm.matrix, self.ec, self.om.matrix)
        self.m.train()


    def test_BeagleCompositeIO(self):
        from tempfile import NamedTemporaryFile
        from vsm.model.beaglecomposite import BeagleComposite 
        import os

        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.m.save(tmp.name)
            tmp.close()
            m1 = BeagleComposite.load(tmp.name)
            self.assertTrue((self.m.matrix == m1.matrix).all())
    
        finally:
            os.remove(tmp.name)
示例#10
0
    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.c = random_corpus(1000, 50, 0, 10, context_type='sentence')

        self.e = BeagleEnvironment(self.c, n_cols=100)
        self.e.train()

        self.ms = BeagleOrderSeq(self.c, self.e.matrix)
        self.ms.train()
        '''
示例#11
0
class TestBeagleComposite(unittest.TestCase):
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecomposite import BeagleComposite
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq

        self.ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        self.cc = self.ec.apply_stoplist(
            stoplist=[str(i) for i in range(0, 50, 7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.cm = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.cm.train()

        self.om = BeagleOrderSeq(self.ec, self.e.matrix)
        self.om.train()

        self.m = BeagleComposite(self.cc, self.cm.matrix, self.ec,
                                 self.om.matrix)
        self.m.train()

    def test_BeagleCompositeIO(self):
        from tempfile import NamedTemporaryFile
        from vsm.model.beaglecomposite import BeagleComposite
        import os

        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.m.save(tmp.name)
            tmp.close()
            m1 = BeagleComposite.load(tmp.name)
            self.assertTrue((self.m.matrix == m1.matrix).all())

        finally:
            os.remove(tmp.name)
示例#12
0
class TestBeagleContext(unittest.TestCase):

    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecontext import BeagleContextSeq, BeagleContextMulti 
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.ec = random_corpus(1000, 50, 0, 5, context_type='sentence')
        self.cc = self.ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,50,7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.ms = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.ms.train()
        '''
        self.mm = BeagleContextMulti(self.cc, self.ec, self.e.matrix)
        self.mm.train(n_procs=2)
        '''


    def test_BeagleContextSeq(self):
        from tempfile import NamedTemporaryFile
        import os

        from vsm.model.beaglecontext import BeagleContextSeq 
        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.ms.save(tmp.name)
            tmp.close()
            m1 = BeagleContextSeq.load(tmp.name)
            self.assertTrue((self.ms.matrix == m1.matrix).all())
    
        finally:
            os.remove(tmp.name)


    '''
示例#13
0
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecomposite import BeagleComposite
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq

        self.ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        self.cc = self.ec.apply_stoplist(
            stoplist=[str(i) for i in range(0, 50, 7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.cm = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.cm.train()

        self.om = BeagleOrderSeq(self.ec, self.e.matrix)
        self.om.train()

        self.m = BeagleComposite(self.cc, self.cm.matrix, self.ec,
                                 self.om.matrix)
        self.m.train()
示例#14
0
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecontext import BeagleContextSeq, BeagleContextMulti 
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.ec = random_corpus(1000, 50, 0, 5, context_type='sentence')
        self.cc = self.ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,50,7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.ms = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.ms.train()
        '''
示例#15
0
def test_compare():

    from vsm.util.corpustools import random_corpus
    from vsm.model.beagleenvironment import BeagleEnvironment

    c = random_corpus(1000, 100, 0, 20, context_type='sentence')

    e = BeagleEnvironment(c, n_cols=5)
    e.train()

    psi = rand_pt_unit_sphere(e.shape[1])

    rand_perm = two_rand_perm(e.shape[1])

    print 'Training single processor model'
    ms = BeagleOrderSeq(c, e.matrix, psi=psi, rand_perm=rand_perm)
    ms.train()

    print 'Training multiprocessor model'
    mm = BeagleOrderMulti(c, e.matrix, psi=psi, rand_perm=rand_perm)
    mm.train()

    assert np.allclose(ms.matrix, mm.matrix), (ms.matrix, mm.matrix)
示例#16
0
def test_BeagleComposite():

    from vsm.util.corpustools import random_corpus
    from vsm.model.beagleenvironment import BeagleEnvironment
    from vsm.model.beaglecontext import BeagleContextSeq
    from vsm.model.beagleorder import BeagleOrderSeq

    ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
    cc = ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,50,7)])

    e = BeagleEnvironment(ec, n_cols=5)
    e.train()

    cm = BeagleContextSeq(cc, ec, e.matrix)
    cm.train()

    om = BeagleOrderSeq(ec, e.matrix)
    om.train()

    m = BeagleComposite(cc, cm.matrix, ec, om.matrix)
    m.train()

    from tempfile import NamedTemporaryFile
    import os

    try:
        tmp = NamedTemporaryFile(delete=False, suffix='.npz')
        m.save(tmp.name)
        tmp.close()
        m1 = BeagleComposite.load(tmp.name)
        assert (m.matrix == m1.matrix).all()
    
    finally:
        os.remove(tmp.name)

    return m.matrix
示例#17
0
class TestBeagleContext(unittest.TestCase):
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecontext import BeagleContextSeq, BeagleContextMulti
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.ec = random_corpus(1000, 50, 0, 5, context_type='sentence')
        self.cc = self.ec.apply_stoplist(
            stoplist=[str(i) for i in range(0, 50, 7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.ms = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.ms.train()
        '''
        self.mm = BeagleContextMulti(self.cc, self.ec, self.e.matrix)
        self.mm.train(n_procs=2)
        '''

    def test_BeagleContextSeq(self):
        from tempfile import NamedTemporaryFile
        import os

        from vsm.model.beaglecontext import BeagleContextSeq
        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.ms.save(tmp.name)
            tmp.close()
            m1 = BeagleContextSeq.load(tmp.name)
            self.assertTrue((self.ms.matrix == m1.matrix).all())

        finally:
            os.remove(tmp.name)

    '''
示例#18
0
class TestBeagleOrder(unittest.TestCase):

    def setUp(self):

        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beagleenvironment import BeagleEnvironment

        self.c = random_corpus(1000, 50, 0, 10, context_type='sentence')

        self.e = BeagleEnvironment(self.c, n_cols=100)
        self.e.train()

        self.ms = BeagleOrderSeq(self.c, self.e.matrix)
        self.ms.train()
        '''
        self.mm = BeagleOrderMulti(self.c, self.e.matrix)
        self.mm.train(2)
        '''


    def test_BeagleOrderSeq(self):
        from tempfile import NamedTemporaryFile
        import os

        try:
            tmp = NamedTemporaryFile(delete=False, suffix='.npz')
            self.ms.save(tmp.name)
            tmp.close()
            m1 = BeagleOrderSeq.load(tmp.name)
            self.assertTrue((self.ms.matrix == m1.matrix).all())
    
        finally:
            os.remove(tmp.name)


    '''
示例#19
0
    def setUp(self):
        from vsm.corpus.util.corpusbuilders import random_corpus
        from vsm.model.beaglecomposite import BeagleComposite 
        from vsm.model.beagleenvironment import BeagleEnvironment
        from vsm.model.beaglecontext import BeagleContextSeq
        from vsm.model.beagleorder import BeagleOrderSeq

        self.ec = random_corpus(1000, 50, 0, 20, context_type='sentence')
        self.cc = self.ec.apply_stoplist(stoplist=[str(i) for i in xrange(0,50,7)])

        self.e = BeagleEnvironment(self.ec, n_cols=5)
        self.e.train()

        self.cm = BeagleContextSeq(self.cc, self.ec, self.e.matrix)
        self.cm.train()

        self.om = BeagleOrderSeq(self.ec, self.e.matrix)
        self.om.train()

        self.m = BeagleComposite(self.cc, self.cm.matrix, self.ec, self.om.matrix)
        self.m.train()