Skip to content

Is it possible to use a custom loss function in GPfLOW? #2036

Answered by st--
nfraehr asked this question in Q&A
Discussion options

You must be logged in to vote

If you write your objective_func using TensorFlow instead of NumPy (e.g. tf.math.sqrt, tf.reduce_mean) you should be able to simply pass that to gf.optimizers.Scipy().minimize(...) instead of model.training_loss:

def objective_func():
    GP_output = model.predict_y(X)[0]

    Predicted_output = data_treatment_func(GP_output)

    return tf.sqrt(tf.reduce_mean(tf.square(Predicted_output - y_obs)))

gf.optimizers.Scipy().minimize(
    objective_func, model.trainable_variables, options=optimizer_config
)

Replies: 1 comment 1 reply

Comment options

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

Answer selected by nfraehr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants