Skip to content
Discussion options

You must be logged in to vote

Maybe like this? It only checks the points you pass for monotonicity though; maybe that's enough? I guess you could always pass more points if needed.

from pysr import jl, PySRRegressor

jl.seval("using Zygote")  # Need to load package for gradient calculations

loss_function = """
function cdf_loss(tree::Node, dataset::Dataset{T,L}, options::Options) where {T,L}
    X = dataset.X
    y = dataset.y

    y_pred, grad, completed = eval_grad_tree_array(tree, X, options; variable=true)

    if !completed
        return convert(L, 1e9)
    end

    loss = convert(L, sum((y_pred .- y).^2) / length(y))
    is_monotonic = all(grad .>= 0)
    min_val = minimum(y_pred)
    max_val = maximum(y_pred)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
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
1 participant