Skip to content

Constraint that excludes constants that are not (part of) coefficients #713

Closed Answered by MilesCranmer
GoldenGoldy asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry for the late reply @GoldenGoldy. This constraint sounds a bit tricky but it is certainly doable. Have a look at https://symbolicml.org/DynamicExpressions.jl/dev/examples/base_operations/ to learn how to write custom constraints. For your problem I suppose I would have some check like:

num_constants_under_multiply = sum(tree) do node
    is_mul = node.degree == 2 && node.op == 1  # Assuming * was passed as first operator
    if is_mul
        left = node.l
        right = node.r
        left_is_constant = left.degree == 0 && left.constant
        right_is_constant = right.degree == 0 && right.constant
        
        return left_is_constant + right_is_constant
    else
        return 0

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by GoldenGoldy
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@GoldenGoldy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion SymbolicRegression.jl SymbolicRegression.jl-related discussion
2 participants