Skip to content

Python variables in julia custom loss function #444

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

You must be logged in to vote

Hi @AndrewHutani,

This is definitely possible. However loss expects elementwise loss only (e.g., loss="my_loss(prediction, target) = (prediction - target)^2" for a single scalar prediction and single scalar target). Instead you should use full_objective. The example of this is here: https://astroautomata.com/PySR/api/#the-objective. Do you want to try with that and see if you can get it to work?

To get your Python lower and upper bounds into the loss, I would do something with string interpolation and just put them into the string like:

full_objective=f"""
    function eval_loss(tree, dataset, options)
        lower_bounds = [{", ".join(map(str, np.min(y, axis=0)))}]
        upper_bounds = [

Replies: 1 comment 8 replies

Comment options

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

@AndrewHutani
Comment options

@MilesCranmer
Comment options

@MilesCranmer
Comment options

@AndrewHutani
Comment options

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