コード例 #1
0
def compute_observation_prob(params, samples):
    # choose a set of param
    for key in params.keys():
        print("#### TREE : " + key)
        parameters = params[key]
        for j in [1, 2, 3, 4, 5]:
            t = Tree()
            t.load_params(parameters)
            samples_name = key + '_sample_' + str(j)
            try:
                sample = samples[samples_name]
            except:
                break
            t.load_sample(sample)
            compute_posterior(t)
            print("\tsample_" + str(j) + " : " +
                  str(compute_leaves_probability(t)))
コード例 #2
0
def sample_given_trees(params, samples):
    # choose a set of param
    for key in params.keys():
        print("#### TREE : " + key)
        parameters = params[key]
        for j in [1, 2, 3, 4, 5]:
            t = Tree()
            t.load_params(parameters)
            samples_name = key + '_sample_' + str(j)
            try:
                sample = samples[samples_name]
            except:
                break
            t.load_sample(sample)
            compute_posterior(t)
            # sample_tree(t)
            t.print_tree(True, True, True)
コード例 #3
0
    tree.root.sample = 1
    return tree


if __name__ == "__main__":
    t = Tree()

    my_data_path = ''

    # get data to load into the tree
    params = np.load(my_data_path + 'tree_params.npy').tolist()
    samples = np.load(my_data_path + 'tree_samples.npy').tolist()

    # choose a set of param
    params_name = params.keys()[0]
    parameters = params[params_name]

    # choose samples
    samples_name = params_name + '_sample_2'
    sample = samples[samples_name]

    # Load params into tree and samples
    t.load_params(parameters)
    t.load_sample(sample)
    print("### printing loaded tree")
    t.print_tree(True, True)

    t = custom_tree()
    t.print_tree(True, True)
    print(compute_probability_observation(t))
コード例 #4
0
"""
print("### printing the tree with samples:")
print_tree(root, print_sample=True)

print(root.cat)
"""
Use tree object:
"""

t = Tree()

my_data_path = ''

with open(my_data_path + 'tree_params.pickle', 'rb') as handle:
    params = pickle.load(handle)

key = params.keys()[0]
"""
Load params into tree
"""
t.load_params(params[key])
print("### printing loaded tree")
t.print_tree(False, True)
"""
Generate a random tree
"""

print("### generating random tree")
t.create_random_tree(3)
t.print_tree()