Пример #1
0
def setup_func():
    global T, tv, nb_trees, tree_list, mtg_name, g
    # build some random initial tree
    stat_tool.plot.DISABLE_PLOT = True
    inf_bound = 0
    sup_bound = 3
    distrib = stat_tool.Uniform(inf_bound, sup_bound)
    max_depth = 3
    max_size = 10
    nbtrees = 40
    # define a set of trees
    tree_list = []
    tv = [1., 0, 1, 2.]  # trees.TreeValue([1., 0])
    R = trees.TreeStructure(distrib, max_size, max_depth)
    tmp_tree = trees.Tree(tv, R)
    n = 1
    tree_list.append(trees.Tree(tmp_tree))
    while n < nbtrees:
        n = n + 1
        R.Simulate(distrib, max_size, max_depth)
        tmp_tree = trees.Tree(tv, R)
        tree_list.append(trees.Tree(tmp_tree))
    distrib_list = []
    for i in range(tmp_tree.NbInt()):
        distrib_list.append(distrib)
    for n in range(len(tree_list)):
        tree_list[n].Simulate(distrib_list)
    T = trees.Trees(tree_list)
    nb_trees = nbtrees
    mtg_name = "data/sample_mtg_forest.mtg"
    g = build_mtg()

    return T, tv, nb_trees, tree_list, mtg_name, g
Пример #2
0
def test_tree_structures():
    """Test TreeStructure class"""
    msg1 = "Bad number of vertices for TreeStructure: "
    msg2 = "Bad correspondence from MTG to Tree vertices: "
    mtg_t = test_mtg_build()
    TrMTG = mtg_t.Tree(0)
    # Copy tree structures
    Tr = trees.TreeStructure(TrMTG)
    assert Tr.Size() == TrMTG.Size(), msg1 + str(Tr.Size())
    assert Tr.TreeVertex() == TrMTG.TreeVertex(), msg2
    assert Tr.MTGVertex() == TrMTG.MTGVertex(), msg2
    # Build trees with same structures as mtg_t
    tree_list = []
    attributes = mtg_t.Attributes()
    for t in range(mtg_t.NbTrees()):
        TrMTG2 = mtg_t.Tree(t)
        Tr = trees.TreeStructure(TrMTG2)
        tree_list += [trees.Tree([0], Tr)]
    T0 = trees.Trees(tree_list, attribute_names=[attributes[0]])
    Tr = T0.Tree(0)
    assert Tr.Size() == TrMTG.Size(), msg1 + str(Tr.Size())
    assert Tr.TreeVertex() == TrMTG.TreeVertex(), msg2
    assert Tr.MTGVertex() == TrMTG.MTGVertex(), msg2
Пример #3
0
    ident, inf_bound, sup_bound, parameter, probability)

print "Distribution used for the number of children and the tree attributes:"
print distrib

max_depth = 3
max_size = 10
nbtrees = 4

# test the initialization and the estimation of a HMT
print "Test the initialization and the estimation of a HMT"
# define a set of trees

tree_list = []
tv = [1., 0, 1, 2.]  # trees.TreeValue([1., 0])
R = trees.TreeStructure(distrib, max_size, max_depth)
tmp_tree = trees.Tree(tv, R)
n = 1
tree_list.append(trees.Tree(tmp_tree))
while n < nbtrees:
    n = n + 1
    R.Simulate(distrib, max_size, max_depth)
    tmp_tree = trees.Tree(tv, R)
    tree_list.append(trees.Tree(tmp_tree))
distrib_list = []

for i in range(tmp_tree.NbInt()):
    distrib_list.append(distrib)

for n in range(len(tree_list)):
    tree_list[n].Simulate(distrib_list)
Пример #4
0
    sup_bound = 3
    distrib = stat_tool.Uniform(inf_bound, sup_bound)
    nbtrees = 40
    max_depth = 3
    max_size = 20
    n = 5


init()
print distrib

################################
# TreeStructure
################################

D = trees.TreeStructure()
print "Default tree structure: ", D
print "A random tree structure R:"
R = trees.TreeStructure(distrib)
print R
print "(size, depth) = (", R.Size(), ", ", R.Depth(), ")."
R.Simulate(distrib, max_size, max_depth)
print "A second realization of R: "
print R
# TreeStructure.SelectSubTree
ST = R.SelectSubTree(1)
print "Extract subtree rooted at vertex 1 from R:"
print ST
# pruning
ST = R.SelectSubTree(1, False)
print "Prune subtree rooted at vertex 1 from R:"
import openalea.stat_tool as stat_tool
import openalea.tree_statistic.trees as trees
inf_bound = 1
sup_bound = 3
probability = 0.6
children_distrib = stat_tool.Uniform(inf_bound, sup_bound)
# distribution of the children
attributes_distrib = stat_tool.Uniform(0, 10)
# distribution of the attributes
max_depth = 3
max_size = 10
nbtrees = 2
# defining a set of trees
tree_list = []
# simulation of the structure
R = trees.TreeStructure(children_distrib, max_size, max_depth)
tmp_tree = trees.Tree([1., 0], R)
n = 1
tree_list.append(trees.Tree(tmp_tree))
while n < nbtrees:
    n = n+1
    R.Simulate(children_distrib, max_size, max_depth)
    tmp_tree = trees.Tree([1., 0], R)
    tree_list.append(trees.Tree(tmp_tree))

distrib_list = []
# simulation of the labels
for i in range(tmp_tree.NbInt()):
    distrib_list.append(attributes_distrib)

for n in range(len(tree_list)):