コード例 #1
0
def run_exp(params, verbose):
    print_params(params)

    n_episodes = 10000

    episode_params = dict(n_way=params.n_way,
                          n_support=params.n_shot,
                          n_query=params.n_query,
                          n_semi=params.n_semi)

    model = ProtoSemi(opt=params)
    model = model.cuda()

    train_mean, cl_data_file = load_features(params)

    acc_list = []
    start_time = time.perf_counter()
    for i in range(1, n_episodes + 1):
        acc = run_episode(train_mean, cl_data_file, model, **episode_params)
        acc_list += acc
        if i % verbose == 0:
            print_msg(i, n_episodes, start_time, acc_list, acc)
    res = [avg(acc_list[ind::len(acc)]) for ind in range(len(acc))]
    ci = [ci_95(acc_list[ind::len(acc)]) for ind in range(len(acc))]
    return res, ci
コード例 #2
0
ファイル: to_kcnf.py プロジェクト: giovannirescia/tesis
def dump(data, problem, rfolder):
    if len(data) > 0:
        fname = os.path.join(rfolder, ('%s.cnf' % problem))
        f = open(fname, 'w')
        f.write(data)
        print_msg(('CNF file: %s' % fname))
        f.close()
コード例 #3
0
def _translate_generators(n_gens, v_map):
    l_gens = []
    for g in n_gens:
        l_g = []
        for c in g:
            l1 = v_map[c[0]]
            l2 = v_map[c[1]]
            if l1[0] == l2[0]:
                l_g.append((l1[0], l1[1], l2[1]))
            else:
                print_msg('Modal depth doesn''t match')
        l_gens.append(l_g)
    return l_gens
コード例 #4
0
ファイル: graphA2.py プロジェクト: giovannirescia/tesis
def calculate_symmetries(problem_name , formula, results_dir, bliss_file = True,
                         dot_file = True):
    
    global _graph_gens
    global _formula_gens
    _graph_gens = []
    _formula_gens = []

    print_msg('Generating Intermediate graph representation...')
    c, v, e = fparser.parse_formula(formula)
    
    print_msg('Generating Bliss graph...')
    g, nodes, edges, mapping = _generate_bliss_graph(c, v, e)

    nn = g.nof_vertices()
    nc = len(c)
    nv = sum(map(len, v))
    print_msg(('Nof Nodes: %s - Nof Clauses: %s - Nof Literals: %s' % (nn, nc, nv)))
    
    bf = ''
    if bliss_file:
        bf = os.path.join(results_dir, (problem_name + '.bliss'))
        print_msg('Generating Bliss file...')
        _generate_bliss_file(bf, nodes, edges, mapping)
        
    df = ''
    if dot_file:
        df = os.path.join(results_dir, (problem_name + '.dot'))
        print_msg('Generating Dot file...')
        _generate_dot_file(df, g)
        
    start = time.time()
    print_msg('Calculating graph automorphisms...')
    gz = g.find_automorphisms(_process_perm, nodes)
    duration = time.time() - start
    
    gf = os.path.join(results_dir, (problem_name + '.gens'))
    print_msg('Generating generators file...')
    _generate_generators_file(gf)
    
    ngg = len(_graph_gens)
    nfg = len(_formula_gens)
    
    _graph_gens = None
    _formula_gens = None
    
    res = [problem_name.replace(',', ';'), nn, nc, nv, ngg, nfg, gz, duration]
    
    print_report(res)
    #print_msg('---------------------------------------------')
    return res
コード例 #5
0
    if len(data) > 0:
        fname = os.path.join(rfolder, 'stats.csv')
        f = open(fname, 'w')
        f.write(','.join(CSV_HEADER) + '\n')
        for s in data:
            row = []
            f.write(','.join([str(e) for e in s]) + '\n')
        #print_msg(('Stats file: %s' % fname))
        print fname

stats = []
folder = None
if len(sys.argv) > 1:
    folder = sys.argv[1]
else:
    print_msg('No folder specified. ')
    exit(0)
    
#print_msg(('Processing files in %s' % folder))

problems = list_files(folder, '.bliss')
#print_msg(('%s files were find' % len(problems)))
for p in problems:
    problem = os.path.basename(p).upper()
    try:
        #print_msg(('Processing: %s...' % problem))
        print p   
        data = get_stats(p, folder)
        stats.append([problem] + data)
    except Exception, e:
        print_msg(('**************************EXCEPTION in problem: %s *******************************' % problem))
コード例 #6
0
ファイル: to_kcnf.py プロジェクト: giovannirescia/tesis
def sig_handler(signum, frame):
    global stats
    global results_folder
    print_msg('Cancelling the job...')
    print_msg('Bye...')
    exit(0)
コード例 #7
0
ファイル: to_kcnf.py プロジェクト: giovannirescia/tesis
def sig_handler(signum, frame):
    global stats
    global results_folder
    print_msg('Cancelling the job...')
    print_msg('Bye...')
    exit(0)

#signal.signal(signal.SIGTERM, sig_handler)
#signal.signal(signal.SIGINT, sig_handler)

folder = None
if len(sys.argv) > 1:
    folder = sys.argv[1]
else:
    print_msg('No folder specified.')
    exit(0)

results_folder = os.path.join(RESULTS_ROOT, ('%s_kcnf-%s' % (os.path.basename(folder), int(time.time()))))

if not os.path.exists(results_folder):
    os.mkdir(results_folder)
   
print_msg(('Looking for intohylo files in %s' % folder))
problems = list_files(folder, '.intohylo')
print_msg(('%s problems were find' % len(problems)))

problems.sort()
for p in problems:
    problem = os.path.basename(p).upper()
    try: