Ejemplo n.º 1
0
def custom_tree():
    tree = Tree()
    tree.root = Node("1", [[0.9, 0.1]])
    child1 = Node("2", [[0.15, 0.85], [0.1, 0.9]])
    child2 = Node("3", [[0.5, 0.5], [0.1, 0.9]])
    child3 = Node("3", [[0.3, 0.7], [0.4, 0.6]])
    child1.sample = 0
    child2.sample = 0
    child3.sample = 0
    child1.ancestor = tree.root
    child2.ancestor = tree.root
    child3.ancestor = tree.root
    tree.root.descendants.append(child1)
    tree.root.descendants.append(child2)
    tree.root.descendants.append(child3)
    tree.root.sample = 1
    return tree
Ejemplo n.º 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)
Ejemplo n.º 3
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)))
Ejemplo n.º 4
0
    child3 = Node("3", [[0.3, 0.7], [0.4, 0.6]])
    child1.sample = 0
    child2.sample = 0
    child3.sample = 0
    child1.ancestor = tree.root
    child2.ancestor = tree.root
    child3.ancestor = tree.root
    tree.root.descendants.append(child1)
    tree.root.descendants.append(child2)
    tree.root.descendants.append(child3)
    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]
Ejemplo n.º 5
0
Print the tree (not very sophisticated). Structure: nodename_parentname
"""
print("### printing the tree:")
print_tree(root)
"""
Print the tree with sample (not very sophisticated). Structure: nodename_parentname:sample
"""
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
Ejemplo n.º 6
0
def sample_given_tree(root):
    # choose a set of param
    tree = Tree()
    tree.root = root
    sample_tree(tree)
    tree.print_tree(True, True, True)