コード例 #1
0
def test_find_cm_on_examples():
    for example in examples:
        cover = find_cm(example.UDG)
        correct_cover = example.MCM
        assert cover.shape == correct_cover.shape
        for clique in correct_cover:
            assert (~np.any(cover - clique, axis=1)).any()
コード例 #2
0
def test_reduction_rule_1_on_3cycle_plus_isolated():
    graph = np.zeros((4, 4), dtype=int)
    graph[1:4, 1:4] = 1
    graph[0, 0] = 1

    cover = find_cm(graph)

    assert cover.shape == (1, 4)
    assert ~np.any(cover - [0, 1, 1, 1], axis=1)
コード例 #3
0
    def predict(self, dataset: DatasetInterface):
        # make sample data
        num_latent, num_observed = triangle.MCM.shape

        decoder = MeDILCausalModel(biadj_mat=triangle.MCM)
        sampler = gaussian_mixture_sampler(num_latent)

        input_sample, output_sample = decoder.sample(sampler, num_samples=1000)
        np.save("measurement_data", output_sample)

        # step 1: estimate UDG
        p_vals, null_corr, dep_graph = hypothesis_test(output_sample.T, num_resamples=100)
        # dep_graph is adjacency matrix of the estimated UDG

        # step 2: learn graphical MCM
        learned_biadj_mat = find_cm(dep_graph)

        # step 3: learn functional MCM
        num_latent, num_observed = learned_biadj_mat.shape

        decoder = MeDILCausalModel(biadj_mat=learned_biadj_mat)
        sampler = uniform_sampler(num_latent)

        minMCM = GAN("measurement_data.npy", decoder, latent_sampler=sampler, batch_size=100)
        trainer = Trainer(max_epochs=100)
        trainer.fit(minMCM)

        # confirm given and learned causal structures match
        vis.show_dag(triangle.MCM)
        vis.show_dag(learned_biadj_mat)

        # compare plots of disttrance correlation values for given and learned MCMs
        generated_sample = decoder.sample(sampler, 1000)[1].detach().numpy()
        generated_dcor_mat = distance_correlation(generated_sample.T)

        vis.show_obs_dcor_mat(null_corr, print_val=True)
        vis.show_obs_dcor_mat(generated_dcor_mat, print_val=True)

        # get params for learned functional MCM; replace '0' with 'i' to get params for any M_i
        result = decoder.observed["0"].causal_function
コード例 #4
0
ファイル: pgm_demo.py プロジェクト: neuroinfo19/medil
# make sample data
num_latent, num_observed = triangle.MCM.shape

decoder = MeDILCausalModel(biadj_mat=triangle.MCM)
sampler = gaussian_mixture_sampler(num_latent)

input_sample, output_sample = decoder.sample(sampler, num_samples=1000)
np.save("measurement_data", output_sample)

# step 1: estimate UDG
p_vals, null_corr, dep_graph = hypothesis_test(output_sample.T,
                                               num_resamples=100)
# dep_graph is adjacency matrix of the estimated UDG

# step 2: learn graphical MCM
learned_biadj_mat = find_cm(dep_graph)

# step 3: learn functional MCM
num_latent, num_observed = learned_biadj_mat.shape

decoder = MeDILCausalModel(biadj_mat=learned_biadj_mat)
sampler = uniform_sampler(num_latent)

minMCM = GAN("measurement_data.npy",
             decoder,
             latent_sampler=sampler,
             batch_size=100)
trainer = Trainer(max_epochs=100)
trainer.fit(minMCM)

# confirm given and learned causal structures match
コード例 #5
0
def test_find_cm_on_3_cycle():
    cycle_3 = np.ones((3, 3), dtype=int)
    cover = find_cm(cycle_3)
    assert cover.shape == (1, 3)
    assert ~np.any(cover - [1, 1, 1], axis=1)