Feat(random): Start random tree generation
This commit is contained in:
parent
538cbdcbcc
commit
c9c44be0d1
@ -7,7 +7,7 @@
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Tools to extract random leafs, random variables, generate random values and
|
||||
Tools to extract random nodes, random variables, generate random values and
|
||||
fill new trees
|
||||
|
||||
Flow
|
||||
@ -15,9 +15,9 @@ Flow
|
||||
|
||||
Tree with RdLeaf
|
||||
|
|
||||
| Extract rdLeaf
|
||||
| Extract nodes
|
||||
|
|
||||
List of leafs to generate
|
||||
List of nodes to generate
|
||||
|
|
||||
| extract_rv
|
||||
|
|
||||
@ -27,9 +27,9 @@ List random variables to generate
|
||||
|
|
||||
Dictionnary of generated random variables
|
||||
|
|
||||
| Compute leafs
|
||||
| Compute nodes
|
||||
|
|
||||
Dictionnary of computed leafs
|
||||
Dictionnary of computed nodes
|
||||
|
|
||||
| Replace
|
||||
|
|
||||
@ -45,12 +45,11 @@ Tree with RdLeaf replaced by generated values
|
||||
> {a*k}
|
||||
>>> extract_rdleaf(rd_t)
|
||||
['a', 'a*k']
|
||||
|
||||
|
||||
"""
|
||||
|
||||
from .leaf import RdLeaf
|
||||
|
||||
|
||||
def extract_rdleaf(tree):
|
||||
""" Extract rdLeaf in a Tree
|
||||
|
||||
@ -73,6 +72,7 @@ def extract_rdleaf(tree):
|
||||
rd_leafs.append(leaf.name)
|
||||
return rd_leafs
|
||||
|
||||
|
||||
def extract_rv(leafs):
|
||||
""" Extract the set of random values from the leaf list
|
||||
|
||||
@ -91,6 +91,7 @@ def extract_rv(leafs):
|
||||
rd_values.add(c)
|
||||
return rd_values
|
||||
|
||||
|
||||
def compute_leafs(leafs, generated_values):
|
||||
""" Compute leafs from generated random values
|
||||
|
||||
@ -106,6 +107,7 @@ def compute_leafs(leafs, generated_values):
|
||||
"""
|
||||
return {leaf: eval(leaf, generated_values) for leaf in leafs}
|
||||
|
||||
|
||||
def replace_rdleaf(tree, computed_leafs):
|
||||
""" Replace RdLeaf by the corresponding computed value
|
||||
|
||||
@ -117,10 +119,11 @@ def replace_rdleaf(tree, computed_leafs):
|
||||
> 2
|
||||
> 6
|
||||
"""
|
||||
|
||||
def replace(leaf):
|
||||
try:
|
||||
return leaf.replace(computed_leafs)
|
||||
except AttributeError:
|
||||
return leaf
|
||||
return tree.map_on_leaf(replace)
|
||||
|
||||
return tree.map_on_leaf(replace)
|
||||
|
@ -10,10 +10,12 @@
|
||||
|
||||
"""
|
||||
|
||||
class RdLeaf():
|
||||
|
||||
class RdLeaf:
|
||||
""" Random leaf
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, name):
|
||||
self._name = name
|
||||
self.rdleaf = True
|
||||
|
Loading…
Reference in New Issue
Block a user