From 7f0e5993cb298086e98dc060d713acc62b0b940f Mon Sep 17 00:00:00 2001 From: Logan Ward Date: Wed, 13 Sep 2023 15:01:33 -0400 Subject: [PATCH] Adjust the scale to be a unit normal Should reduce the likelihood of numerical issues --- jitterbug/model/mbtr.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jitterbug/model/mbtr.py b/jitterbug/model/mbtr.py index 36c62ba..f1e940c 100644 --- a/jitterbug/model/mbtr.py +++ b/jitterbug/model/mbtr.py @@ -32,14 +32,15 @@ class MBTRCalculator(Calculator): normalization="l2", ), 'model': LinearRegression(), - 'intercept': 0. + 'intercept': 0., # Normalizing parameters + 'scale': 0. } def calculate(self, atoms=None, properties=('energy', 'forces'), system_changes=all_changes): # Compute the energy using the learned model desc = self.parameters['descriptor'].create_single(atoms) energy_no_int = self.parameters['model'].predict(desc[None, :]) - self.results['energy'] = energy_no_int[0] + self.parameters['intercept'] + self.results['energy'] = energy_no_int[0] * self.parameters['scale'] + self.parameters['intercept'] # If desired, compute forces numerically if 'forces' in properties: @@ -60,6 +61,8 @@ def train(self, train_set: list[Atoms]): energies = np.array([atoms.get_potential_energy() for atoms in train_set]) self.parameters['intercept'] = energies.mean() energies -= self.parameters['intercept'] + self.parameters['scale'] = energies.std() + energies /= self.parameters['scale'] # Compute the descriptors and use them to fit the model desc = self.parameters['descriptor'].create(train_set)