deepxde
deepxde copied to clipboard
Custom loss in the form of Gaussian
Hey @lululxvi, Is it possible that we can define a custom loss in deepxde so that the output has both mean variance like the code shown below?
Thank you in advance!
def gaussian_nll(y_true, y_pred):
# y_true is the true labels
# y_pred is the predicted labels, which includes both the mean and standard deviation
y_pred_mean, y_pred_std = tf.split(y_pred, 2, axis=-1)
y_pred_std = tf.nn.softplus(y_pred_std) # ensure standard deviation is positive
mse = 0.5 * tf.square((y_true - y_pred_mean) / y_pred_std)
log_likelihood = mse + tf.math.log(y_pred_std) + 0.5 * np.log(2.0 * np.pi)
return tf.reduce_mean(log_likelihood)
Yes.
Hi @lululxvi, Could you please guide me how may i address this?
See https://deepxde.readthedocs.io/en/stable/modules/deepxde.html#deepxde.model.Model.compile. loss
can be a python loss function.