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)
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))
""" 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()
""" Print the tree (not very sophisticated). Structure: nodename_parentname """ print_tree(root) """ Print the tree with sample (not very sophisticated). Structure: nodename_parentname:sample """ print_tree(root, print_sample=True) """ 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]) t.print_tree() """ Generate a random tree """ t.create_random_tree(3) t.print_tree()
def sample_given_tree(root): # choose a set of param tree = Tree() tree.root = root sample_tree(tree) tree.print_tree(True, True, True)