예제 #1
0
파일: cca.py 프로젝트: karlstratos/cca
def main(args):
    set_quiet(args.quiet)
    
    if args.corpus: 
        unigrams = count_unigrams(args.corpus)
        vocab, outfname = decide_vocab(unigrams, args.cutoff, 
                                       args.vocab, args.want)
        if args.rewrite: 
            rewrite_corpus(args.corpus, vocab, outfname)
        else:
            extract_stat(args.corpus, vocab, outfname, args.window)
    
    if args.stat:
        assert(args.m is not None and args.kappa is not None)
        if args.no_matlab:        
            C = canon()
            C.set_params(args.m, args.kappa)     
            C.get_stat(args.stat)
            C.start_logging()
            C.approx_cca()
            C.end_logging()
            C.write_result()
        else:
            call_matlab(args.stat, args.m, args.kappa)
        
    if args.clean: clean()
예제 #2
0
def main(args):
    set_quiet(args.quiet)

    if args.corpus:
        unigrams = count_unigrams(args.corpus)
        vocab, outfname = decide_vocab(unigrams, args.cutoff, args.vocab,
                                       args.want)
        if args.rewrite:
            rewrite_corpus(args.corpus, vocab, outfname)
        else:
            extract_stat(args.corpus, vocab, outfname, args.window)

    if args.stat:
        assert (args.m is not None and args.kappa is not None)
        if args.no_matlab:
            C = canon()
            C.set_params(args.m, args.kappa)
            C.get_stat(args.stat)
            C.start_logging()
            C.approx_cca()
            C.end_logging()
            C.write_result()
        else:
            call_matlab(args.stat, args.m, args.kappa)

    if args.clean: clean()
예제 #3
0
    ('dog', '<?><+1>'): 2,
    ('the', 'cat<-1>'): 1,
    ('<?>', 'cat<-1>'): 1,
    ('the', 'cat<+1>'): 2,
    ('cat', '<?><+1>'): 1
}

stat = check()

# Check if the result of python sparsesvd agrees with the result of Matlab.
m = 2
kappa = 1

C = canon()
C.set_params(m, kappa)
C.get_stat(stat)
C.start_logging()
C.approx_cca()
C.end_logging()
C.write_result()

outdirname = call_matlab(stat, m, kappa)
sv_matlab = map(lambda line: float(line.split()[0]),
                open(os.path.join(outdirname, 'sv')).readlines())
for i in range(len(C.sv)):
    assert (abs(C.sv[i] - sv_matlab[i]) < 1e-10)

sys.stderr.write('Correctness of statistics and svd calculations verified.\n')
sys.stderr.write('Cleaning.\n')
clean()
예제 #4
0
파일: debug.py 프로젝트: karlstratos/cca
                ('the','<?><-1>'): 2, 
                ('dog','<?><+1>'): 2, 
                ('the','cat<-1>'): 1, 
                ('<?>','cat<-1>'): 1, 
                ('the','cat<+1>'): 2, 
                ('cat','<?><+1>'): 1
                }

stat = check()

# Check if the result of python sparsesvd agrees with the result of Matlab.
m = 2
kappa = 1

C = canon()
C.set_params(m, kappa)
C.get_stat(stat)        
C.start_logging()
C.approx_cca()
C.end_logging()
C.write_result()

outdirname = call_matlab(stat, m, kappa)
sv_matlab = map(lambda line: float(line.split()[0]), 
                open(os.path.join(outdirname, 'sv')).readlines())
for i in range(len(C.sv)): assert(abs(C.sv[i] - sv_matlab[i]) < 1e-10) 

sys.stderr.write('Correctness of statistics and svd calculations verified.\n')
sys.stderr.write('Cleaning.\n')
clean()