コード例 #1
0
ファイル: audit.py プロジェクト: guoyu07/audit-lab
def set_audit_seed(e, new_audit_seed):
    """ 
    Set e.audit_seed to new value (but only if not already set). 

    The idea is that the command line may set the audit seed to a non-None
    value first, in which case it is "sticky" and thus overrides any 
    setting that might be in the audit seed file.

    This routine also sets the global auditRandomState.
    """

    global auditRandomState

    e.audit_seed = new_audit_seed
    # audit_seed might be None if no command-line argument given

    auditRandomState = utils.RandomState(e.audit_seed)
コード例 #2
0
ファイル: main.py プロジェクト: yilunchen27/AutoNE
def get_result(dataset_name,
               target_model,
               task,
               kargs,
               sampled_dir='',
               debug=debug,
               cache=cache):
    rs = utils.RandomState()
    rs.save_state()
    rs.set_seed(0)
    embedding_filename = utils.get_names(target_model, **kargs)
    if task == 'classification':
        cf = os.path.abspath(
            os.path.join('result/{}'.format(dataset_name), sampled_dir, 'cf',
                         embedding_filename))
    elif task == 'link_predict':
        cf = os.path.abspath(
            os.path.join('result/{}'.format(dataset_name), sampled_dir, 'lp',
                         embedding_filename))
    embedding_filename = os.path.abspath(
        os.path.join('embeddings/{}'.format(dataset_name), sampled_dir,
                     embedding_filename))
    dataset_filename = os.path.abspath(
        os.path.join('data/{}'.format(dataset_name), sampled_dir,
                     'graph.edgelist'))
    if target_model != 'gcn':
        if (not cache) or (not os.path.exists(embedding_filename)) or (
                os.path.getmtime(embedding_filename) <
                os.path.getmtime(dataset_filename)):
            utils.run_target_model(target_model,
                                   dataset_filename,
                                   os.path.dirname(embedding_filename),
                                   embedding_test_dir=embedding_test_dir,
                                   debug=debug,
                                   **kargs)
        if (not cache) or (not os.path.exists(cf)) or (
                os.path.getmtime(cf) < os.path.getmtime(embedding_filename)):
            if task == 'classification':
                labels = os.path.abspath(
                    os.path.join(os.path.dirname(dataset_filename),
                                 'label.txt'))
            elif task == 'link_predict':
                labels = os.path.abspath(
                    os.path.join(os.path.dirname(dataset_filename)))
            utils.run_test(task,
                           dataset_name, [embedding_filename],
                           labels,
                           cf,
                           embedding_test_dir=embedding_test_dir)
    else:
        if (not cache) or (not os.path.exists(cf)):
            data_path = os.path.abspath(
                os.path.join('data/{}'.format(dataset_name)))
            with utils.cd(
                    os.path.join(embedding_test_dir, 'src/baseline/gcn/gcn')):
                cmd = ('python3 main.py' +\
                        ' --epochs {} --hidden1 {} --learning_rate {}' +\
                        ' --output_filename {} --debug {} --dataset {} --input_dir {}').format(kargs['epochs'], kargs['hidden1'], kargs['learning_rate'], cf, debug, dataset_name, data_path)
                if debug:
                    print(cmd)
                else:
                    cmd += ' > /dev/null 2>&1'
                os.system(cmd)
    rs.load_state()
    res = np.loadtxt(cf, dtype=float)
    if len(res.shape) != 0:
        res = res[0]
    return res