RBF Regression for Free Energy Surface Fitting#39
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Radial Basis Function Regression for Free Energy Surface Fitting
Summary
This PR introduces a new
ForceMatchingRegressorclass that uses radial basis functions (RBF) to fit free energy surfaces from position-force pairs. The implementation supports both periodic and non-periodic dynamical variables, uses PyTorch Lightning for training, and includes comprehensive unit tests.Key Features
1. Per-Dimension Kernel Bandwidths
2. Periodic and Non-Periodic Variable Support
DynamicalVariablebounds3. Dynamical Variable Integration
DynamicalVariableobjects to extract bounds and periodicity information4. Training Features
TemporaryDirectoryfor automatic cleanup5. Type Safety
API
Mathematical Formulation
The potential is approximated as:
where:
The model is trained by minimizing the mean squared error between predicted and actual forces:
where$\mathbf{f}(\mathbf{s}) = -\nabla_{\mathbf{s}} U(\mathbf{s})$ is the predicted force.
Implementation Details
Classes
RBFPotential(nn.Module): Core RBF potential implementationGradMatch(pl.LightningModule): PyTorch Lightning module for trainingForceMatchingRegressor: High-level API classfit(),predict(), andget_parameters()methodsKey Implementation Choices
GradMatch) separated from API (ForceMatchingRegressor)Testing
Comprehensive unit tests (
test_regression.py) with 24 test cases covering:Coverage: 100% for
regression.py(113 statements)Breaking Changes
None - this is a new feature addition.
Dependencies
pytorch(PyTorch, via conda)lightning(PyTorch Lightning, via conda)numpyFiles Changed
openxps/regression.py(new file, 331 lines)openxps/tests/test_regression.py(new file, 384 lines)openxps/__init__.py(updated to exportForceMatchingRegressor)openxps/bounds/base.py(addedlengthattribute toBoundsclass)pyproject.toml(addedtorchandlightningto dependencies)devtools/conda-envs/test_env.yaml(addedpytorchandlightningdependencies)devtools/conda-envs/deployment_env.yaml(addedpytorchandlightningdependencies)devtools/conda-recipes/anaconda/meta.yaml(addedpytorchandlightningto runtime dependencies)Future Enhancements
Potential future improvements: