Skip to content

How to track the current iteration number in a custom loss function? #859

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

You must be logged in to vote

Hi @GFODK,

Unfortunately you cannot have a dynamic loss function, because it is cached at various points in the search rather than re-computing each time. So if your loss function changes, it will break some assumptions in the code.

What you can do though is adjust the loss function and call fit! again—it will start where it left off, and recompute all the losses on existing populations of expressions. So, for example:

model = SRRegressor(
    niterations=1,
    binary_operators=[+, -, *, /],
    unary_operators=[sin, cos, exp, log],
    population_size=50,
    loss_function=loss_functions[1]
)
mach = machine(model, x, y)
fit!(mach)

for i in 2:100
    mach.model.loss_function = loss_func…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@GFODK
Comment options

@MilesCranmer
Comment options

@GFODK
Comment options

@MilesCranmer
Comment options

@GFODK
Comment options

Answer selected by GFODK
Comment options

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

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