Exemplo n.º 1
0
 def _run_alg(excluded):
     setting_list_exclude = [setting for setting in setting_list if excluded not in setting['known_interventions']]
     iv_estimated_folder = os.path.join(ESTIMATED_FOLDER, 'exclude_%s' % excluded)
     filename = os.path.join(iv_estimated_folder,
                             'utigsp_%s_alpha=%.2e,alpha_i=%.2e.txt' % (ci_test, alpha, alpha_invariance))
     if not os.path.exists(filename):
         if ci_test == 'gauss_ci':
             os.system('touch gauss_ci_utigsp_%d.tst' % excluded)
             est_dag = unknown_target_igsp(
                 obs_samples,
                 setting_list_exclude,
                 suffstat,
                 nnodes,
                 gauss_ci_test,
                 hsic_invariance_test,
                 alpha=alpha,
                 nruns=10,
                 alpha_invariance=alpha_invariance,
             )
         elif ci_test == 'hsic':
             os.system('touch hsic_utigsp_%d.tst' % excluded)
             est_dag = unknown_target_igsp(
                 obs_samples,
                 setting_list_exclude,
                 obs_samples,
                 nnodes,
                 hsic_test,
                 hsic_invariance_test,
                 alpha=alpha,
                 nruns=10,
                 alpha_invariance=alpha_invariance,
             )
         else:
             raise ValueError
         np.savetxt(filename, est_dag.to_amat())
Exemplo n.º 2
0
    np.savetxt(os.path.join(sample_folder, 'observational.txt'), samples)
    iv_str = 'known_ivs=%s;unknown_ivs=%s.txt' % (nnodes - 1, 0)
    np.savetxt(os.path.join(iv_sample_folder, iv_str), iv_samples)

    # === RUN ALGORITHMS
    dag_igsp = igsp(sample_dict,
                    suffstat,
                    nnodes,
                    gauss_ci_test,
                    hsic_invariance_test,
                    nruns=10,
                    alpha_invariance=1e-5)
    dag_utigsp = unknown_target_igsp(sample_dict,
                                     suffstat,
                                     nnodes,
                                     gauss_ci_test,
                                     hsic_invariance_test,
                                     nruns=10,
                                     alpha_invariance=1e-2)
    amat_gies = run_gies(sample_folder, lambda_=50)
    dag_gies = cd.DAG.from_amat(amat_gies)

    dags_igsp.append(dag_igsp)
    dags_utigsp.append(dag_utigsp)
    dags_gies.append(dag_gies)
    shds_igsp.append(dag_igsp.shd(d))
    shds_utigsp.append(dag_utigsp.shd(d))
    shds_gies.append(dag_gies.shd(d))

print(np.mean(shds_igsp))
print(np.mean(shds_utigsp))
Exemplo n.º 3
0
# === RUN IGSP
igsp_dag = igsp(sample_dict,
                suffstat,
                nnodes,
                gauss_ci_test,
                hsic_invariance_test,
                alpha=1e-5,
                alpha_invariance=1e-5,
                depth=6,
                verbose=True,
                starting_permutations=starting_permutations)

np.random.seed(1729)
random.seed(1729)
# === RUN UTIGSP
utigsp_dag = unknown_target_igsp(obs_samples,
                                 setting_list,
                                 suffstat,
                                 nnodes,
                                 gauss_ci_test,
                                 hsic_invariance_test,
                                 alpha=1e-5,
                                 alpha_invariance=1e-5,
                                 depth=6,
                                 verbose=True,
                                 starting_permutations=starting_permutations)

print(true_dag.shd(utigsp_dag))
print(true_dag.shd(igsp_dag))
print(igsp_dag.shd(utigsp_dag))
Exemplo n.º 4
0
import random

np.random.seed(40)
random.seed(9879132)

nnodes = 10
nsamples = 100
dag = cd.rand.directed_erdos(nnodes, 1.5 / (nnodes - 1), 1)
gdag = cd.rand.rand_weights(dag)
obs_samples = gdag.sample(nsamples)
setting_list = []
for i in range(10):
    iv_samples = gdag.sample_interventional_perfect(
        {
            i: cd.GaussIntervention(1, .1),
            0: cd.GaussIntervention(1, .1)
        }, nsamples)
    setting_list.append({'known_interventions': {i}, 'samples': iv_samples})
suffstat = dict(C=np.corrcoef(obs_samples, rowvar=False), n=nsamples)

est_dag, learned_intervention_targets = unknown_target_igsp(
    obs_samples,
    setting_list,
    suffstat,
    nnodes,
    gauss_ci_test,
    hsic_invariance_test,
    1e-5,
    1e-5,
    nruns=5,
    verbose=True)