Skip to content

Make PySR look for strictly factorised functions #465

Discussion options

You must be logged in to vote

Good question. You could do this with a custom loss function that checks if the expression is factorized, otherwise returns a large loss:

function eval_loss(tree, dataset::Dataset{T,L}, options)::L where {T,L}
    # Check if expression is factorized:
    penalty_term = L(0)

    # Make sure root is degree 2:
    if tree.degree != 2
        penalty_term += L(10000)
    else
        # Make sure operator is *
        if options.operators.binops[tree.op] != *
            penalty_term += L(1000)
        else
            # Split the expression into two subexpressions at the root node:
            g0 = tree.l
            g1 = tree.r
            # Check if it's factorized:
            has_x1_in_g0 =

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@MilesCranmer
Comment options

@MilesCranmer
Comment options

@manuel-morales-a
Comment options

Answer selected by MilesCranmer
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