예제 #1
0
파일: run_igsp.py 프로젝트: csquires/utigsp
        est_dags = list(tqdm(pool.imap(_run_igsp, dag_nums), total=ndags))

    # === CREATE FOLDER FOR RESULTS
    nonlinear_str = '_nonlinear' if nonlinear else ''
    dag_str = f'nnodes={nnodes}_nneighbors={nneighbors}_ndags={ndags}{nonlinear_str}'
    sample_str = 'nsamples=%s,num_known=%d,num_unknown=%d,nsettings=%d,intervention=%s' % (
        nsamples, num_known, num_unknown, nsettings, intervention)
    alg_str = 'nruns=%d,depth=%d,alpha=%.2e,alpha_invariant=%.2e' % (
        nruns, depth, alpha, alpha_invariant)
    result_folder = os.path.join(PROJECT_FOLDER, 'simulations', 'results',
                                 dag_str, sample_str, 'igsp', alg_str)
    os.makedirs(result_folder, exist_ok=True)

    # === LOAD TRUE DAGS
    dag_filenames = [
        os.path.join(get_dag_folder(ndags, nnodes, nneighbors, dag_num),
                     'amat.npy') for dag_num in range(ndags)
    ]
    true_dags = [
        cd.DAG.from_amat(np.load(dag_filename))
        for dag_filename in dag_filenames
    ]

    # === SAVE SHDS
    shds = [
        true_dag.shd(est_dag)
        for true_dag, est_dag in zip(true_dags, est_dags)
    ]
    np.save(os.path.join(result_folder, 'shds.npy'), shds)

    # === GET LISTS OF KNOWN AND ALL INTERVENTIONS
예제 #2
0
파일: run_icp.py 프로젝트: csquires/utigsp
            return np.loadtxt(filename)


    with multiprocessing.Pool(multiprocessing.cpu_count() - 1) as pool:
        dag_nums = list(range(ndags))
        est_amats = list(tqdm(pool.imap(_run_icp, dag_nums), total=ndags))

    # === CREATE FOLDER FOR RESULTS
    dag_str = 'nnodes=%d_nneighbors=%s_ndags=%d' % (nnodes, nneighbors, ndags)
    sample_str = 'nsamples=%s,num_known=%d,num_unknown=%d,nsettings=%d,intervention=%s' % (nsamples, num_known, num_unknown, nsettings, intervention)
    alg_str = 'alpha=%.2e' % alpha
    result_folder = os.path.join(PROJECT_FOLDER, 'simulations', 'results', dag_str, sample_str, 'icp', alg_str)
    os.makedirs(result_folder, exist_ok=True)

    # === LOAD TRUE DAGS
    dag_filenames = [os.path.join(get_dag_folder(ndags, nnodes, nneighbors, dag_num), 'amat.txt') for dag_num in range(ndags)]
    true_amats = [np.loadtxt(dag_filename) for dag_filename in dag_filenames]
    true_dags = [cd.DAG.from_amat(amat) for amat in true_amats]

    # === SAVE SHDS
    shds = [utils.shd_mat(true_amat, est_amat) for true_amat, est_amat in zip(true_amats, est_amats)]
    np.savetxt(os.path.join(result_folder, 'shds.txt'), shds)

    # === CONVERT AMATS TO DAGS IF POSSIBLE
    est_dags = []
    for est_amat in est_amats:
        try:
            d = cd.DAG.from_amat(est_amat)
        except Exception as e:
            print(e)
            d = None