Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining custom loss functions. #2070

Open
agosztolai opened this issue May 26, 2023 · 0 comments
Open

Defining custom loss functions. #2070

agosztolai opened this issue May 26, 2023 · 0 comments

Comments

@agosztolai
Copy link

Hello,

I am trying to implement a simple custom loss function for the purpose of finding the least-squares projection ||f(x) - y||_2 to a pre-trained GP f defined by the model manifold_GP. I can provide an initial guess for x.

I have tried a million ways and failed. Below is my latest attempt.

Can you please tell me how to do this?

y = y_train[[1]]
def loss() -> tf.Tensor:
    Y_predicted = manifold_GP.predict_f(x_initial)
    squared_error = (Y_predicted - tf.convert_to_tensor(y)) ** 2
    return tf.reduce_mean(squared_error)

x_initial = np.array(x_test[[0]])  # Initial guess for x
opt = gpflow.optimizers.Scipy()
result = opt.minimize(loss, variables=[tf.Variable(x_initial)]) 

Documentation/tutorial notebooks

Is there anything missing in the docs?

Are there any mistakes in the docs?

Is there a feature that needs some example code in a notebook?

Do you know how to fix the docs? If so, it'd be amazing if you'd be willing to directly contribute a pull request :)

Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant