Skip to content

Help with custom loss function #613

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

You must be logged in to vote

How can I feed in Actual_S and Actual_P to a custom loss function although they can are not included in the x variables?

What I normally do here is just feed in the variables as additional columns of X, but then zero them out within the custom loss function. For example:

function my_loss_function(tree, dataset::Dataset{T,L}, options)::L where {T,L}
    X = copy(dataset.X)
    y = copy(dataset.y)  # Don't need to copy if you aren't modifying; but just a safer habit

    # Ordering (depends how you pass to .fit)
    # 'a' - 1; 'k' - 2; 'd' - 3; 'L' - 4; 'w' - 5; 'g' - 6;'o' - 7.
    # Thus, say that 'P' is 8 and 'S' is 9
    X_without_P_and_S = vcat(
        X[1:7, :],  # The actual data

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@gm89uk
Comment options

@gm89uk
Comment options

Answer selected by gm89uk
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
2 participants