Generating binary trees #47
Replies: 1 comment 7 replies
-
I think what's tripping you up is that you're thinking of the object passed to function jsonwrap(child)
vecs = Data.Vectors(child)
dicts = Data.Dicts(strings, child)
vecs | dicts
end
Data.recursive(branch_gen; max_layers=3) do childgen
branches = Data.Vectors(childgen; min_size=2, max_size=2) # this really should be something that generates tuples...
map(branches) do v
Node{T}(; operator.op, v...)
end
end i.e. build a I agree that #45 would be the most appropriate instead of The crucial thing is that the function passed to |
Beta Was this translation helpful? Give feedback.
-
Hi @Seelengrab,
I'm looking to integrate Supposition.jl into the tests of DynamicExpressions.jl and SymbolicRegression.jl and was wondering if I could ask if I am going the right direction. I am attempting to build a generator for binary trees up to a certain max depth.
Here is what I have so far:
Now, I wish to use
branch_gen
to recursively generate trees of arbitrary size. Here's my attempt:The
filter(t -> t.degree == 0, root)
is a utility in DynamicExpressions.jl to pick out all the leafs of a tree. Then, I put this in a data generator withSampledFrom
.However, I'm not sure the next step. What I want to do now is call
branch_gen
to get a new branch node, and then set the leaf node equal to that branch node, thus expanding the tree. But I'm not sure how to passleafs_gen
tobranch_gen
and I can't seem to create closures (#45 and #46).Any tips? Alternative to the above approach, I'd love to hear any tips on generating binary trees like https://github.com/SymbolicML/DynamicExpressions.jl/blob/cab1143ae06b147cd81482a783912d9deb9247d6/src/Node.jl#L73-L135. (I couldn't seem to transfer the JSON example to this)
Thanks again for the nice package!!
Best,
Miles
Beta Was this translation helpful? Give feedback.
All reactions