Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the grammar sampling method #43

Closed
THinnerichs opened this issue Aug 25, 2023 · 1 comment
Closed

Fix the grammar sampling method #43

THinnerichs opened this issue Aug 25, 2023 · 1 comment
Assignees

Comments

@THinnerichs
Copy link
Member

function _sample(node::RuleNode, x::RuleNodeAndCount, maxdepth::Int)

The sampling function is buggy and doesn't really do what we want to do here. (See discussion in #36 (comment))

@THinnerichs
Copy link
Member Author

THinnerichs commented Dec 22, 2023

I ran a few examples and the sampling seems to quite skewed. It either generates very large or very small trees. Intermediate sizes barely happen.

julia> arithmetic_grammar = @cfgrammar begin
                   X = X * X
                   X = X + X
                   X = X - X
                   X = |(1:4)
               end
...               
             
julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
4,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
6,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
5,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
2{1{3{3{2{1{5,2{4,3{4,6}}}6}1{6,7}}2{1{1{4,3{6,7}}3{7,3{6,3{5,6}}}}3{3{7,2{6,1{5,6}}}1{4,2{5,2{1{6,6}4}}}}}}4}4}

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
4,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
6,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
6,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
2{3{5,1{7,4}}1{4,3{1{4,1{4,4}}7}}}

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
5,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
1{7,5}

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
6,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
5,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
3{6,6}

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
3{2{7,3{5,6}}3{3{6,3{1{1{2{2{2{1{1{4,1{6,1{4,4}}}6}7}5}1{2{3{6,6}3{4,4}}4}}7}6}5}}2{2{1{1{3{7,1{1{2{7,1{6,2{4,3{7,2{6,5}}}}}4}4}}2{2{3{6,5}2{2{3{1{5,3{4,2{6,4}}}6}2{4,1{1{2{5,5}7}6}}}1{4,1{4,4}}}}6}}5}6}6}}}

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
6,

julia> expression_generated = rand(RuleNode, arithmetic_grammar, :X, 15)
3{1{2{7,4}7}6}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants