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