openkim / kliff

KIM-based Learning-Integrated Fitting Framework for interatomic potentials.
https://kliff.readthedocs.io
GNU Lesser General Public License v2.1
34 stars 20 forks source link

Alternative Error Functions for Loss Calculation #176

Open kbushick opened 4 months ago

kbushick commented 4 months ago

Is your feature request related to a problem? Please describe. It seems that KliFF natively supports only RMSE loss type functions. While users can define their own residual functions, the loss is always squared (lines 528, 575, 851 in loss.py). loss = 0.5 * np.linalg.norm(residual) ** 2 loss = torch.sum(torch.pow(residual, 2))

Describe the solution you'd like It would be helpful to be able to specify the loss function that should be used, in combination with the residual, i.e. MAE, RMSE, etc. as a flag in the Loss constructor. Since different functions may be better or worse depending on the specific use case, there could be utility in allowing a simple switch in the loss computation.

Describe alternatives you've considered Knowing that the square is always there, an alternative approach would be crafting a custom residual function to compensate, for example taking the square root of the residual. I believe this should be a feasible short term solution, but may make code harder to follow.

mjwen commented 3 months ago

Hi @kbushick, Sorry for the late response!

We are making major updates to KLIFF, and a new version which supports flexible loss functions among others is coming soon. Stay tuned!